Curve.ProjectToPlane regression in Rhino 8

Hi,

We are working on upgrading one of our Rhino plugins from Rhino 7 to Rhino 8. We came across the following bug with ProjectToPlane for specific breps and curves.

The code below creates a sphere with a cylinder that removes the center of it. When you project the faces of the Brep to the world xy plane it works fine and generates the curves as shown below. In Rhino 7 it works fine, but in Rhino 8 it fails.

var rhinoDoc = RhinoDoc.ActiveDoc;

Point3d sphereCenter = new Point3d(0, 0, 0);
double sphereRadius = 10;
Sphere sphere = new Sphere(sphereCenter, sphereRadius);
Brep brepSphere = Brep.CreateFromSphere(sphere);

Circle cylinderBase = new Circle(sphereCenter, 5);
double cylinderHeight = 20;
Cylinder cylinder = new Cylinder(cylinderBase, cylinderHeight);
Brep brepCylinder = Brep.CreateFromCylinder(cylinder, false, false);

Brep[] brepDifference = Brep.CreateBooleanDifference(new[] { brepSphere }, new[] { brepCylinder }, 0.001);
Brep brep = brepDifference[0];

rhinoDoc.Objects.Add(brep);

Plane testPlane = new Plane(Point3d.Origin, Vector3d.ZAxis);

foreach (var face in brep.Faces)
{
	var loop = face.OuterLoop.To3dCurve();
	var newLoop = Curve.ProjectToPlane(loop, testPlane);
	if (newLoop is not null)
	{
		rhinoDoc.Objects.Add(newLoop);
	}
}


In case it matters, this was tested on Rhino 8.19.25132.1001 and Rhino 7.27.23032.13001 on Windows.

This particular API call is used quite a bit in our plugin, so it would be good to know what exactly triggers this failure. A workaround could go a long way as well.

Hi @SK-Structurecraft,

In Rhino 7, Curve.ProjectToPlane used to convert input curves to NURBS before projecting. Otherwise, projecting can fail on some non-deformable curve types (lines, circles, etc.).

This is no longer the case in Rhino 8.

To fix your code, do this:

Curve loop = face.OuterLoop.To3dCurve().ToNurbsCurve(); // nurbify

– Dale

Thanks for the quick reply. Tried it out and that works great. I think that should fix it for our case.

Are there any other Curve methods that need similar fixes?

I don’t know - maybe.

Here are all of the RhinoCommon issues that have been fixed thus far in Rhino 8.

– Dale

1 Like