How to check if a curve intersect with anything?

Hello.
I have problem, that would be easier to solve if I can check if a curve ever intersect with another. I know how to check between two curve using Rhino.Geometry.Intersect.Intersection.CurveCurve. What I want is that I have a curve then know if that curve ever intersect with another, then give me something (may be a list) about the intersection and with which curve. As I have lot of curves, I don’t like to iterating them one by one to check intersection if possible. Can anyone help? I’m using python for this.
Thanks in advanced.


Intersect.gh (16.9 KB)

1 Like

Hi. Thanks for your answer. But, isn’t it kinda like check if the curve intersect with any member of a curve list by checking one by one? Though it happened inside a component, not by our own code.

You can use Intersection.CurveCurve like this:

private void RunScript(Curve a, Curve b, ref object A)
{
  var tol = RhinoDocument.ModelAbsoluteTolerance;
  var events = Rhino.Geometry.Intersect.Intersection.CurveCurve(a, b, tol, tol);
  A = events.Count > 0;
}

CurveCurve.gh (16.2 KB)

If your curves are coplanar you can use Curve.PlanarCurveCollision:

private void RunScript(Curve a, Curve b, ref object A)
{
  var tol = RhinoDocument.ModelAbsoluteTolerance;
  A = Curve.PlanarCurveCollision(a, b, Plane.WorldXY, tol);
}

PlanarCurveCollision.gh (17.4 KB)

If you need to create the list inside your code:

private void RunScript(Curve a, List<Curve> obstacles, ref object A)
{
  var tol = RhinoDocument.ModelAbsoluteTolerance;
  var collisions = new List<bool>();
  foreach(var obs in obstacles)
  {
    var events = Rhino.Geometry.Intersect.Intersection.CurveCurve(a, obs, tol, tol);
    collisions.Add(events.Count > 0);
  }
  A = collisions;
}

CurveCurveList.gh (15.0 KB)

You can also use System.Linq:

private void RunScript(Curve a, List<Curve> obstacles, ref object A)
{
  var tol = RhinoDocument.ModelAbsoluteTolerance;
  var collisions = obstacles.Select(obs => Intersection.CurveCurve(a, obs, tol, tol)).Select(events => events.Count > 0).ToList();
  A = collisions;
}

CurveCurveLinq.gh (15.0 KB)

If you only need to get the first intersected obstacle:

private void RunScript(Curve a, List<Curve> obstacles, ref object A)
{
  var tol = RhinoDocument.ModelAbsoluteTolerance;
  foreach(var obs in obstacles)
  {
    var events = Intersection.CurveCurve(a, obs, tol, tol);
    if(events.Count == 0) continue;
    A = obs;
    break;
  }
}

firstObstacle.gh (14.4 KB)

1 Like

Moved to Rhino Developer sub-forum.

Hi. Thanks. I’ll try them

This was quite useful. Thank you for sharing.