2
$\begingroup$

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$?

  • 0
    @J.M. Your link above is now dead. If you have an idea to a replacement link, please let me know and I'll edit it in. If not, let me know and I'll delete the comment.2014-03-18

2 Answers 2

1

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

1

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%).