Curves

8 Sept 2022


§ Motivation

Keyframe

Often in computer animation, an artist creates keyframes which is the state (position, rotation, scale, etc.) at a discrete time step.

Then, an algorithm takes these keyframes and interpolates between them to accomplish a (typically) smooth transition between the keyframes .

Almost anything can be keyframed.

Keyframing: Position and Orientation over Time

An artist may provide positions at timesteps t1,t2,t_1, t_2, and t3t_3 and we generate a curve between them to get the position at any time between t1t_1 and t3.t_3.

Keyframing: Joint Angles

We can model an arm and its movement using joint angles θ1,θ2,\theta_1, \theta_2, and θ3.\theta_3.

Then, we can define θi(t)\theta_i(t) to describe how the angles change with respect to time.

This then leaves us with the question of how we would interpolate between keyframes?

§ Representation of Curves

There are a few ways to express a curve:

Type Form Example for Circle
Explicit y=f(x)y = f(x) y=±1x2y = \pm \sqrt{1 - x^2}
Implicit f(x,y)=0f(x, y) = 0 x2+y21=0x^2 + y^2 - 1 = 0
Parametric x=f(t),y=g(t)x = f(t), y = g(t) x=cost,y=sintx = \cos t, y = \sin t

§ Explicit

  • Easy to Generate
  • Only one value of yy for each xx
  • Heavily dependent on choice of independent variable

§ Implicit

  • f(x,y)f(x, y) is a measure of the distance of a point to curve (level-set information).
  • Difficult to generate points on a curve

§ Parametric

  • Easy to generate points on a curve
  • Can have multiple yy for a given xx

§ Cubic Bézier Curve

Cubic Bézier Curve

Specify 4 "control" points, (a0,b0),,(a3,b3),(a_0, b_0), \dots, (a_3, b_3), then the cubic Bézier can be given in parametric form by

x(u)=a0+a1u+a2u2+a3u3y(u)=b0+b1u+b2u2+b3u3\begin{align*} x(u) &= a_0 + a_1u + a_2u^2 + a_3u^3\\ y(u) &= b_0 + b_1u + b_2u^2 + b_3u^3 \end{align*}

Alternatively in vector notation:

p(u)=(1u)3p0+3u(1u)2p1+3u2(1u)p2+u3p3p(0)=p0, p(1)=p3\begin{align*} \vec{p}(u) &= (1-u)^3\vec{p}_0 + 3u(1-u)^2\vec{p}_1 + 3u^2(1-u)\vec{p}_2 + u^3\vec{p}_3\\ \vec{p}(0) &= \vec{p}_0,\ \vec{p}(1) = \vec{p}_3 \end{align*}

And in matrix form:

p(u)=(p0p1p2p3)G(1331036300330001)B(1uu2u3)up(u)=GBcubic Bezier basisu\begin{align*} \vec{p}(u) &= \underbrace{\begin{pmatrix} \vec{p}_0 & \vec{p}_1 & \vec{p}_2 & \vec{p}_3 \end{pmatrix}}_{G} \underbrace{\begin{pmatrix} 1&-3&3&-1\\ 0&3&-6&3\\ 0&0&3&-3\\ 0&0&0&1 \end{pmatrix}}_{B} \underbrace{\begin{pmatrix} 1\\ u\\ u^2\\ u^3 \end{pmatrix}}_{\vec{u}}\\ \vec{p}(u) &= G\underbrace{B}_{\mathclap{\textrm{cubic Bezier basis}}}\vec{u} \end{align*}

  • Why use 4 control points?
  • The parametric equations have 8 unknowns; each point gives us 2 pieces of information.

§ Continuity in Concatenated Bézier Curves

There different classes of curve continuity

  • C0C^0, the curves are connected
  • C1C^1, tangents are the same
  • G1G^1, tagent directions are the same

They can be visualised with the following illustration

CnC^n and GnG^n are families of curves where the nnth derivative matches, but for animation C2C^2 or G2G^2 is good enough in most cases.

§ Cubic Catmull-Rom Spline

Catmull-Rom Spline

The Catmull-Rom spline is a C1C^1 curve, but it is not C2C^2. Specifically, not C2C^2 at its control points

The basis for the Catmull-Rom spline can be given by

B=12(0121205301430011)B = \frac{1}{2} \begin{pmatrix} 0 & -1 & 2 & -1\\ 2 & 0 & -5 & 3\\ 0 & 1 & 4 & -3\\ 0 & 0 & -1 & 1 \end{pmatrix}

Connecting Sequence of Control Points

Connecting a sequence of 3D/2D points can be done using a Catmull-Rom spline.

p(u)=p0, p1, p2the curve passes through the middle 2 points, p3Bu, u[0,1]p(u)=p1, p2, p3, p4Bu, u[0,1]p(u)=p2, p3, p4, p5Bu, u[0,1]\begin{align*} \vec{p}(u) &= \langle\vec{p}_0,\ \overbrace{\vec{p}_1,\ \vec{p}_2}^{\mathclap{\text{the curve passes through the middle 2 points}}},\ \vec{p}_3\rangle B\,\vec{u},\ u \in [0, 1]\\ \vec{p}(u) &= \langle\vec{p}_1,\ \vec{p}_2,\ \vec{p}_3,\ \vec{p}_4\rangle B\,\vec{u},\ u \in [0, 1]\\ \vec{p}(u) &= \langle\vec{p}_2,\ \vec{p}_3,\ \vec{p}_4,\ \vec{p}_5\rangle B\,\vec{u},\ u \in [0, 1] \end{align*}

  • Every set of 4 control points define a segment of the curve
  • "Concatenated" uu goes from [0,n3][0, n - 3] where nn is the number of control points.
  • To convert between uu concatenated to u^[0,1]\hat{u} \in [0, 1]

k=uu^=uk=ukG=[pk,pk+1,pk+2,pk+3]4×4\begin{align*} k &= \lfloor u\rfloor\\ \hat{u} &= u_k = u - k\\ G &= \big[\vec{p}_k, \vec{p}_{k+1}, \vec{p}_{k+2}, \vec{p}_{k+3}\big]_{4 \times 4} \end{align*}

Then, the curve can be computed using

p(u)=GkBuk,u[0,n1]\vec{p}(u) = G_kB\vec{u_k}, u \in [0, n - 1]

where nn is the number of control points.