[Math] How to calculate C1- and C2-Continuity of Bezier-Curve

bezier-curvegraphing-functions

I have the following example I don't understand.

Here is a Bezier-Curve over [0, 1] with the following setup
Bezier Curve

Now the example explains how to construct the other Bezier-Curve, which connects to point (2,2) with a C2-Continuity, over [1, 2].

(This is in German. "Stetigkeit" stands for continuity. Sorry about that)

enter image description here

Generally I know about

  • Calculate the length of the two intervals (1 and 1 each)
  • The positions of p1,2 and p2,2 are relative to the length of the intervals.

But I don't understand how to calculate them by pure math-

Best Answer

The description presented looks confusing, so here is one possible interpretation, if the subject is about making a $C_2$ connection of the two cubic Bezier curves (segments).

The expression

\begin{align} s_1(t)&= B_0^3(t)\left[\begin{matrix}0\\ 0\end{matrix}\right] +B_1^3(t)\left[\begin{matrix}0\\ 1\end{matrix}\right] +B_2^3(t)\left[\begin{matrix}1\\ 2\end{matrix}\right] +B_3^3(t)\left[\begin{matrix}2\\ 2\end{matrix}\right] \tag{1}\label{1} \end{align}

defines the coordinates of a point $s_1(t)$ for any $t\in[0,1]$ on the first cubic Bezier curve (segment) with control points

\begin{align} p_{01}&=(0,0) ,\quad p_{11}=(0,0) ,\quad p_{21}=(1,2) ,\quad p_{31}=(2,2) , \end{align}
where, for example, $p_{21}=(1,2)$ means that $x$-coordinate of of the point $p_{21}$ is $1$, and its $y$-coordinate is $2$.

Points $p_{0k}$ and $p_{3k}$ are always located on the endpoints of the curve. The other two points $p_{1k}$ and $p_{2k}$ usually are not on the curve, but they control the shape of the curve.

Next, $B_k^3(t)$ means $k$-th cubic Bernstein polynomial,

\begin{align} B_k^3(t)&=\textstyle\binom{3}{k}(1-t)^{3-k}t^k ,\\ B_0^3(t)&=(1-t)^3 ,\quad B_1^3(t)=3(1-t)^2t ,\quad B_2^3(t)=3(1-t)t^2 ,\quad B_3^3(t)=t^3 . \end{align}

Thus, the expression \eqref{1} can be written in a general form for the $k$-th segment as

\begin{align} s_k(t)&= (1-t)^3 p_{0k} +3(1-t)^2t\cdot p_{1k} +3(1-t)t^2\cdot p_{2k} +t^3\cdot p_{3k} \tag{2}\label{2} , \end{align}

which in fact represents two expressions (in 2D), for $x$ and $y$-coordinates of the point $s_k(t)$ on the $k$-th Bezier segment

\begin{align} s_{kx}(t)&= (1-t)^3 p_{0kx} +3(1-t)^2t\cdot p_{1kx} +3(1-t)t^2\cdot p_{2kx} +t^3\cdot p_{3kx} ,\\ s_{ky}(t)&= (1-t)^3 p_{0ky} +3(1-t)^2t\cdot p_{1ky} +3(1-t)t^2\cdot p_{2ky} +t^3\cdot p_{3ky} , \end{align}

which are just ordinary cubic polynomials in terms of parameter $t$.

Note that for any segment the parameter $t$ (often called as time parameter) runs from $t=0$ (point $p_{0k}$) to $t=1$ (point $p_{3k}$).

The sequence of such connected segments $s_k$ is often called a cubic Bezier spline (don't confuse it with B-splines!), and the word "spline" suggests that these segments are connected smoothly, which this exercise was supposed to demonstrate.

What is missing in the original illustration, are the two actual cubic Bezier segments, which are smoothly connected:

enter image description here

So, the instructions tell us that given the first cubic Bezier segment $s_1$ which is defined by control points $p_{01}$ through $p_{31}$, we can smoothly (that is, the resulting two-segment curve will be $C_2$-continuous) extend the curve with segment $s_2$, by calculating three of its control points, $p_{02},p_{12}$ and $p_{22}$. The last control point can be chosen freely, its location does not affect the smoothness of the curve $s_1,s_2$ (in fact, the point $p_{01}$ can be chosen freely as well).

In order to get the $C_2$-continuity, we need first ensure $C_0$, that is, the starting point $p_{02}$ of the second segment must coincide with the endpoint $p_{31}$ of the first:

\begin{align} p_{02}&=p_{31} ,\\ \text{or }\quad s_1(1)&=s_2(0) . \end{align}

To get $C_1$-continuity, we need to guarantee that

\begin{align} s'_1(t)|_{t=1}&=s'_2(t)|_{t=0} ,\\ \text{which gives }\quad p_{12} &= 2p_{31}-p_{21} \end{align}

The last condition for $C_2$--continuity is

\begin{align} s''_1(t)|_{t=1}&=s''_2(t)|_{t=0} ,\\ \text{which gives }\quad p_{22} &= p_{11}+2p_{12}-2p_{21} . \end{align}
Also, note that the phrase "$\dots$ which connects to point $(2,2)$ with a $C_2$-continuity, over $[1, 2]$" is incorrect. The second segment (the actual curve) smoothly connects the endpoint $p_{31}$ of the first segment $s_1$ with the endpoint $p_{32}$ of the second segment $s_2$, and not "over $[1, 2]$", but still "over $[0, 1]$", that is, $t\in[0,1]$. Even if, for example, this two-segment curve represents a smooth trajectory of the point for some timeline $T$ and we assume that the segment $s_1$ starts at $T=0$ and ends at $T=1$, then $s_2$ follows and ends at $T=2$, we still have to use $t$ from 0 to 1 to calculate the points according to \eqref{2}.

Edit

In case if we would like to use a global time parameter $T$ to control the smooth movement of the point using given sequence of "time points", we need to use modified expression for the point on the curve.

Since cubic Bezier curves are defined for local time parameter $t\in[0,1]$, we need to modify the procedure of the smooth connection of the two segments by using a transformation from the global $T$, starting time $T=t_k$ and ending time $T=t_{k+1}$ for the segment $s_k$: \begin{align} t&=\tfrac{T-t_k}{t_{k+1}-t_k} . \end{align}

Then we have the expression for the coordinated of the point on the segment $s_k$ as

\begin{align} s_k(T) &= (1-\tfrac{T-t_k}{t_{k+1}-t_k})^3\cdot p_{0k} \\ &+3\cdot(1-\tfrac{T-t_k}{t_{k+1}-t_k})^2(\tfrac{T-t_k}{t_{k+1}-t_k})\cdot p_{1k} \\ &+3\cdot(1-\tfrac{T-t_k}{t_{k+1}-t_k})(\tfrac{T-t_k}{t_{k+1}-t_k})^2\cdot p_{2k} \\ &+(\tfrac{T-t_k}{t_{k+1}-t_k})^3\cdot p_{3k} . \end{align}

Given that, we can find the control points of the smoothly attached segment $s_{k+1}$, which has assigned global time length $t_{k+2}-t_{k+1}$, that satisfy three conditions of continuity:

\begin{align} s_{k+1}(T)|_{T=t_{k+1}}&=s_{k}(T)|_{T=t_{k+1}} ,\\ s'_{k+1}(T)|_{T=t_{k+1}}&=s'_{k}(T)|_{T=t_{k+1}} ,\\ s''_{k+1}(T)|_{T=t_{k+1}}&=s''_{k}(T)|_{T=t_{k+1}} . \end{align}

This system results in \begin{align} p_{0\,k+1}&=p_{1\,k} ,\\ p_{1\,k+1}&= p_{3\,k}- \tfrac{t_{k+2}-t_{k+1}}{t_{k+1}-t_k}\cdot(p_{2\,k}-p_{3\,k}) ,\\ p_{2\,k+1}&= 2p_{1\,k+1}-p_{3\,k} +(\tfrac{t_{k+2}-t_{k+1}}{t_{k+1}-t_k})^2\cdot(p_{1\,k}-2\,p_{2\,k}+p_{3\,k}) . \end{align}

Back to the OP: assuming we have

\begin{align} t_0&=0 ,\quad t_{1}=1 ,\quad t_{2}=3 . \end{align}

Then the control points of the extension curve $q_2$ would be \begin{align} q_{02}&=p_{31} ,\\ q_{12}&=3\,p_{31}-2\,p_{21} ,\\ q_{22}&=4\,p_{11}-12\,p_{21}+9\,p_{31} . \end{align}

And since we still can choose any point as $q_{32}$, let $q_{32}=p_{32}$, so we can compare the two extension segments, which differ in the time span: for the first one we have $t_1=1$, $t_2=2$, and for the second one we have $t_1=1$, $t_2=3$.

Here is the difference:

enter image description here