Grasshopper

algorithmic modeling for Rhino

Hi,
Does anyone know if it's possible intersect ARCS with Planes using OnUtil.ON_Intersect? I know that this is possible in grasshopper using CURVE | PLANE math interesection. I would like to compact my code by using a VB component instead.

Thanks.

Views: 1373

Replies to This Discussion

The ON_Intersect function looks to be primarily based on mathematical intersections (ie ones that can be solved without any nurbs geometry per-say). There is not a Plane/Arc intersection there, but there is a Plane/Sphere intersection method that might be promising. Essentially, you could use the Plane/Sphere intersection with the sphere being generated from the center point & radius of the arc, with the result of that intersection being a circle. Then you would do use the IntersectCurve method to see if there's an intersection between the arc that you have and the circle from the plane intersection.

Note that in order to do any curve/curve intersections both curves in question need to be derived from an OnCurve class. Both OnArc and OnCircle are "light" classes that really only contain the mathematical abstraction of those objects. However, there is an OnArcCurve class that does derive from the OnCurve class and contains all of the necessary functions/methods to do stuff like intersections with them.

There is another possible option here, and that would be to create a surface representing the plane, then intersect the curve with the surface. Generating the surface from the plane isn't really that hard at all, you just have to make sure its big enough to fully intersect the curve. Again, in order to perform that intersection, the curve would need to be an object that derives from OnCurve....OnArcCurve rather than an OnArc.

The last option that pops to mind involves retrieving the plane that the arc lies on, intersecting that with the plane in question (resulting in a line) and finding an intersection between the line and the arc. Not overly complicated, but like the other two, there are a few steps to it.

Each method has their pros and cons, especially if you may be looking to use this beyond just arc curves. Let me know if you need any more specifics.
Hi Kermin,

Like Damien just pointed out, there is no method that supports arc/plane or circle/plane intersection in ON_Intersect at the moment, but you were looking in the right place and I sort of expected to find it there.
I forwared your request to our math brians and this method will be added (soon I hope). For now, any of the suggestion above will work.
While we're here Rajaa, there are a few other mathematical intersections that could probably be in there, but aren't. Here's a three more that seam like they could be added; Line/Circle, Circle/Circle, Sphere/Sphere. Some of the arc stuff could be added as well, but if the circle stuff is there, then at least the step to finding out arc intersections is that much easier.
Some code to go into a C# component. It uses the Plane|Plane intersection and then a sort of Line|Circle intersection like Damien suggested.



double t0, t1;
switch (PlaneCircle(y, x, out t0, out t1))
{
case PlaneCircleIntersection.None :
type = "None";
break;

case PlaneCircleIntersection.Parallel :
type = "Parallel";
break;

case PlaneCircleIntersection.Coincident :
type = "Coincident";
break;

case PlaneCircleIntersection.Tangent :
type = "Tangent";
pA = x.PointAt(t0);
break;

case PlaneCircleIntersection.Secant :
type = "Secant";
pA = x.PointAt(t0);
pB = x.PointAt(t1);
break;





Additional code:

public static PlaneCircleIntersection PlaneCircle(OnPlane plane, OnCircle circle, out double param1, out double param2)
{
param1 = double.NaN;
param2 = double.NaN;

if (plane.zaxis.IsParallelTo(circle.plane.zaxis, 1e-12 * Math.PI) != 0)
{
if (plane.DistanceTo(circle.Center()) < 1e-12)
{ return PlaneCircleIntersection.Coincident; }
else
{ return PlaneCircleIntersection.Parallel; }
}

OnLine L = new OnLine();

//At this point, the PlanePlane should never fail since I already checked for parallellillillity.
if (!RMA.OpenNURBS.OnUtil.ON_Intersect(plane, circle.plane, ref L)) { return PlaneCircleIntersection.Parallel; }

double Lt = 0.0;
L.ClosestPointTo(circle.Center(), ref Lt);

On3dPoint Lp = L.PointAt(Lt);

double d = circle.Center().DistanceTo(Lp);

//If circle radius equals the projection distance, we have a tangent intersection.
if (Math.Abs(d - circle.radius) < 1e-12)
{
circle.ClosestPointTo(Lp, ref param1);
param2 = param1;
return PlaneCircleIntersection.Tangent;
}

//If circle radius too small to get an intersection, then abort.
if (d > circle.radius) { return PlaneCircleIntersection.None; }

double offset = Math.Sqrt((circle.radius * circle.radius) - (d * d));
On3dVector dir = L.Tangent() * offset;

if (!circle.ClosestPointTo(Lp + dir, ref param1)) { return PlaneCircleIntersection.None; }
if (!circle.ClosestPointTo(Lp - dir, ref param2)) { return PlaneCircleIntersection.None; }

return PlaneCircleIntersection.Secant;
}

///
/// Represents all possible cases of a Plane|Circle intersection event.
///
public enum PlaneCircleIntersection : int
{
///
/// No intersections. Either because radius is too small or because circle plane is parallel but not coincident with the intersection plane.
///
None = 0,

///
/// Tangent (one point) intersection
///
Tangent = 1,

///
/// Secant (two point) intersection.
///
Secant = 2,

///
/// Circle and plane are planar but not coincident.
/// Parallel indicates no intersection took place.
///
Parallel = 3,

///
/// Circle and plane are co-planar, they intersect everywhere.
///
Coincident = 4
}
Thanks guys.

In the end, before your posts, I had used RhUtil.RhinoCurveBrepIntersect with the arc coming in as a curve and the planes being converted to Breps by making them large enough to encompass the arc in question. I think this is the 2nd method Damien refers to below.

I switched the arc from a grasshopper arc to curve by inserting a geometry component in between.

The planes were converted to Breps by using a scale and move grasshopper function before feeding them into the VB component.

So in the end, it was a combination of grasshopper components to convert the objects and native Rhino functions to get the intersections.I think this provided the most compact code since RhUtil.RhinoCurveBrepIntersect was a single function to get the intersection points.

A more general question for everyone is whether there is more guidance on the RHINO SDK functions. I see that the functions are documented and listed but the real issue is understanding what the functions do and when to use what. Any suggestions?



Thanks again for the help.
I have a similar situation, only that in my case, I am dealing with true curves. All suggested solutions here seem to bank upon the fact that the given curve has an arc/circle form.

Arc and plane are both mathematical forms, and therefore it seems possible for finding the intersection purely mathematically, without have to do geometric operations, keeping it light. Now I am wondering how the native GH component solves intersection events for a Plane and a Curve (when one input is mathematical and other geometric?) Is there still a light mathematical method for doing this, or does it work by creating a surface and treating the line as a curve and the using RhUtil.RhinoCurveBrepIntersect (as Kermin's method)?

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service