Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This works (SplineDegree -> 2)

ParametricPlot[BezierFunction[{{0, 0}, {1, 0.5}, {2, 2}}, SplineDegree -> 2][u], {u, 0, 1}]

BezierFunction SplineDegree 2

but this does not (SplineDegree -> 1)

ParametricPlot[BezierFunction[{{0, 0}, {1, 0.5}, {2, 2}}, SplineDegree -> 1][u], {u, 0, 1}]

BezierFunction::invdeg: Value of option SplineDegree -> 1 should be a positive integer, or a list of positive integers

I found no reference to a possible issue in the documentation for BezierFunction.

SplineDegree -> 1 works fine with BSplineFunction and BezierCurve; shouldn't it also work with BezierFunction?

(Mma 8.0.4 Mac OSX)

share|improve this question
4  
The only value that seems to work for an arbitrary list of values seems to be the length of the list minus 1. –  Heike Jul 11 '12 at 16:21
5  
When you look at the definition of Bézier curves you can see why the degree of the polynomial has to be equal to the number of points minus one, like Heike pointed out. The error message could be more helpful here, though. –  Thies Heidecke Jul 11 '12 at 18:55
3  
@ThiesHeidecke And yet SplineDegree->1 works for BezierCurve[]? You get straight lines when you put that in a Graphics[]. What am I missing? –  JxB Jul 11 '12 at 19:01
3  
@ThiesHeidecke And moreover, the option SplineDegree which is explicitly mentioned in the docs for BezierFunction is then completely misleading because it suggests that the function works just like BezierCurve. So my guess is that they did mean to make these two functions work the same way, but forgot to partition the argument lis of BezierFunction according to the SplineDegree when it's explicitly given. –  Jens Jul 11 '12 at 19:01
    
Yes, this could definitely be improved on Wolfram's side. It is confusing as it is at the moment. –  Thies Heidecke Jul 11 '12 at 19:06
add comment

1 Answer 1

up vote 10 down vote accepted

Reason for incompatibility

Yes, the doc shouldn't mention that it is fully compatible (that's an oversight...). BSplineFunction and BSplineCurve are fully compatible as far as I remember, but not BezierCurve and BezierFunction.

The reason is that what BezierCurve is doing when it has more than d+1 control points for SplineDegree->d case is something called composite Bezier curve. Essentially, the remainder of control points are grouped in d points, and creating degree d spline by carrying the last point from the previous curve.

pts = {{0, 0}, {1, 1}, {2, -1}, {3, 0}, {4, 2}, {6, -1}, {7, 3}, {8, -1}, {9, 1}, {10, -2}};

Graphics[{BezierCurve[pts], Green, Line[pts], Red, Point[pts]}]

composite bezier

It is a convenient hack that graphics / CAD people has been using for a long time, and it makes sense when you are creating multiple continuous curve segments.

not c1

But the problem with it for BezierFunction is that:

  1. it does not guarantee the continuous derivative at the connection points (which are marked with blue circles). It only guarantees $C^0$:

  2. Another problem is parametrization. Should parameters run between 0 to 1 (by uniformly dividing by the number of curve segments), or what... None of this is a problem for graphics primitives.

  3. This idea is not working well in multi-dimensional case (it can be extended, but no one uses it and has no mathematical meaning).

  4. There are few mathematical ways to make the connection $C^d$ when $d$ is the degree, nonetheless (introducing intermediate control points or using smoothing function), but then it is not matching with BezierCurve either.

So, we decided not to support it.

Work around

  1. SplineDegree->1 case: Just use BSplineFunction. It is exactly the same parametrization, running between 0 to 1, uniformly divided by the number of line segments.

  2. SplineDegree->d where d > 1: CompositeBezierFunction code will be provided.

share|improve this answer
    
Taken up by work. I will try to finish up the code and modify the post soon. –  Yu-Sung Chang Jul 12 '12 at 14:31
2  
Couldn't BezierFunction simply act like your CompositeBezierFunction whenever a non-maximal SplineDegree is explicitly specified? –  Jens Jul 12 '12 at 16:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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