Bug introduced in 10.0.0 and fixed in 10.2
When I enter the following command, half of the fourth-degree spline is missing from the graph (i.e. it doesn't touch the last point). Is this a bug in Mathematica or am I fundamentally misunderstanding something about Bézier curves?
Manipulate[
Graphics[{BezierCurve[pts, SplineDegree -> 4], Dashed, Green,
Line[pts]}, PlotRange -> {{-.5, 1.5}, {-.5, 1.5}},
Frame -> True], {{pts, {{0, 0}, {.5, 0}, {.5, .5}, {1, .5}, {1,
1}}}, Locator, LocatorAutoCreate -> True}]
Here's a screenshot of the output:
What makes me suspicious is that the same behavior shows up in Mathematica's own help file on BezierCurve
.
Answer
Since there is really something wrong with the BezierCurve
, I made this work-around:
Clear[bezierCurve];
bezierCurve[pts_] :=
First@ParametricPlot[
BezierFunction[pts, SplineDegree -> Length[pts] - 1][t], {t, 0, 1}]
Manipulate[
Graphics[{bezierCurve[pts], Dashed, Green, Line[pts]},
PlotRange -> {{-.5, 1.5}, {-.5, 1.5}},
Frame -> True], {{pts, {{0, 0}, {.5, 0}, {.5, .5}, {1, .5}, {1,
1}}}, Locator, LocatorAutoCreate -> True}]
Since the spline degree is always one less than the length of the point list, I didn't adhere to the built-in syntax where the degree is specified separately through an option. I just let the function bezierCurve
compute the appropriate degree automatically, to reduce the potential for error.
Comments
Post a Comment