Combining multiple Bézier curves

bezier-curve

Consider the situation where we have two [cubic] Bézier curves with the following properties:

  • They share one common point (end of curve 1 = start of curve 2)
  • They have the same direction at the point where they meet (a smooth join)
  • We suspect that they are likely to be the result of having split a single cubic Bézier curve to create the two curves we see (i.e. they can probably be combined into one curve)

Given this information:

  1. Is it possible to determine whether there is a single cubic Bézier that represents the same shape as the two original curves?
  2. If so, how can we calculate the control points of the new combined curve?

Best Answer

If the two Bézier curves came from splitting one, then the geometry must look like this:

enter image description here

We know the blue points: $A$, $B$, $C$, $D$ are the control points of the first curve, and $D$, $E$, $F$, $G$ are the control points of the second one.

First, find $k$ such that $E = D + k(D-C)$. We know this $k$ exists because we’re assuming a smooth joint. Then compute the red points $P$, $Q$, $R$, $S$, $T$ as follows:

  1. $P = B + k(B-A)$
  2. $Q = C + k(C-B)$
  3. $R = Q + k(Q-P)$
  4. $S = E + k(E-Q)$
  5. $T = S + k(S-R)$

If $S= F$ and $T = G$, then the two curves arose by splitting a larger one, and this larger one has control points $A$, $P$, $R$, $G$.

Of course, in floating point arithmetic, it's not likely that $S= F$ and $T = G$ exactly, so you'll need to use an equality tolerance. But this tolerance should be easy to choose because it's directly related to the geometry of the curves.

The computations might remind you of the de Casteljau algorithm. In fact, what we're doing here is running the de Casteljau algorithm to extend the curve on the left, and then we just check that the extension matches the curve on the right.