RhinoCommon - Get vector perpendicular to planar crv

I’m dealing with a planar Curve, which I’m trying to use to trim away surfaces. I want to trim in the direction perpendicular to the Curve. For exampe, if the Curve is in the XY-plane, it would trim in the Z-direction. It is not oriented along one of my world axes, so I wanted to use the Curve itself to determine the direction that the trim would work in. However, I’m not quite sure what the best approach would be to obtain the perpendicular vector to the planar Curve. How should I approach this? I want to obtain the vector direction of the arrow below.

PS I suppose I could also just straight Extrude it a million miles and then use that to trim anything it passes through, but I figured there was a more elegant solution.

If you are using RhinoCommon, you can use the Curve.TryGetPlane method. If successful, then use the z-axis of the output plane.

Curve curve = ...
if (curve.TryGetPlane(out Plane plane))
{
  var normal = plane.ZAxis;
  // TODO...
}

– Dale

Yes that was my initial guess as well, but unfortunately it fails to generate the plane. My next plan will be:

Brep.CreatePlanarBreps
Surface.NormalAt

I’ll see if I get anywhere tomorrow.

Hi @SNC,

You might consider using Curve.TryGetPlane overload that requires a tolerance. Pass it the document’s model absolute tolerance.

– Dale

Thanks Dale, that did it!

planarCrvPlane = Rhino.Geometry.Curve.TryGetPlane(crv,0.001)[1].Normal

Where crv is the planar curve of interest.

Hi @SNC,

Curve.TryGetPlane is not a static function. You will need to use like this:

Curve curve = ...
if (curve.TryGetPlane(out Plane plane, doc.ModelAbsoluteTolerance))
{
  var normal = plane.ZAxis;
  // TODO...
}

– Dale

Yes of course, I’ll keep that in mind. Thanks again!