Grasshopper

algorithmic modeling for Rhino

Hey guys,

I suppose this is a quite simple question:

I have a list of points in python and another point. I would like to check if there is the point with same coordinates in the list. But somehow, I always get false.

bBoxNewBrep = rs.coercebrep(bBoxNew)
vertexBrep = bBoxNewBrep.DuplicateVertices()


for j in range(0, len(vertexBrep)):
if rg.Point3d(vertexBrep[j]) in listPoints:
testGrid = "true"
else:
testGrid = "false"
break

Views: 1331

Replies to This Discussion

False is what you should get. An object is only equal to itself.

Why don't you test for distance? If the distance is smaller than tolerance then the points are the same.

but should'n it compare coordinates of each point?

when I print my point variable I get something like [0,100,150]. Is there a way to see if there is a point with same coordinates in the list of points?

You are probably comparing a guid with Point3d.
So either set your "listPoints" input "Type hint" to "Point3d" or add the coerce3dpoint function:

bBoxNewBrep = rs.coercebrep(bBoxNew)
vertexBrep = bBoxNewBrep.DuplicateVertices()
listPointsObj = [rs.coerce3dpoint(pt) for pt in listPoints]

for j in range(0, len(vertexBrep)):
    if vertexBrep[j] in listPointsObj:
        testGrid = "true"
        break
    else:
        testGrid = "false"

Btw, if your listPoints list has only one point, then you do not need the for loop at all, when using python's "in" operator:

bBoxNewBrep = rs.coercebrep(bBoxNew)
vertexBrep = bBoxNewBrep.DuplicateVertices()
pt = rs.coerce3dpoint(listPoints[0])

if pt in vertexBrep:
    testGrid = "true"
else:
    testGrid = "false"

Djordje, thank you for reply. I would like to raise a couple of questions:

if I use coerce, will I get rhino object or a point3d class?

also, is the break going to exit all nested loops, or only the last one?

Hi Petar,
You will get a point3d object.
"break" will only break your last loop.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service