Animation
Five original substantive sections, three fully worked problems, two bounded interactive numerical simulations; editorial review outstanding.
§6.1 Keyframes and time-dependent scene state
Animation is a function of time, not a sequence of unrelated pictures
An animated scene is a state that changes with time. A renderer evaluates that state at a particular instant, or integrates over an exposure interval when motion blur is required. A keyframe animation stores selected states at specified times and reconstructs the intermediate states through interpolation. This separation allows an artist to define meaningful poses without specifying every frame. It also means that a keyframe curve must be treated as a mathematical function whose continuity, speed, and extrapolation behavior can be analyzed. Simply drawing a smooth-looking path is not enough when an object must avoid collisions or synchronize with sound.
For scalar properties such as opacity or a camera's focal length, linear interpolation between values a and b at normalized time u is (1-u)a+ub. The result is continuous in position, but its derivative changes abruptly at adjacent keyframes if slopes differ. A sudden change in velocity may look like a mechanical jerk. Cubic Hermite interpolation uses endpoint values and endpoint tangents to control both position and velocity. In one dimension, the Hermite basis functions are h00=2u³-3u²+1, h10=u³-2u²+u, h01=-2u³+3u², and h11=u³-u². The interpolated value is h00 p0+h10 m0+h01 p1+h11 m1, with tangents scaled consistently for the time interval. If m0 and m1 are derivatives with respect to physical time, multiply them by the segment duration before using normalized u.
The distinction between time parameter and path distance matters. An object following a curved path at constant parameter speed does not necessarily move at constant world-space speed. The speed is the magnitude of the derivative of position with respect to time. For a parametric curve p(u), arc length from u0 to u1 is the integral of |p'(u)| du. Reparameterizing by arc length, or using a lookup table of cumulative lengths, can make a camera dolly move approximately uniformly along a spline. Without this step, a camera may visibly accelerate in tightly curved regions even though its keyframe time spacing is uniform.
A keyframe system also needs extrapolation rules. Before the first key and after the last, the value might be held constant, extended linearly, looped, or mirrored. These choices change both appearance and event timing. A looping walk cycle should not jump between the last and first pose; its position and preferably velocity should match at the seam. However, perfect mathematical continuity is not always the artistic goal. A bouncing ball has an intentional velocity discontinuity at impact in a simple rigid-body model, while a character's anticipation motion may deliberately ease into a jump.
Sampling animation at fixed display frame numbers can conceal a timing bug. If an object advances by a fixed displacement each rendered frame, its speed depends on frame rate. The correct time-based approach evaluates the animation using elapsed time or a fixed simulation timestep with interpolation for rendering. A variable frame rate is normal on real devices, so test at several rates and after pauses or dropped frames. Animation should not move twice as fast merely because a high-refresh display renders more frames per second.
§6.2 Rotation and skeletal motion
Why rotations require more care than translations
Rotations in three dimensions do not commute. Rotating a model around the x-axis and then the y-axis generally produces a different orientation from applying them in the opposite order. Euler angles are convenient for interfaces but can encounter gimbal lock, where two rotational axes align and a degree of freedom becomes locally ambiguous. Rotation matrices avoid that coordinate singularity but require maintaining orthogonality under repeated numerical updates. Unit quaternions provide a compact representation suitable for interpolating orientation, provided they remain normalized and their sign ambiguity is handled correctly.
A unit quaternion q and its negation -q represent the same three-dimensional rotation. When interpolating between two quaternion keys, choosing signs inconsistently can cause the interpolation to travel along the longer path on the unit four-dimensional sphere. A common technique checks the quaternion dot product and flips one sign when necessary before spherical interpolation. Spherical linear interpolation, or slerp, maintains constant angular speed along the selected shortest arc for a fixed pair of orientations. Linear interpolation followed by normalization, often called nlerp, is cheaper and may be adequate for small angular differences, but it does not generally preserve constant angular speed.
A skeleton is a hierarchy of joints with parent-child transforms. Each joint's local transform is composed with its parent's world transform to obtain a world-space joint transform. The mesh is attached to the skeleton through skinning weights. In linear blend skinning, a vertex is transformed by a weighted combination of bone matrices, often with weights summing to one. This method is fast and widely supported, but it can collapse volume near strongly twisted joints because averaging transformation matrices does not necessarily produce a rigid transform. Dual-quaternion skinning can better preserve volume for many rigid joint blends, although nonuniform scaling and other transformations require special handling.
The rest pose and inverse bind matrices are essential. A vertex is originally expressed in a mesh coordinate frame. To deform it with a bone, the pipeline transforms it from the rest configuration into the bone's bind-local frame and then into the bone's current posed frame. Omitting the inverse bind transform can move an apparently stationary character even when all joints are at rest. A useful invariant test is that applying the rest-pose skeleton should reproduce the original vertex positions within numerical tolerance. Test vertices attached to a single bone before debugging blended weights.
Inverse kinematics solves for joint parameters that achieve a target position or orientation. For a two-link planar arm with lengths l1 and l2, the target distance r must satisfy |l1-l2| <= r <= l1+l2 for an exact solution without stretching. The law of cosines gives cos(theta2)=(r²-l1²-l2²)/(2l1l2) for a standard joint-angle convention. There are generally elbow-up and elbow-down solutions. Joint limits, obstacles, and continuity from the previous pose determine which is appropriate. Clamping an unreachable target to the nearest reachable point can produce a stable result, but the system should report that the requested target was not exactly attained.
Animation blending and locomotion
A character often combines multiple motions: walking, turning, reaching, and reacting. Blending transforms or joint parameters with weights can produce intermediate poses, but blending arbitrary Euler angles may take an unintended rotational path. Layered animation may apply a full-body walk and an upper-body wave to different joint subsets. Additive animation represents an offset from a reference pose, which is useful for breathing or subtle reactions. The reference pose and blending order must be explicit because adding a rotation offset before or after a parent transform can produce different results.
Root motion separates the character's movement through the world from local limb movement. If a walk cycle translates the root and the game controller also advances the character, the motion can be counted twice. Conversely, keeping the root fixed while advancing the game object can make the feet slide. A robust locomotion system coordinates animation speed, root displacement, and collision handling. Foot-contact events can guide inverse kinematics so feet remain planted on uneven ground. These constraints may conflict, and a real-time system needs priorities rather than assuming every target can be satisfied simultaneously.
§6.3 Physical simulation and integration
Dynamics require forces, masses, and numerical decisions
Keyframe animation specifies motion directly. Physical simulation instead computes motion from state, forces, and constraints. For a particle with mass m, Newton's second law gives acceleration a=F/m. Integrating acceleration yields velocity, and integrating velocity yields position. Continuous equations must be approximated in a discrete program. Explicit Euler uses v_next=v+a dt and x_next=x+v dt. Semi-implicit Euler updates velocity first and then uses the new velocity for position. Both are first-order methods, but semi-implicit Euler often behaves better for simple oscillatory mechanical systems because of its different energy behavior.
Numerical stability depends on timestep, force model, and integrator. A stiff spring with a large timestep can cause an explicit method to explode even when the physical system is stable. Reducing the timestep can improve accuracy but increases computation. A fixed simulation timestep makes behavior easier to reproduce, while rendering can interpolate between stored states for smooth display. A variable timestep tied directly to frame duration can produce inconsistent collisions and constraint behavior when a frame stalls. A practical engine may accumulate elapsed time and execute several fixed-size simulation steps, with a safety cap to prevent an unbounded catch-up loop.
Collision detection asks whether bodies overlap or are about to intersect. Discrete detection checks at selected times and may miss a fast-moving small object that passes through a thin wall between frames. Continuous collision detection estimates time of impact over the interval, often using swept shapes or conservative advancement. Contact resolution then changes velocities and positions to enforce nonpenetration, friction, and restitution. These processes are separate. A perfect overlap detector cannot prevent tunneling if it is never asked about the interval between positions, and a solver can still leave visible penetration if it does not converge sufficiently.
A rigid body has both translation and rotation. Its rotational dynamics depend on the inertia tensor, which describes mass distribution about the center of mass. Applying a torque to a long thin rod can produce a different angular acceleration than applying the same torque to a compact disk of equal mass. Treating every object as a point mass with a decorative rotation is insufficient for physically credible impacts. For introductory animations, simplified rigid-body approximations may be justified, but they should not be used to claim engineering-grade contact forces or structural deformation.
Cloth and soft bodies introduce many coupled degrees of freedom. A mass-spring cloth model connects particles through structural, shear, and bending constraints. A position-based dynamics approach can enforce constraints by adjusting positions iteratively, often producing stable interactive motion even with simplified force interpretation. The tradeoff is that visually plausible behavior does not automatically correspond to calibrated elastic material properties. If the goal is scientific prediction, discretization, constitutive laws, damping, convergence, and validation against measured experiments become essential.
Energy and constraint diagnostics
For a mass on a spring without damping, mechanical energy is E=0.5 m v²+0.5 k x². An ideal integrator should approximately preserve this energy over time within its numerical properties. Explicit Euler tends to add energy for a simple oscillator under common conditions, while symplectic methods often keep energy bounded over long runs at sufficiently small timesteps. Plotting energy against time is more informative than merely watching an animation, because a slowly growing oscillation can look natural for a few seconds while being numerically unstable.
A constraint solver should also expose residual errors. For a rigid rod of length L connecting points a and b, the length residual is |b-a|-L. If the residual grows, the system is not enforcing the constraint adequately. Report maximum residual, not only average residual, because a single badly violated constraint can create a visible artifact. If the solver uses iterative correction, compare results across iteration counts and timesteps. Convergence evidence is more valuable than asserting that a chosen number of iterations is always enough.
§6.4 Interpolation, motion blur, and temporal consistency
Sampling a moving scene
A shutter-open camera integrates light over a time interval. A moving object occupies different positions during that interval, so a physically motivated motion-blur renderer samples the scene at several shutter times. Simply drawing a blurred line between the previous and current screen positions can approximate some motion but cannot account correctly for occlusion changes, rotations, deformation, or camera movement. For a spinning propeller, temporal sampling may reveal distinct blade patterns or smooth blur depending on shutter duration and sample count. These are consequences of time integration, not merely artistic effects.
Motion vectors describe projected movement between frames and support temporal reconstruction and postprocess blur. They must be computed consistently for moving objects, skinned geometry, and camera motion. A common failure is to use current and previous camera matrices while forgetting previous bone transforms; the body then appears to move while animated limbs leave incorrect streaks. Newly visible surfaces have no reliable previous-frame history, so temporal algorithms need disocclusion handling. Excessive history reuse causes ghosting; overly aggressive rejection produces flicker and noise.
Interpolating physical states for rendering is not the same as extrapolating the simulation. If the physics engine stores states at times t0 and t1, the renderer can blend between them using a fractional parameter when displaying an intermediate time. This adds a small visual delay but avoids coupling physics to fluctuating display rates. Extrapolation predicts beyond the newest simulated state and can reduce apparent latency, but it can be wrong near collisions or sudden control changes. Choose explicitly according to application needs and test with abrupt reversals and dropped frames.
Animation curves should be evaluated with attention to precision. A long-running timeline represented by a low-precision floating-point number can lose the ability to distinguish nearby frame times. Storing a local time within each clip or using a higher-precision timeline reduces drift. Events such as footsteps or dialogue cues should be triggered by crossing event times rather than equality comparisons with floating-point timestamps. When the playback direction reverses or a loop wraps, event logic must handle the interval correctly so cues are neither skipped nor repeated accidentally.
§6.5 Integrated investigation: a robotic arm animation
Combine authored intent with reachable motion
A training visualization shows a two-link robotic arm moving a tool between inspection points. The director wants smooth cinematic motion, while an engineering reviewer wants joint angles and endpoint positions that are kinematically consistent. Begin with a simple geometric model: two rigid links connected by revolute joints, known link lengths, and a fixed base. Define the coordinate frame at each joint and verify the forward kinematics by testing easy poses, such as both links aligned horizontally. Do not introduce realistic textures before the geometric motion is correct.
Create a sequence of target positions. Use inverse kinematics to find candidate joint angles, checking the reachable annulus before attempting to solve. Select elbow-up or elbow-down configurations consistently across adjacent frames to avoid sudden branch flips. Interpolate the joint angles using curves that respect joint limits and speed constraints. A smooth tool path in Cartesian space does not guarantee smooth joint motion near singular configurations, so inspect angular velocity as well as endpoint velocity. Where a target is unreachable, display a visible warning and move to the nearest valid point rather than silently stretching the links.
If the arm carries a payload, add a simplified physical model only for effects the demonstration intends to explain. A hanging cable may be animated with a lightweight constraint solver, but the tool path should remain governed by the kinematic controller. Test the cable at several fixed timesteps and track length-constraint residuals. Avoid interpreting a visually pleasing cable swing as a verified prediction of real tension without material parameters and experimental calibration. This distinction lets the training visualization remain informative without overstating simulation accuracy.
For presentation, sample the animated scene at shutter times to generate motion blur in the final render, while keeping the technical view sharp and labeled. Show the current joint angles, tool position, and any limit violations. Record the clip's timebase, interpolation method, link lengths, and coordinate convention in the export metadata. Reopen the exported animation and compare several poses numerically against the authoring environment. The investigation is successful when the visual story and the kinematic measurements describe the same motion.
Step-by-Step Programming Fundamentals Solutions
Three original questions connect calculations, definitions and interpretation. Open each solution to follow the reasoning.
A scalar animation moves from p0=2 at time t=0 to p1=10 at time t=4 seconds. Both endpoint velocities are zero. Use cubic Hermite interpolation to find position at t=1 second and velocity at that time.
The segment duration is 4 seconds, so u=t/4=0.25. Since endpoint velocities are zero, the Hermite tangent contributions vanish. The curve reduces to p(u)=(2u³-3u²+1)p0+(-2u³+3u²)p1.
At u=0.25, u²=0.0625 and u³=0.015625. The interpolation weight for p1 is -2(0.015625)+3(0.0625)=0.15625. Hence p=2+(10-2)×0.15625=3.25.
The derivative of the p1 weight with respect to u is -6u²+6u=1.125. Thus dp/du=8×1.125=9. Since du/dt=1/4, velocity is dp/dt=2.25 units per second. It is nonzero inside the interval even though both endpoint velocities vanish.
Position 3.25 and velocity 2.25 units/s at t=1 s.
A planar arm has two links of lengths l1=3 and l2=2. The tool target is (3,2) relative to the base. Determine whether the target is reachable and calculate the elbow angle theta2 using the standard two-link law-of-cosines convention.
The target distance is r=sqrt(3²+2²)=sqrt(13), approximately 3.606. The reachable distance interval is [|3-2|,3+2]=[1,5], so the target is reachable in the ideal unrestricted model.
The relation is cos(theta2)=(r²-l1²-l2²)/(2l1l2)=(13-9-4)/(12)=0. Therefore theta2=arccos(0)=90 degrees for the positive elbow branch, or -90 degrees for the other branch in a signed convention.
Both branches can place the tool at the target with different shoulder angles. Joint limits or nearby obstacles may make one branch invalid. The calculation says nothing about collision-free motion between the previous pose and the target pose.
Reachable; elbow angle magnitude 90 degrees, with two possible signed branches.
A particle starts at x=0 with velocity v=2 m/s and constant acceleration a=3 m/s². Use one timestep dt=0.1 s to calculate its new position and velocity with explicit Euler and semi-implicit Euler. Compare both with the exact constant-acceleration position.
Both methods use vnext=v+a dt=2+3(0.1)=2.3 m/s for this simple constant-acceleration step.
Explicit Euler uses the old velocity: xnext=0+2(0.1)=0.2 m. Semi-implicit Euler uses the new velocity: xnext=0+2.3(0.1)=0.23 m.
Exact position is x+v dt+0.5 a dt²=0+0.2+0.015=0.215 m. Explicit Euler is 0.015 m low, while semi-implicit Euler is 0.015 m high. Neither method is exact for this step, and this one example does not prove that one method is always more accurate.
Both give vnext=2.3 m/s; explicit Euler x=0.2 m, semi-implicit Euler x=0.23 m, exact x=0.215 m.