MathsGraphing & Visualization

Bezier Curve
calculator.

Find the point, tangent, length and split of a Bezier curve at any value of t.

How it's worked out

A Bezier curve is set by its control points. The first and last are the ends of the curve. The ones between act like magnets: they pull the curve toward them without the curve passing through them. With n + 1 points the curve has degree n, so 4 points make a cubic.

The number t runs from 0 at the start to 1 at the end. Each point on the curve is a weighted average of the control points, and the weights are the Bernstein polynomials:

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

The weights are never negative and add to 1, so the curve stays inside the shape made by its control points. At t = 0.5 a cubic uses the weights 0.125, 0.375, 0.375, 0.125.

De Casteljau's method finds the same point by drawing. Move the fraction t of the way along each side of the control polygon. That gives one point fewer. Repeat until one point is left, and that point is on the curve. The Bézier primer calls it a geometric approach, and it is the one the tool uses, with the weighted sum as the check.

The tangent comes from the derivative, which is itself a Bezier curve one degree lower, with control points:

Qi\displaystyle Q_i=n(Pi+1−Pi)\displaystyle {}= n\,(P_{i+1} - P_i)

So a cubic leaves its first point heading straight at the second: here B′(0) = (3, 6), which is 3 times the step from P₀ to P₁.

Arc length has no closed formula for a cubic, the primer notes, so it is worked out by Gauss-Legendre quadrature: the speed is sampled at five set points in each of 64 slices of t and added with set weights. Turning points are where x′(t) or y′(t) is 0, and with the two ends they give the smallest box around the curve.

Worked examples

Kai places a marker on an animation path

Kai animates a dot along a cubic path in pixels, with control points (0, 0), (40, 120), (160, 120) and (200, 0). He wants the halfway point and the way the dot should face.

At t = 0.5 the dot is at (100, 90), the top of the arch, and the tangent points 0° from the x-axis, so it is moving level. The whole path is 287.6 px long.

t is not distance. At t = 0.25 the dot has gone 80.7 px, which is 28.1% of the path, not 25%. For even spacing he should step by length, using the length column of the coordinates table.

Open this example in the tool

Rosa checks the CSS ease-in-out curve

The CSS Easing Functions spec fixes P₀ at (0, 0) and P₃ at (1, 1), and defines ease-in-out as cubic-bezier(0.42, 0, 0.58, 1). The x value is the share of the time gone and y is the share of the change done.

At t = 0.25 the point is (0.2744, 0.1563). So when 27.4% of the time has passed, the animation is 15.6% done. That slow start is what "ease in" means.

A browser works the other way: it knows the time, so it solves x(t) for t first and then reads y. The tool prints the cubic-bezier text whenever the points fit those rules.

Open this example in the tool

Tom finds the true height of an arch

Tom draws an arch for a sign with control points (0, 0), (1, 2), (3, 3) and (4, 0). The control points reach y = 3, but the curve does not.

y stops rising where y′(t) = 0, at t = 0.5486. The top of the arch is at (2.2184, 1.8934), so the tight box is 4 wide and 1.8934 tall. The primer finds a box the same way, from the roots of the derivative.

The top is not at t = 0.5. There the curve is at (2, 1.875), a little lower and to the left, because the second handle is higher than the first.

Open this example in the tool

Reading your result

The point B(t) is where the curve is at your t. The working lists every round of De Casteljau, and the last step checks the answer with the Bernstein weights.

Speed is how fast the point moves as t grows, in your units per unit of t. Tangent direction is the angle of travel from the positive x-axis, which is how you would rotate an object riding the curve.

Curvature is positive when the curve turns left, with y pointing up, and negative when it turns right. One over its size is the radius of the circle that best fits there. Where the speed is 0 there is no direction and no curvature, and the tool says so.

The split gives two new sets of control points, one for the piece before t and one for the piece after. Together they draw the same curve.

Common mistakes

  • Expecting the curve to pass through every point. Only the first and last points are on it. To pass through a point in the middle, join two curves there.
  • Using t as time or distance. Equal steps in t bunch up where the curve moves slowly and spread out where it moves fast.
  • Taking the control-point box as the size. The handles usually stick out past the curve, as the arch example shows. Use the tight box.
  • Building a circle from one cubic. A cubic cannot be a true circle. With handles of about 0.552285 on a quarter circle, the midpoint lands at (0.7071, 0.7071), on the circle, but other points are slightly off.
  • Breaking the CSS rule. A cubic-bezier easing needs both middle x values from 0 to 1; outside that the tool does not print one.

Questions people ask

Each point on the curve is a blend of all the control points, and the middle ones never get the full weight. They pull the curve toward them like handles. Only the two end points are always on the curve.

Sources