Grasshopper

algorithmic modeling for Rhino

Hello,

I want to do the same thing as "Closest Points" in Grasshopper by Ghpython,
and I imitated the discussion below.

http://www.grasshopper3d.com/forum/topics/multiple-n-closest-points...

But I don't understand well Vb, so I coudn't make the same funcition like this...

My scriript is

import rhinoscriptsyntax as rs

closePts = []
distList = []
for pt2 in pts:
dist = rs.Distance(pt1, pt2)
if(dist > 0): # exclude itself by > 0
distList.append(dist)
distList.sort()
for ptc in pts:
dist = rs.Distance(pt1, ptc)
if(dist > 0 and dist <=distList[num-1]):
closePts.append(ptc)


a = closePts

I sort at first the List of distance and after that,

I do "for Loop" once more to extract the closest points,

but I want to sort the List of Points as the discussion do in Vb.

Is there any good idea?

Thanks,

Views: 4273

Attachments:

Replies to This Discussion

Hello Marcus,

Thank you for your reply!

I know that your advice about "import ghpythonlib.components as ghcomp" is the best way,

but I want to know how to write the scricpt in python!

Can you tell me how to write the script of "ClosestPoint?


Thank you Marcus!

I did'nt know at all about "import heapq".
I will try to make a script with "import heapq" and Pythagoras!

Ken

Hi Ken, you want the RhinoCommon Point3dList class. I'm pretty sure that's what the Grasshopper component implements. Most RhinoCommon geometry types also have methods for finding closest points on the geometry. I would think that the rhinoscriptsyntax Python module has functions which wrap around these RhinoCommon methods (haven't checked though). No need to make things harder than they need be ;)

Hi Anders,

Thank you for your reply!

I did'nt check the RhinoCommon.

I will import RhinoCommon and try to use "Point3dList class".

" No need to make things harder than they need be", 

I think so too...
So I follow your advice and Marcus's advice in trying the simplest way.

Thank you very much!

Ken

count = 3

closestPoints = []


for c in range( count ):
    i = rs.PointArrayClosestPoint( testPoints, point )
    p = testPoints.pop( i )
    closestPoints.append( p )

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