Ma · Mathematics

How to Compute the Coordinates of a Bézier Curve

Published By the 9to5Science editorial team

At a glance

  1. 1. List the control points

    Write the curve’s control points in order, from the starting point to the ending point.

  2. 2. Choose a parameter

    Pick a value t between 0 and 1 to identify a point on the curve.

  3. 3. Calculate the weights

    For a degree-n curve, use the Bernstein weights for the chosen t.

  4. 4. Combine coordinates

    Multiply each control point by its weight and add the results component by component.

A Bézier curve is specified by its control points and a parameter tt. To compute a point on the curve, evaluate a weighted average of the control points. The weights depend on tt and on the curve’s degree.

For the usual curve segment, take 0≤t≤10\le t\le1: t=0t=0 gives the first control point, and t=1t=1 gives the last. Intermediate values trace the curve between them.

The Bézier curve formula

Given n+1n+1 control points P0,P1,…,PnP_0,P_1,\ldots,P_n, the degree-nn Bézier curve is

B(t)=∑i=0n(ni)(1−t)n−itiPi.B(t)=\sum_{i=0}^{n}\binom{n}{i}(1-t)^{n-i}t^iP_i.

The factors

wi(t)=(ni)(1−t)n−itiw_i(t)=\binom{n}{i}(1-t)^{n-i}t^i

are called the Bernstein weights. For 0≤t≤10\le t\le1, they are nonnegative and sum to 11. Thus B(t)B(t) is a weighted average of the control points.

The formula works for points in two or three dimensions, or any coordinate space: apply it separately to each coordinate. For example, if Pi=(xi,yi)P_i=(x_i,y_i), then

B(t)=(∑i=0nwi(t)xi,  ∑i=0nwi(t)yi).B(t)=\left(\sum_{i=0}^{n}w_i(t)x_i,\;\sum_{i=0}^{n}w_i(t)y_i\right).

Common formulas by degree

A linear Bézier curve has two control points:

B(t)=(1−t)P0+tP1.B(t)=(1-t)P_0+tP_1.

A quadratic Bézier curve has three:

B(t)=(1−t)2P0+2(1−t)tP1+t2P2.B(t)=(1-t)^2P_0+2(1-t)tP_1+t^2P_2.

A cubic Bézier curve has four:

B(t)=(1−t)3P0+3(1−t)2tP1+3(1−t)t2P2+t3P3.B(t)=(1-t)^3P_0+3(1-t)^2tP_1+3(1-t)t^2P_2+t^3P_3.

The degree is one less than the number of control points. For a cubic curve, for instance, there are four control points.

Worked example: a cubic curve

Take the control points

P0=(0,0),P1=(1,2),P2=(3,2),P3=(4,0),P_0=(0,0),\quad P_1=(1,2),\quad P_2=(3,2),\quad P_3=(4,0),

and calculate the curve point at t=12t=\tfrac12. The cubic weights are

(1−t)3=18,3(1−t)2t=38,3(1−t)t2=38,t3=18.(1-t)^3=\tfrac18,\quad 3(1-t)^2t=\tfrac38,\quad 3(1-t)t^2=\tfrac38,\quad t^3=\tfrac18.

So

B(12)=18(0,0)+38(1,2)+38(3,2)+18(4,0)=(38+98+48,  68+68)=(2,1.5).\begin{aligned} B\left(\tfrac12\right) &=\tfrac18(0,0)+\tfrac38(1,2)+\tfrac38(3,2)+\tfrac18(4,0)\\ &=\left(\tfrac38+\tfrac98+\tfrac48,\;\tfrac68+\tfrac68\right)\\ &=(2,1.5). \end{aligned}

The curve passes through (2,1.5)(2,1.5) at parameter value t=12t=\tfrac12. Notice that this point is not found by simply taking the midpoint of any one pair of control points; all four contribute according to their weights.

A reliable alternative: de Casteljau’s algorithm

You can compute the same point using repeated linear interpolation. Start with the control points and, at each stage, interpolate between neighboring points using

L(A,B;t)=(1−t)A+tB.L(A,B;t)=(1-t)A+tB.

For the example at t=12t=\tfrac12, the first stage gives

(0.5,1),(2,2),(3.5,1).(0.5,1),\quad(2,2),\quad(3.5,1).

Interpolate between those three points to get (1.25,1.5)(1.25,1.5) and (2.75,1.5)(2.75,1.5). Interpolating once more gives (2,1.5)(2,1.5), matching the Bernstein-form calculation.

De Casteljau’s algorithm is especially useful for computation because it uses only linear interpolation and works for any degree. It also gives intermediate control polygons that can be used to split a curve into smaller Bézier curves.

Common mistakes

  • Using the wrong degree: With four control points, use the cubic formula, not the quadratic one.
  • Mixing up the order of points: The first and last control points are the curve’s endpoints, so their order matters.
  • Applying powers to coordinates: The powers in the formula apply to tt and 1−t1-t; the resulting weights multiply the control points.
  • Assuming equal parameter steps mean equal distances: Equal increments in tt do not generally produce equally spaced points along the curve. The parameter describes how the curve is evaluated, not distance traveled.
  • Confusing control points with points on the curve: Except for the endpoints, a control point usually guides the curve rather than lying on it.

For a standard polynomial Bézier segment, evaluate at values in [0,1][0,1]. The same polynomial can be evaluated outside that interval, but those values describe an extrapolation beyond the segment rather than the usual curve segment.

References

  1. Gerald Farin, Curves and Surfaces for CAGD: A Practical Guide
  2. James D. Foley et al., Computer Graphics: Principles and Practice

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.