algorithmic modeling for Rhino
Point3d ClosestPoint(Point3d pt, object Geo, out Vector3d normal){
if(Geo is Brep){
Brep g = (Brep) Geo;
Point3d cpt = Point3d.Unset;
ComponentIndex ci = ComponentIndex.Unset;
double s,t;
g.ClosestPoint(pt, out cpt, out ci, out s, out t, double.MaxValue, out normal);
return cpt;
}else if(Geo is Curve){
Curve g = (Curve) Geo;
double ct; g.ClosestPoint(pt, out ct);
normal = pt - g.PointAt(ct);
return g.PointAt(ct);
}else if(Geo is Mesh){
Mesh g = (Mesh) Geo;
Point3d cpt = Point3d.Unset;
g.ClosestPoint(pt, out cpt, out normal, double.MaxValue);
return cpt;
}else if(Geo is Point3d){
Point3d g = (Point3d) Geo;
normal = pt - g;
return g;
}else if(Geo is Line){
Line g = (Line) Geo;
Point3d cpt = g.ClosestPoint(pt, true);
normal = pt - cpt;
return cpt;
}else if(Geo is Plane){
Plane g = (Plane) Geo;
normal = g.ZAxis;
return g.ClosestPoint(pt);
}else if(Geo is Arc){
Arc g = (Arc) Geo;
Point3d cpt = g.ClosestPoint(pt);
normal = pt - cpt;
return cpt;
}else if(Geo is Circle){
Circle g = (Circle) Geo;
Point3d cpt = g.ClosestPoint(pt);
normal = pt - cpt;
return cpt;
}else if(Geo is Rectangle3d){
Rectangle3d g = (Rectangle3d) Geo;
Point3d cpt = g.ClosestPoint(pt);
normal = pt - cpt;
return cpt;
}else if(Geo is Box){
Box g = (Box) Geo;
Point3d cpt = g.ClosestPoint(pt);
normal = pt - cpt;
return cpt;
}else{
//throw new Exception("Invalid geometry");
}
normal = Vector3d.Zero;
return Point3d.Unset;
}
Hi Daniel,
Thanks a lot - this is great!
However, there's an option in the GH component that has the option to only check the "closest" from the list of geometries, so that the input points don't return results from all of the geometries they are measuring against. Is that something that's just post-processing and finding the lowest? Or would there be a faster way of doing it - I'm trying to write it in C# mainly because of speed/performance issue of the component, and would like to convert it into Parallel For loops in Visual Studio.
Thanks again!
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
© 2024 Created by Scott Davidson. Powered by