Sphere and cylinder trim bug

What’s the argument for not making it correct?

It has already been demonstrated that the user can force Rhino to make the 3d edge of the sphere a true circle by joining the sphere and cylinder and then extracting the sphere. The intersection of the cylinder and sphere is already computed correctly.

You might as well also argue against the use of cylinders, spheres, arcs, tori, cones, etc.

In the manufacturing world what you are arguing against are the basic foundational geometry entities because there needs to be ways to communicate and contractually agree, between all parties involved, on what is meant without any arguments.

If the Rhino user wants the geometry as a nice degree 3 or higher B-splines with reasonably spaced knots they can use the Rebuild command. Currently the intersection between a sphere and a sphere or a plane and a sphere are never nice degree 3 splines with reasonably spaced knots.

I would think it would be reasonably easy to make sphere/sphere intersection or plane sphere intersection as a true circle or arc(partial intersection) even when the intersection does not coincide with the sphere’s isocurve.

What’s the argument for not making it correct?

What does “correct” mean to you?

Here are the pointwise errors of the obvious degree 2 and 3 NURBS unit circles:

So, they are not “correct” if you evaluate them in double-precision arithmetic. The relative error will hover around 1 ulp due to numerical roundoff. Does this matter for you?

In fact, their weights involve things like sqrt(2)/2, which can’t be represented exactly using floating-point numbers. So we don’t even have the “correct” NURBS curve when we store it in Rhino, just one which is very close by. Does that matter?

Hmm. I know that if I have the circle C(t) = (cos(t), sin(t)), I can take derivatives like C’(t) = (-sin(t), cos(t)), C’'(t) = (-cos(t), -sin(t)), C^(3)(t) = (sin(t), -cos(t)), C^(4)(t) = (cos(t), sin(t)), and so on… So, each “hodograph” of the circle is also a circle, still arc length parametrized, just rotated. That’s nice. The representation does not get more complicated as I take derivatives, the magnitude of the derivatives does not shrink or blow up or otherwise get unstable.

Oh no! What is this?? This plot is very interesting. Can you tell what’s going on? Does it matter for you?

Here are some plots of pointwise error of various (non-rational) B-spline approximations to the circle (the number of control points for each is N = 2^n):

How much accuracy do you need? What does 1e-7 pointwise error here mean? What about 1e-15?

In the very first plot in this post (showing d = 2, 3 NURBS), the level of numerical roundoff is hovering right around machine epsilon, which for a double-precision float is about 2.2e-16. That means about 2.2e-16 % error from being a circle. If we were measuring errors in lengths, and if the radius of the circle is 1m, this is smaller than one femtometer of error. One femtometer is roughly the “size” of a proton or neutron. Do you need this much accuracy?

Above, the orange curve in the middle plot shows that a degree 5 B-spline with uniform knots that is computed using a least squares fit has about 1e-7 % error. This is sub-micron precision and is much more accurate than what Rhino guarantees by default. Is this enough accuracy?

I can go on and list even more issues with NURBS curves if you want me to.

Please understand I am not the only person who holds this opinion. Here’s a paper written by Piegl and Tiller (the people who literally wrote the book on NURBS…): It is time to drop the “R” from NURBS | Engineering with Computers | Springer Nature Link

You might as well also argue against the use of cylinders, spheres, arcs, tori, cones, etc.

Clearly I am doing no such thing. Each of these types of geometry can be represented many different ways, and NURBS (as in rational B-splines) are only one choice.

[…] because there needs to be ways to communicate and contractually agree, between all parties involved, on what is meant without any arguments.

I am not sure what point you’re trying to make. Please elaborate if there is something important here I should understand.

I would think it would be reasonably easy to make sphere/sphere intersection or plane sphere intersection as a true circle or arc(partial intersection) even when the intersection does not coincide with the sphere’s isocurve.

Yes, it is. We can do that. Is this what you would like me to spend my time on? If there is a very good reason for it, which you can clearly articulate (beyond “the NURBS circle is correct”, which I do not find to be a particularly compelling argument), I am happy to do so.

Sam

@David53

Can you please clarify what you mean by “concentric constraints”? Is this something Rhino does already, or a plugin? If there a link to a video you can post here, please do. A video showing how a competing product does it is fine, too.

Sam

I used AI to break this down a bit:

1. Why CNCs don’t cut raw NURBS curves

  • Hardware speaks G-code: CNC controllers drive motors using simple math—specifically straight lines (G01) or circular arcs (G02/G03).

  • Real-time physics: Calculating acceleration and feed rates on the fly is trivial along straight lines, but computationally complex along variable NURBS splines.

  • CAM conversion: CAM software (or Rhino’s export settings) must convert smooth NURBS curves into a series of tiny line/arc segments within a tight tolerance (e.g., 0.001mm) for the motors to execute.

2. Why .dxf is used instead of .3dm

  • Universal standard: DXF became the open “PDF of 2D CAD” in the 1980s. CAM and machine developers built importers for DXF rather than supporting dozens of proprietary CAD formats like .3dm.

  • Not a degree limit: DXF has actually supported degree-3 and higher NURBS splines since 1994. The file format can easily hold smooth curves—it is the machine controller downstream that converts those splines into lines and arcs to drive the physical motors.

^ So basically, after 12-13 years in fabrication and outputting data from Rhino to send to producers, I’ve always had to give them .DXF files, and they always had issues when curves beyond degree 1 or 2 were in the data.

There are some odd occasions where someone felt lucky and bought a machine that can read .AI files, but those work on Beziers.

So whenever I use Rhino, I’m paranoid about obtaining degree3+ geometry, and try to “fight” it all the time.

Do you use SimplifyCrv to convert NURBS curves to straight line and arc segements? SimplifyCrv | Rhino 3-D modeling
I trimmed a planar surface with a sphere, and DupEdge the trimmed edge. The result was a degree 3 NURBS curve. SimplifyCrv replaced the NURBS curve with a circle.

(Added) Also, only some special cases of degree 2 NURBS curves are exactly arcs or circles. Other degree 2 curves do not meet the requirement of only straightline and circular arc segments.

There are also a load of configurable options when exporting to DXF…

– Dale

Including Export Scheme R12 Lines and Arcs which appears to replace NURBS curves with line and arc/circle segments.

You should not need to be paranoid about degree 3+ geometry. If you’re having trouble exporting degree 3+ to DXF files and need more fine-grained control, please make a separate Discourse post explaining carefully what the issue is and we can try to help you. The problem you’re describing is independent of this thread’s discussion around trim curves and intersections.

Only a few special combinations of object types and orientations have exact intersections and trimmed edges which are circles. These combinations include:

Note: Spheres in Rhino have an axis. The “v” isocurves converge at the poles of the axis.

Planar surface, sphere
Rhino produces a circle object if the axis of the sphere is perpendicular to the surface.

Planar surface. circular cylinder with the axis of the cylinder perpendicular to the planar surface
Rhino produces a circle object

Planar surface, surface of revolution (including cones and paraboloid) with the axis of revolution perpendicular to the planar surface
Rhino produces a circle object

Sphere, sphere
Rhino produces a circle object if the center of one sphere is on the axis of the other sphere.

Sphere, circular cylinder with the center of the sphere on the axis of the cylinder
Rhino produces a circle object

Sphere, surface of revolution with the center of the sphere on the axis of the surface of revolution
Rhino produces a circle object (or a set of arcs corresponding to a circle)

Circular cylinder, surface of revolution with the axis of the cylinder aligned with the axis of the surface
Rhino produces a circle object (or a set of arcs corresponding to a circle)

Surface of revolution, surface of revolution with the axes of the two surfaces of revolution aligned
Rhino produces a circle object (or a set of arcs corresponding to a circle)

I think one of the common issues I have seen complaints about in the past is that some fabrication programs (CAM) that use feature recognition to find holes in imported surface/solid objects don’t manage to recognize trimmed edges that should be circles but are not.

Curves are usually fine if SimplifyCrv is run on them before export or if automatic simplification is enabled in the export routine.

Don’t ask me. You are the one who called it “correct”

You said, " It is arguably worthwhile to go ahead and get the 3D trim curve correct"

and I asked what’s the argument against making it correct?

The point I was making is that in the world of manufacturing a sphere is an entity with a center point and a radius. The intersection of two spheres is a circle and the intersection of a sphere and a plane is also a circle.

Nobody in manufacturing is interested in the petty limitations of a program like Rhino that thinks a sphere has an axis. They’re not interested in explanations that the intersection is sometimes a circle and sometimes not based on the orientation of the sphere’s mythical axis.

People in manufacturing need to communicate. That’s easy when things are defined simply and unambiguously.

It’s easy enough for a competent user to work around these limitations. Its not hard to force Rhino to make the intersection a true circle. Its just a little annoying that the user is always expected to be more competent than the developers.

Yeah, but its not just CAM. CMM, blueprints, spreadsheets and much more also don’t like splines.

OK, the only actual specific complaint that I’ve heard so far is that some CAM software automatically recognizes holes and fails to do so if the geometry isn’t a circle.

It would be helpful to have confirmed by someone who has used this kind of software themselves that this means that storing a B-rep’s edge curve as an ON_ArcCurve will solve this problem. Thank you @Helvetosaur for providing a concrete example of a workflow that breaks. I see no problem with this, and this is useful detail I can add to the YT that Dale created. (For instance, adding a NURBS circle would not be helpful here, since that would rely on the CAM software to automatically detect whether a NURBS is a circle, which is going to be finnicky at best.)

@jim

Nobody in manufacturing is interested in the petty limitations of a program like Rhino that thinks a sphere has an axis.

Its just a little annoying that the user is always expected to be more competent than the developers.

Keep it civil. We’re here to help you; how well we can do that depends on how effectively you can communicate with us.

Yeah, but its not just CAM. CMM, blueprints, spreadsheets and much more also don’t like splines.

This isn’t helpful. If you have specific complaints about which workflows break, make them. You can use this template: “When I try to do X, Rhino fails to do Y, which prevents me from doing Z (or which causes a lot of work of the form Z).”

Based on my quick and limited testing the only situations which need coding changes so that the B-rep edge curve is a ON_ArcCurve object are when a sphere intersects a planar surface or another sphere. Other situations appear to already result in the B-rep edge curve being ON_ArcCurve object. That’s based on what type of object is created by DupEdge.

I’m glad the original purpose of this topic has succeeded in tracking a relevant bug.

SimplifyCrv is my best friend indeed. In this case, it did not help.

Unfortunately hardly any of the export settings for DXF seem to make any difference for producers. They mostly keep asking why we wouldn’t just export from AutoCAD directly…

Using “Lines & Arcs” like someone showed is what I do, and it works fine, so long as you are mindful of geometry.

@DuncanW Great, glad we got there in the end.

For your DXF issues, I would recommend that you make new Discourse posts for any specific problems you encounter. We can always try to make things work better for you, and it sounds like the situation is not good… I don’t have any experience with DXF or CAM myself, so I can’t guess as to what the problem might be, but definitely someone around here will be able to help.