4
$\begingroup$

Mathematica seems to render rational Bézier curves (drawn with BSplineCurve) using polylines whose segments can be annoyingly long, while polynomial Bézier curves (drawn with BezierCurve) behave better. Consider, for example,

Graphics[{Blue, 
   BezierCurve[{{-0.05, 0}, {0, 0.02}, {0.05, 0}}, 
            SplineDegree -> 2],
   Red, 
   BSplineCurve[{{-0.05, 0.05}, {0, 0.07}, {0.05, 0.05}}, 
            SplineDegree -> 2, SplineWeights -> {1, 1, 1}]},
 PlotRange -> {{-1, 1}, {-0.1, 0.2}}, AspectRatio->Automatic]

Those two quadratic Bezier curves should differ only by a small vertical translation. When I execute that code (in version 11.3), however, the default image looks like this:

image at default size

with the upper, red curve rendered as a straight line. If I stretch the image a bit, the red curve becomes a two-segment polyline:

image a bit larger

Stretching the image further causes the red curve to acquire three segments, and so forth.

How can I control the accuracy with which BSplineCurve's are converted into polylines? The straight segments in my current images, while they are fairly short, still generate corners that are sharp enough to be obvious bugs.

$\endgroup$
2
$\begingroup$

(with thanks to Mr. Wizard.)

There is an undocumented option you can use to control the rendering of B-splines:

Graphics[{Blue, BezierCurve[{{-0.05, 0}, {0, 0.02}, {0.05, 0}}, SplineDegree -> 2], 
          Red, BSplineCurve[{{-0.05, 0.05}, {0, 0.07}, {0.05, 0.05}},
                            SplineDegree -> 2, SplineWeights -> {1, 1, 1}]}, 
         BaseStyle -> {BSplineCurveBoxOptions -> {Method -> {"SplinePoints" -> 30}}},
         PlotRange -> {{-1, 1}, {-0.1, 0.2}}]

Bézier and B-spline

Increase or decrease the "SplinePoints" setting as seen fit.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.