 # What RhinoCommon function can test a curve inside a closed curve?

I just want to know is there a function that I can use to determine if a curve is inside a closed curve?

I know the work around is to test a bunch of points from the curve and use the Contains method. I would like to know if there is a function exist before I reinvent the wheel.

1 Like

Hi Toby,

The crv.PlanarClosedCurveRelationship() method is what you need.

Thanks a lot, I learn something new everyday. Got a problem with the crv.PlanarClosedCurveRelationship()

I got 3 objects, a Closed Curve, a point and a Obround curve. I got this code to test if the Obround curve is inside the ClosedCurve, However, even if the Obround curve is clearly inside the ClosedCurve, the function crv.PlanarClosedCurveRelationship() will return false.

Any ideas? Is it because the Obround curve is a polycurve?

``````  public override bool isInside(Curve closedCurve,  Point3d point3d)
{

Point3d leftPoint = new Point3d(point3d.X - (this.X / 2) + (Y / 2) + tolerance, point3d.Y, 0);
Point3d rightPoint = new Point3d(point3d.X + (this.X / 2) - (Y / 2) -tolerance, point3d.Y, 0);

Arc leftArc = new Arc(new Circle(leftPoint, Y / 2), Math.PI);
leftArc.StartAngle = Math.PI / 2;
leftArc.EndAngle = 3 * Math.PI / 2;

Arc rightArc = new Arc(new Circle(rightPoint, Y / 2), Math.PI);
rightArc.StartAngle = -Math.PI / 2;
rightArc.EndAngle = Math.PI / 2;

Line top = new Line(point3d.X + (this.X / 2) - (Y / 2), point3d.Y + Y / 2, 0, point3d.X - (this.X / 2) + (Y / 2), point3d.Y + Y / 2, 0);
Line bottom = new Line(point3d.X - (this.X / 2) + (Y / 2), point3d.Y - Y / 2, 0, point3d.X + (this.X / 2) - (Y / 2), point3d.Y - Y / 2, 0);

PolyCurve polyCurve = new PolyCurve();

polyCurve.Append(leftArc);
polyCurve.Append(bottom);
polyCurve.Append(rightArc);
polyCurve.Append(top);

if (Curve.PlanarClosedCurveRelationship(closedCurve, polyCurve, Plane.WorldXY, tolerance) == RegionContainment.BInsideA)
{
return true;
}
else
{
return false;
}
}``````

This work for me (here) with curves just like yours:

https://github.com/dalefugier/SampleCsCommands/blob/master/SampleCsTestPlanarCurveContainment.cs

Does this help?