TransWikia.com

How can I control the length of the line segments used in rendering a BSplineCurve?

Mathematica Asked by Lyle Ramshaw on December 18, 2020

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.

One Answer

(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.

Correct answer by J. M.'s discontentment on December 18, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP