# The Serious Mathematics of Digital Animation

By Matthew R. Francis

While computer simulations have a wide range of uses, their goals are generally similar: find the simplest model that recreates the properties of the system under investigation. For scientific systems, this involves matching observed or experimental phenomena as precisely as necessary.

But what about movie simulations? Should they match the processes they replicate so closely? Computer-generated imagery (CGI) is a common feature in both animated and live-action films. For these CGI systems, creating visuals that look right is an important task. However, Joseph Teran of the University of California, Los Angeles believes that starting from physical models is still a good idea.

During his invited address at the 2018 SIAM Annual Meeting, held in Portland, Ore., this July, Teran pointed out that beginning with a mathematical system is often easier than drawing from real life. Many movies model a system’s various forces and internal structures with partial differential equations (PDEs) for this reason. While solving these equations to produce CGI is computationally expensive, such methods have become powerful tools for creating realistic visual cinematic effects.

Teran and his collaborators utilized a general physical model for a wide range of movie phenomena, such as smoke, sand, snow, water and other fluids, and even clothing (see Figure 1). Teran noted that modeling everyday occurrences—such as pouring coffee or the behavior of clothes on a human body—in a convincing manner is much more difficult than simulating exotic things like exploding spaceships. The very familiarity of ordinary systems frequently exposes inconsistencies; this is in contrast to esoteric things, akin to the “uncanny valley effect”^{1} wherein attempts at realistic human faces fall short.

**Figure 1.** The coupling of elastic cloth with seven million colored grains of sand displays dazzling flow patterns. Image courtesy of [1].

### From Jell-O to Snow

During his presentation, Teran focused on a particular model known as “elastoplasticity,” which allows animators to treat a wide range of visual phenomena with a few equations, governed by a reasonable number of parameters that can be adjusted until things look right. Elastoplastic theory describes materials that both spring back when deformed (hence, elastic) and retain some of their altered shape (plastic).

For example, snow is granular on one level because it comprises small crystals that are visible to the human eye. However, a large-scale view shows that it is an elastoplastic material, as anyone who has ever made a snowball knows. How well a snowball holds together depends on its texture and “wetness,” among other things. And how well the initial handful packs together partly depends on snow’s plasticity. The crumbliness of “dry” snow—which renders it unsuitable for snowballs—also means that it blows more readily in the wind, making for easier cleanup. The varying elastoplastic properties of snow dictate whether or not it flows, thus determining the manner in which it drifts and the dangers of possible avalanches.

Based on this theoretical framework, Teran and his colleagues consulted with Walt Disney Animation Studios to generate realistic-looking snow for the computer-animated film *Frozen*. Animators must create movie special effects without having to produce simulations of various phenomena from scratch. This is when PDEs become useful, as does reduction of the physical model’s parameters, which can be adjusted based on a film’s visual needs.

The general conservation laws for mass and momentum govern these physics-based models. For materials, these equations are PDEs that describe changes in the materials’ velocity vector field \(v (x, t)\) and density \(\rho (x, t)\):

\[ \frac{Dv}{Dt} = \frac{1}{\rho} \: \bigtriangledown\:\cdot \: \underline{\sigma} + g \frac{D \rho}{Dt} + \rho \bigtriangledown\:\cdot \: v = 0,\]

where \(\textbf{g}\) is the gravitational force vector, \(\underline{\sigma} (x, t)\) is the material’s stress tensor, and

\[ \frac{D}{Dt} = \frac{\partial}{\partial t} + v \: \cdot \: \bigtriangledown\]

is the convective derivative operator. The choice of stress tensor determines which specific physical system is described.

To simulate snow, Teran and collaborators animated cubes of a Jell-O-like substance, adjusting elastic and plastic parameters to visualize how the cubes bounced or stuck together. These cubes—though very unlike snow in a broad sense—formed the basis of the mathematical description of snow’s flow, incorporating frictional forces between snow grains.

Once a software PDE solver fast enough for animation became available after several years of development, the elastoplastic formulation reduced rendering time by a massive amount. Frames of the film that would have previously entailed 40 minutes of generation time with other methods required only three to four minutes using PDEs.

Elastoplastic models are general enough to describe other materials that are useful for CGI. Teran showed his audience simulations of water interacting with sand to demonstrate how the water gradually wears away a sand barrier until it collapses. Like snow, sand is granular and exhibits small-scale behavior governed by moisture content, grain size, and frictional interactions between grains. Wet sand can also be packed (into sandcastles, for instance), though less durably than snow.

### Cloth and Deformed Potatoes

*Frozen* aside, most movies do not require many snow scenes. However, the majority of animated films have human characters who sport hair and wear clothing. These systems are both extremely familiar and very complicated to visually simulate (compare the characters’ blocky hair in early animated films like *Toy Story* or *Shrek* to modern movies like *Moana* that use advanced physics models). Elastoplastic models can also visually describe these phenomena, despite hair and clothing’s dissimilarity to snow or sand.

Teran noted that these systems can employ the same PDE solver as snow simulations. Unfortunately, clothes are not intrinsically granular, which makes them computationally much more expensive. If one treats them as a mesh of particles, the fabric texture constrains the relative positions of those particles. In addition, the external forces change constantly as different patches of cloth come in contact with other cloth, skin, and various objects. From a modeling perspective, cloth is almost *always* deformed; it creases, flaps in the wind, and clings when wet (see Figure 2).

**Figure 2.** A sphere pushes three pieces of clothâ€”with approximately 1.4 million trianglesâ€”back and forth. This yields complex folds and contact. Image courtesy of [1].

Teran described the geometrical process as “mapping a potato onto a deformed potato.” The system’s physics is encapsulated in the Jacobian or “deformation gradient” \({F}\) and its determinant \({J}\):

\[F(X, t) = \frac{\partial \phi}{\partial X} J(X, t) = \textrm{det}\big( F (X, t) \big).\]

The conservation laws and material properties in the elastoplastic model are connected to this mapping. One can linearize the system to simplify the math during each step of the deformation.

The model applies all external and internal forces acting on the cloth, mapping the motion and constraints on each grain. If the forces acting on a particle are physically unreasonable, the calculation employs constraints to restore the particle to an allowable configuration. In other words, every particle that begins in the fabric must end in the fabric in more or less the same position relative to its neighbors; this prevents unphysical deformations to the material.

The resulting elastoplastic model is amazingly powerful, allowing realistic simulation of fabrics from heavy carpets and cable-knit sweaters to light silk cloth. Teran displayed animations of sand pouring over fabric that used the elastoplastic model for both materials (see Figure 3).

**Figure 3.** Two-way coupling between a piece of elastic cloth and seven million grains of sand. Image courtesy of [1].

As with many numerical approximations to continuous systems, the accuracy of the elastoplastic simulation depends on the coarseness of the mesh that models the fabric. If the mesh is too coarse or too fine, the simulated fabric behaves incorrectly. Similarly, the types of constraints necessary to make the fabric behave appropriately are similar to the unrealistic imaginary springs that some simulations utilize for similar tasks in other animations.

Nevertheless, the ability of real physics to produce more realistic animations with lower computational costs, even when the particular physics does not naïvely seem to describe the system at hand, is intriguing. With future advances in graphics processing, animators will have an even greater ability to simulate the world, paving the way for increasingly imaginative stories.

^{1} The uncanny valley effect is the unsettling feeling that people experience upon encountering faces on robots or in digital art that are very nearly human in appearance but not quite convincingly realistic.

**References**

[1] Jiang, C., Gast, T., & Teran, J. (2017). Anisotropic elastoplasticity for cloth, knit and hair frictional contact. *ACM Trans. Graph., 36*(4), 152:1-152:14.

Matthew R. Francis is a physicist, science writer, public speaker, educator, and frequent wearer of jaunty hats. His website is BowlerHatScience.org.