**0**

# Coefficients for bezier curves

###
#1
Members - Reputation: **1139**

Posted 15 May 2013 - 01:34 AM

###
#2
Crossbones+ - Reputation: **2041**

Posted 15 May 2013 - 06:50 AM

You start from the parametric Bézier curve formula and rewrite the terms until you obtain the desired formula. This is simple algebra, nothing complicated. For example, for the quadratic case:

The derivation in the cubic case is similar. But I have always found the Bézier formula a much more useful formulation. Why do you want the coefficients of the polynomial?

EDIT: corrected the formula..

**Edited by apatriarca, 15 May 2013 - 06:58 AM.**

###
#3
Members - Reputation: **1139**

Posted 15 May 2013 - 08:18 AM

Thanks, I'll have to look through that. I am using the coefficients for several things. For example, to get the x at a given t I can just do:

float Curve::QuadraticBezierSegment::getXAtT( float t ) const { // A*t^2 + B*t + C return ( m_AX * t * t ) + ( m_BX * t ) + m_CX; }

There might be some other way to do that too, I am not sure. Also, if I take the derivative of the formula and plug in the coefficients I can solve it and get local extrema, ie. the bounds of the curve. Again, I am not a math person, and there might be other ways to do this. If some come to mind, please feel free to share

**Edited by GuyWithBeard, 15 May 2013 - 08:19 AM.**

###
#4
Crossbones+ - Reputation: **2041**

Posted 15 May 2013 - 02:12 PM

To get a point in a Bézier curve the standard method is known as De Casteljau's algorithm. You iteratively linearly interpolate all control points until you find a single point. This is more robust than evaluating your formula. It is also useful to get a better geometric intuition. You may also be interested in the Horner's Method which is a more robust way to evaluate your polynomial. You write C + t*(B + t*A) instead of C + t*B + t*t*A in the quadratic case.

The derivative of a Bézier curve is a lower degree Bézier curve. The derivative of a quadratic Bézier curve is thus a segment and of a cubic Bézier curve is a quadratic Bézier curve. The proof use the following result on the Bernstein polynomials (used to define the equation of a Bézier curve).

The control points of the derivative curve are indeed the points for all i from 0 to n-1.

If all you want is however to get some bounds on the curve, a Bézier curve also have the property to be contained in the convex hull of its points. It can be useful to easily discard curve pairs for collision for example. There also exists interative methods to compute intersections of Bézier curve using this method (or something similar).

###
#6
Members - Reputation: **1815**

Posted 17 May 2013 - 10:40 AM

(Disclaimer: sorry if the LaTeX equations don't come out right; I've had issues!)

apatriarca's formula for the derivative of a Bezier curve is mostly right, but you need to divide the control points by the interval of the curve. The formula for the derivative's control points is D_{i} = n/(t_{1} - t_{0}) * (P_{i+1}-P_{i}). This isn't a problem if the parameter domain for the Bezier curve is [0,1], but if it's something else, then you have to divide by the interval.

If you want to convert a Bezier curve to a power basis polynomial, you need to convert the Bezier curve into an explicit Bezier curve (one where the x-coordinates of the curve are evenly spaced, such as below:

Then you can express this as a Bernstein polynomial [eqn]y = \sum_{i=0}^n y_i B_i^n (t)[\eqn], where x = t. The closed-form conversion between Bernstein to power basis is given as [eqn]p_i = \sum_{k=0}^i b_k \binom{n}{i} \binom{i}{k} (-1)^{i-k}[\eqn].

My real question is: why you would want to convert to a polynomial when you can probably do what you want in the Bernstein basis?

###
#7
Crossbones+ - Reputation: **2041**

Posted 17 May 2013 - 12:36 PM

In my previous reply I was only considering Bézier curves in which t vary uniformly in the [0, 1] interval. If you change the parametrization you clearly have to adjust the derivative, but this does not make my result wrong in any way. More complicated parametrizations are actually also possible. What if I want to use t = sin(s) with s in [0, pi/2]? The (support of the) curve clearly remains the same, but the velocity/derivative is now different.