algorithmic modeling for Rhino
I am wondering how to get the returned value of the closest object from a point in space given a direction. Basically given a point, i want to cast a ray in a direction and get the xyz location of any object (polygon or nurbs surface) that the ray hits with the name of the object that it hits.
Is there a python function in rhino that does this?
Tags:
Hi Peter,
I do want something in python, but also I don't want to give a list of the geometry, I just want it to find the first geometry it hits. In this case I would need to give a list of all geometry in the scene?
Python is not my game I'm afraid. And you can't translate that thingy attached to P (automatically, that is).
Anyway anything is possible (finding the closest object etc etc) but in order to do that you should provide the List of all objects (obviously).
See notes inside with regard the RayShoot limitations
I did find the RayShoot method is available in python.
Thanks for that example, the comments are enjoyable. In my case in python I can get the GUID, but can't pass it to the RayShoot method as it needs the geometry base class. http://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Geometry_...) but can't find a convert method from GUID to GeometryBase.
Anyway if you have BrepFaces in mind the RayShoot is kinda dating the wrong girl since it doesn't take into account trimming stuff.
For finding the closest object hit just sort an Array (keys = distances, values = objects hit) or use a Sorted Dictionary (ditto).
A classic Array sort in C# looks like this:
And is invoked (distList = the distances):
geomHitList = ArraySort<double, GeometryBase>(distList, geomHitList);
Thus your object is GeometryBase closestThing = geomHitList.First();
If you are using a point and direction, wouldn't it be way easier just drawing a line representing the "ray" and seek collisions/intersections with objects? So if the object intersects, then extract the location + attributes of the objects, and that is easily achieved through normal grasshopper components rather than getting into the trouble of coding something from scratch.
I need it to be scaleable and returning data, drawing lines is not efficient.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by