up to Schedule & Notes

Object State

Instead of keyframing, we can animate objects according to the laws of physics.

We'll consider rigid objects only. Animation of deformable objects can also be modelled with physics, but it's much more difficult.

In animation, we'll take the object state at a particular time, then update the state for a later time. This is repeated over time to create an animation.

An object, at any instant in time, has a position and orientation: $$\textrm{position } x = [ x_0\ x_1\ x_2 ]^T$$ $$\textrm{orientation } q = [ q_0\ q_1\ q_2\ q_3 ]^T$$

We will use the notation (above) that $x$ is a vector with three components, rather than the more usual $x, y, z$ notation in which $x$ is one of the components.

Quaternions

A quaternion is a compact way of representing orientation (via rotation from a standard position).

Quaternion $q = [ q_0\ q_1\ q_2\ q_3 ]$ represents rotation by angle $\theta$ about an axis $a$: $$q_0 = \cos{\theta \over 2}$$ $$a = \sin{\theta \over 2}\ [ q_1\ q_2\ q_3 ]^T$$

We can convert between quaternions and equivalent $3 \times 3$ rotation matrices: $$\left[\begin{array}{c} q_0 \\ q_1 \\ q_2 \\ q_3 \end{array}\right] \ \ \Longleftrightarrow\ \ 2\ \left[\begin{array}{cccc} q_3\ q_3 + q_0\ q_0 - \frac12 & q_0\ q_1 - q_3\ q_2 & q_0\ q_2 + q_3\ q_1 \\ q_0\ q_1 + q_3\ q_2 & q_3\ q_3 + q_1\ q_1 - \frac12 & q_1\ q_2 - q_3\ q_0 \\ q_0\ q_2 - q_3\ q_1 & q_1\ q_2 + q_3\ q_0 & q_3\ q_3 + q_2\ q_2 - \frac12 \end{array}\right]$$

Thinking geometrically, since $|q| = 1$, $q$ is a point on a 4D sphere. Each point on this 4D sphere represents a particular orientation (as a rotation from a standard position).

By the way: This is the key to interpolating between two orientations, $q_a$ and $q_b$: Write each orientation as a quaternion (i.e. a point on the 4D sphere) and find the great circle arc (in 4D!) that joins $q_a$ and $q_b$. Moving along that great circle arc interpolates smoothly (and "naturally") between the orientations.

Object State

An object's state, $(x,v,q,\omega)$, consists of its position and velocity, both translational $$\textrm{position } x = [ x_0\ x_1\ x_2 ]^T$$ $$\textrm{velocity } v = [ v_0\ v_1\ v_2 ]^T$$

and rotational: $$\textrm{orientation } q = [ q_0\ q_1\ q_2\ q_3 ]^T$$ $$\textrm{angular velocity } \omega = [ \omega_0\ \omega_1\ \omega_2 ]^T$$

For angular velocity $\omega$:

For the time derivative of $p$ we will use the notation $\dot{p} = {dp \over dt}$.

Then $v = \dot{x}$.

But $w \neq \dot{q}$. Actually, $$\dot{q} = Q\ \omega$$

or $$\dot{q} \;=\; \left[\begin{array}{c} \dot{q_0} \\ \dot{q_1} \\ \dot{q_2} \\ \dot{q_3} \end{array}\right] \;=\;\; \underbrace{\frac12\ \left[ \begin{array}{rrr} -q_1 & -q_2 & -q_3 \\ q_0 & -q_3 & q_2 \\ q_3 & q_0 & -q_1 \\ -q_2 & q_1 & q_0 \end{array}\right]}_{Q} \ \ \left[\begin{array}{c} \omega_0 \\ \omega_1 \\ \omega_2 \end{array}\right]$$

So, in summary, we have: $$\begin{array}{ccl} \textrm{state} & \textrm{derivative} & \\ x & \dot{x} & \textrm{velocity} \\ \dot{x} & \ddot{x} & \textrm{acceleration} \\ q & \dot{q} & = Q\ \omega \\ \omega & \dot{\omega} & \textrm{angular acceleration} \end{array}$$

How does the object state change?

Consider the velocity, $\dot{x}(t)$ as it changes from time $t$ to time $t+\Delta t$:

In this same interval, the position, $x$, changes as $$\Delta x = \int_{t}^{t + \Delta t} \dot{x}(t)\ dt$$

In other words, the change in position is the area (both positive and negative) under the velocity curve.

The same applies to the other state variables: $\dot{x}, q, \omega$.

Integral approximation

An approximation of this integral is $$x(t+\Delta t) \approx x(t) + \Delta t\ \dot{x}(t)$$

This assumes that the average $\dot{x}$ over the interval is equal to the value at the start of the interval, $\dot{x}(t)$.

The error in this approximation is ${\cal O}( \Delta t^2 )$ from the Taylor series expansion of $x(t)$.

The method above is called Euler Integration.

Euler Integration is probably the worst integration method. It usually requires very small time steps to avoid the accumulation of error over multiple steps.

In production code, you should use something better, like fourth-order Runge Kutta integration. This is harder to implement, but is much more accurate.

The state vector

Let $y$ be the state vector, which contains the state of each of the $n$ objects being animated: $$y = [ x_1\ q_1\ \dot{x}_1\ \omega_1\ \ \ x_2\ q_2\ \dot{x}_2\ \omega_2\ \ \ \dots\ \ \ x_n\ q_n\ \dot{x}_n\ \omega_n ]^T$$

Its derivative is $$\dot{y} = [ \dot{x}_1\ \dot{q}_1\ \ddot{x}_1\ \dot{\omega}_1\ \ \ \dot{x}_2\ \dot{q}_2\ \ddot{x}_2\ \dot{\omega}_2\ \ \ \ldots\ \ \ \dot{x}_n\ \dot{q}_n\ \ddot{x}_n\ \dot{\omega}_n ]^T$$

and we update the state vector with $$y(t+\Delta t) = y(t) + \int_t^{t+\Delta t} \dot{y}(t)\ dt$$

But we need the values in $\dot{y}$ to do this integration:

$\ddot{x}_i$ and $\dot\omega_i$ can be determined from physics.

up to Schedule & Notes