A particular Stack Overflow question asks how to construct a specific cubic Bézier path of constant length. I have experimentally determined the ideal distances of the control points from the nearest on-path handle and plotted them as seen here:

Graph showing actual points compared to ellipse

The graph in blue is the equation I am after. (The $y$ intercept appears to be at $\cos(30°)$.) The graph in red is an ellipse (not the right equation).

Does anyone have either a guess or (better yet) a derivation of what the actual formula ought to be that predicts the distance of a control point oriented $90°$ to the path end points to achieve a constant-length path?

Edit: Here's a diagram showing the constraints on the path:

S Curve showing four points in a 'stair-step' arrangement

  1. The arrangement of the control points $P_1$ and $P_2$ is always orthogonal to the line connecting the end points $P_0$ and $P_3$.

  2. The distance $h$ of each control point from the associated end point is the same for both control points. $|P_1-P_0| = |P_3-P_2|$

  3. The two control points are always on opposite sides of line connecting the end points (they're always in a stair-step, producing a curve looking like an 's').

  4. The goal is to find an equation for $h$ in terms of $d$ (the distance between the two end points).

Edit 2: I can simplify these parametric equations for cubic Bézier curves for my constraints and arrive at:

$$\begin{align*} x(t) &= -6ht^3 + 9ht^2 -3ht\\ y(t)& = -2dt^3 + 3dt^2 \end{align*}$$

How do I integrate from $t=0\ldots1$ to get the length of the curve and then express $h$ in terms of $d$?

  • $\begingroup$ So if I understand correctly: given two points and a length, you want to find a Bezier curve made of three control points, with the prescribed endpoints and arc length? $\endgroup$ – user7530 Nov 23 '11 at 20:13
  • $\begingroup$ @user7530 Yes, with the added constraint that the control points are always at right angles to the line connecting the two end points. I'll edit the question with a diagram for clarity. $\endgroup$ – Phrogz Nov 23 '11 at 21:04
  • $\begingroup$ The particularly nasty thing about your problem is that one requires the services of elliptic integrals to express the arclength of a cubic Bézier curve (see this for instance). Inverting that elliptic integral is an even hairier deal. $\endgroup$ – J. M. isn't a mathematician Nov 24 '11 at 8:44
  • $\begingroup$ See also this demonstration. $\endgroup$ – J. M. isn't a mathematician Nov 24 '11 at 8:52
  • $\begingroup$ @J.M. Thanks for the details. That's unfortunate; I had hoped that the constraints on the points would sufficiently restrict the solution to something with a simple closed form. $\endgroup$ – Phrogz Nov 24 '11 at 16:27

It's (probably) impossible to obtain a formula that gives h as a function of d. But, as you can see from the graph you drew, the function is nicely-behaved, so it should be easy to approximate it by some simple function.

If you're interested in a practical approximation, rather than a theoretically correct closed-form solution, let us know, and the details of some approximation can be elaborated.

This might help: http://steve.hollasch.net/cgindex/curves/cbezarclen.html

| cite | improve this answer | |

The length of a Bézier curve $$ x(t) = x_0 (1-t)^3 + x_1 3 (1-t)^2 t + x_2 3 (1-t) t^2 + x_3 t^3 \\ y(t) = y_0 (1-t)^3 + y_1 3 (1-t)^2 t + y_2 3 (1-t) t^2 + y_3 t^3 $$ is given by $$ L = \int\limits_0^1 \sqrt{ \left( { d x(t) \over d t } \right)^2 + \left( { d y(t) \over d t } \right)^2 } dt $$ The length of your curve is $$ L = 3 \int\limits_0^1 \sqrt { \left ( d 2 t (t-1) \right ) ^2 + \left ( h + h 6 t (t-1) \right ) ^2 } dt $$ Since $L=1$ for $h=0, d=1$ you are searching for the solutions to $$ { 1 \over 3 } - \int\limits_0^1 \sqrt{ \left ( d 2 t (t-1) \right ) ^2 + \left ( h + h 6 t (t-1) \right ) ^2 } dt = 0 $$ I don't think there are any analytical solutions to that (but I'm not a mathematician anyway). However, numerically, $$ h = 0.459 \sqrt{ 1 - d^2 } + 0.407 (1 - d^2)^{1.2065}, 0 \le d \le 1 $$ yields a Bézier curve with length between 0.996 and 1.008, i.e. the error in the curve length is less than 1% (-0.4% to +0.8%).

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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