Hello, I’m new to this forum. I’m using openNURBS as C++ import library of 3DM files in my 2D CAD/CAM software. My application use segments, lines and cubic beziers to model simple geometries and polylines. While importing 3DM files I need to “convert” nurbs planar curves to beziers represenation, possibly controlling the approximation error. I tried to use ON_NurbsCurve::MakePiecewiseBezier(); and than getting bezier control points by iterating through the control vertex:

curve.MakePiecewiseBezier();
int span_count = curve.SpanCount();
int order = curve.m_order;
for(int spani = 0; spani < span_count; spani++) {
ON_3dPoint *ctrl_points = new ON_3dPoint[order];
//Load bezier control points
for(int i = 0; i < order; i++ ){
curve.GetCV(spani*(order-1) + i,ctrl_points[i]);
}
//Use control points to create bezier with our representation,
// if the order is 3 elevate degree to make cubic bezier
...
}

What I obtain with this code is a very raw approximation of the original curve. For example from a NURBS circle I obtain four quadratic bezier which is very inaccurate.
Am I using the functions in the correct way? Can you give me any suggestion about the approximation I’m trying to do?

Edit:

After further investigation I found that my approach generally works, but for some reason fail with the attached file… Circle.3dm (22.3 KB)
This is what I obtain after conversion:

I found that the problem is that the curve is rational. I tried to use curve.MakeNonRational(); before calling curve.MakePiecewiseBezier(); but I get the same result. Any ideas?

Thany you for your answer! Yes, I know that circular arcs can’t be represented exactly by a non-rational bezier curve, but they can be well approximated by a chain of (non-rational) cubic beziers, this is the representation we use in our software. I wrongly thought that MakePiecewiseBezier did such approximation. So I need to find a way to approximate a rational curve with a non-rational one.

No, a rational NURBS will be converted to one or more rational Bezier curves.

To approximate a rational curve with a non-rational one, maybe find a (large-ish) number of points on the rational NURBS curve and interpolate a non-rational NURBS curve through them. Then, convert the non-rational approximate curve to Bezier pieces.