Transforms are used in game development to describe the position, rotation and scale of objects in a virtual world. These properties are encoded in a coordinate transformation, which is a function that transforms the object’s local coordinates into the world’s coordinates. These functions are invertible affine maps, consisting of an invertible linear map and a translation.

Modern games often feature complex objects, each made up of several sub-objects. To manage this complexity it has become common to organize the game objects into a hierarchy, where each object is assigned a parent, which is either another object or the world itself. This forms a tree structure with the world as the root. In such a hierarchy, each object’s transform describes its position, rotation and scale *relative to its parent*. The textbook example is a tank and its turret — the turret has a constant position and scale relative to its parent tank, but can rotate of its own accord.

In order to determine the transform of an object relative to the world, the individual transforms are composed by walking through the tree from the object to the root. Each transform in the sequence transforms from child to parent and the result of the composition is a single transform that describes the object relative to the world.

However, when dealing with dynamics we must acknowledge that these transforms are changing over time. In order to advance a transform forward in time, we could do everything in global terms — applying global velocities and accelerations and then converting the new global transform back into a local transform. This approach is easier, but it effectively bypasses the hierarchy as far as dynamics is concerned.

An interesting alternative is to use local velocities and accelerations, which allows the local transforms to be updated directly. In order take this approach, we need to understand how to convert these velocities and accelerations between the different frames of reference. This is especially important when the dynamics is being driven by physics, such as Newtonian mechanics. Physical forces produce acceleration, and given the acceleration of an object relative to the world, we must determine the acceleration of the object relative to its parent. This will involve taking into account the dynamics of each object in the tree between it and the root. This article explores the mathematics needed to do this.

We begin by expressing the algebraic structure of transforms in terms that keep the translation, rotation and scale components separate (rather than mixing them into a single matrix). Then we discuss our preferred description of the dynamics of a transform using linear and angular velocities and accelerations. The key step is then to extend the algebraic structure to include these velocities and accelerations, which provides the machinery to convert the dynamics between different frames of reference. This is used to derive local-to-global and global-to-local conversions of velocity and acceleration. These results are applied to instantaneous modifications of the dynamics (e.g. by impulses) to gain corresponding conversions for discrete changes in velocity and acceleration.

Finally, we look at a couple of example applications. The first shows how to apply Newtonian forces to generate local accelerations, which results in the well-known inertial forces arising. The second application is for linear impulses, where we also discuss how to counteract inherited changes, which is important for correct collision response.

## Transforms

To begin, let’s define more precisely what kind of transforms we are dealing with. Nothing in this article is specific to 3-dimensional space, so we will work in -dimensional space. Let a transform be a triple consisting of a translation vector , a rotation matrix , and a positive scale factor . As a function , the transform acts on a coordinate vector by

i.e. the scale is applied first, then the rotation, and finally the translation. We will write the linear part as . The linear part coincides with the Jacobian of the map (hence the notation) and its action performs a change of basis. If is a transform from child to parent then is a change of basis from the child basis to the parent basis.

Transforms form a group under composition. We can express the group structure (i.e. composition, identity, inverse) in terms of the individual translation, rotation and scale components.

### Composition of Transforms

The composition of two transforms is a third transform. The resulting transform can be expressed with separate translation, rotation and scale components:

where

Note that the composition of functions means that is applied first, then .

Some implementations allow for multiple scale factors, one for each axis, which are usually stored as a vector. The use of a vector for this can be rather misleading — the correct interpretation is a diagonal matrix. When composing such transforms, the scaling matrix loses its diagonality. It becomes a mixture of diagonal scalings and rotations, which requires the full matrix to describe. For this reason we will restrict ourselves to a single scale factor.

### Identity Transform

The identity transform does nothing, . It is given by : the null vector , the identity matrix , and the unit scalar .

### Inverse Transform

The inverse of a transform is a transform denoted that is defined by

i.e. the inverse undoes the action of the transform, resulting in the identity transform. It is given by

where

and is the matrix transpose of , which describes the inverse rotation. is the linear part of the inverse, which is the inverse of the linear part,

## Dynamics of the Transform

To describe how a transform is changing over time we need to consider the time derivatives of the three components. In this article we are going to assume that the scale factor is constant. It’s unusual to have a time-varying scale factor, and taking it to be constant simplifies some of the following equations.

For the translational and rotational parts, we will consider the first two time derivatives (velocity and acceleration). Dynamics in this domain is often specified by second-order differential equations, such as Newton’s second law, and it is unusual to encounter derivatives of third-order or higher, so two should be sufficient for most applications.

### Describing Translational Dynamics

Since the translation describes the relative position of the object to its parent, the relative velocity is its first derivative and the relative acceleration is its second derivative,

### Describing Rotational Dynamics

The dynamics of the rotation is given by the derivatives and . However, it is not convenient to use these quantities directly. We are using matrices to describe rotations, but only a relatively small number of matrices are valid rotation matrices. The valid matrices form a smooth geometric object — a manifold — within the ambient space of matrices. The time derivative is a tangent vector to this manifold. Due to the curvature of this manifold, the types of matrix that describe valid tangent vectors is dependent on the current rotation, . This means we cannot choose independently of .

What we would like is a way to specify the time derivative in terms independent of the current rotation, analogous to the way we can choose a velocity independently of the current position. We do this by describing the time derivative using a vector in the tangent space at the identity rotation, . This tangent vector can be associated with a tangent vector at by

We call the matrix an angular velocity. The tangent space at the identity is denoted and consists of skew-symmetric matrices, i.e.

This follows straightforwardly from the definition of a rotation matrix (by differentiating the orthogonality constraint). The skew-symmetry is preserved by addition and scalar multiplication, which isn’t surprising given that it characterizes a vector space. Although individual matrix multiplications do not preserve skew-symmetry, the space does feature a Lie bracket given by the matrix commutator, .

Although the angular velocities are matrices, we do not need scalars to describe them. The dimension of the rotation group (and hence its tangent spaces) is . This means for 2-dimensional space we need only a single scalar,

The action of this matrix on a 2-vector corresponds to scalar multiplication of the perpendicular vector,

where the perpendicular vector is . The commutator vanishes for the 2-dimensional case, .

For 3-dimensional space we need 3 scalars,

This allows for an angular velocity to be interpreted as a 3-vector . Under this identification, the action of the matrix on a 3-vector corresponds to the cross product . Similarly, the commutator of the matrix representations corresponds to the cross product of the vector representations, . Since this vector interpretation of angular velocity is unique to the 3-dimensional case, we will keep things in the matrix form. The matrix form is also a bit nicer to work with, since matrix multiplication is associative, while the cross product is not.

The second derivative is then given by

where we have defined the angular acceleration,

The angular accelerations are also skew-symmetric matrices. This allows us to choose , and independently of each other while still providing a complete description of and .

So a transform and its dynamics can be described in terms of the quantities . Now that we have decided how to describe the dynamics of individual transforms, we can extend the transforms’ group structure to include the velocities and accelerations. This algebraic structure will be the means by which we convert between local and global descriptions of an object’s dynamics.

### Dynamics of the Composition

To compute the dynamics of the composition, we take the expression for the composition of two transforms and compute the derivatives of its translation and rotation components. The definitions of velocity and acceleration are then used to identify , , and for the composition.

.

### Dynamics of the Inverse

The inverse converts a child-to-parent transform into a parent-to-child transform. The inverse transform describes the parent relative to the child. By computing the time derivative of the expression for the inverse, we can express the dynamics of the parent relative to the child.

.

### Dynamics of the Identity

The identity transform describes an object *relative to itself*. The dynamics of such a transform is null:

.

Note that and are null vectors, while and are zero matrices (the zero matrix is skew-symmetric).

The interpretation of this is that an object is always at rest relative to itself, regardless of its dynamics relative to other objects/the world.

## Local and Global Dynamics

We now have enough machinery to convert between local and global descriptions of an object’s dynamics.

For each object we can describe its velocities and accelerations either locally (relative to the parent) or globally (relative to the world). For objects that are parented to the world these notions coincide, but in general they do not.

Let an object have transform relative to its parent, and the parent have transform relative to the world.

### Converting Local Dynamics To Global Dynamics

The composition describes the object relative to the world. Given its local dynamics, and the global dynamics of the parent, the object’s global dynamics is given by the dynamics of the composition, given above.

In the case where there are many levels in the hierarchy between the root and the object, each node’s global dynamics depends on the global dynamics of its parent. This approach can be applied recursively, in exactly the same way that a transform hierarchy usually operates. In iterative terms this means starting at the root and walking through the tree towards the object, computing the global transform (and dynamics) of each node in sequence.

### Converting Global Dynamics To Local Dynamics

If we are given the dynamics of (the global dynamics of the object), and want to find the dynamics of (the local dynamics of the object), we can express in terms of and via

The dynamics of is then given by combining the dynamics of the inverse of with the dynamics of the composition with :

The velocity and acceleration can also be written as

## Local and Global Deltas

There are occasions when it is necessary to make instantaneous modifications to the velocity and acceleration of an object. A relevant example is modifying an object’s velocity in response to a collision. We can use the above results to convert the changes in velocities and accelerations between local and global forms.

As before, is the child to parent transform, is the parent to world transform, and is the child to world transform. These transforms are assumed to be unchanged by the interaction, and the velocity/accel is modified instantaneously, meaning no time elapses between the old and new velocities/accelerations.

#### Global change in child due to local change in child

#### Local change in child required to produce the given global change in child

This is just the inverse of the above.

#### Global change in child due to global change in parent

A child’s global dynamics depends on both its local dynamics and its parent’s global dynamics. If the child is locally unmodified but the parent is globally modified then the child’s global dynamics changes according to the following.

## Example: Newtonian Mechanics — Force to Acceleration

In Newtonian mechanics, the dynamics of an object is driven by forces, which are influences that determine its acceleration via , where is the total force, and is the mass of the object. However, this is only valid in what physicists call an *inertial frame*, which is a frame of reference that is either stationary or moving with constant (translational) velocity — no acceleration or rotation. This corresponds to our world frame, the root of the hierarchy.

Consider a non-inertial frame, such as the Earth, which has translational velocity and acceleration due to its orbit around the Sun, angular velocity due to its rotation around its axis, and even some angular acceleration that causes its axis to precess. Let us also have an object that is parented to the non-inertial frame, such as a vehicle on the Earth.

If the Earth has transform and the vehicle has transform then we can convert the acceleration of the object relative to the world to acceleration relative to the Earth by using the global-to-local acceleration equation above,

We can write this in terms of the applied force and mass ,

Recall that the role of is only to change between bases; it does not affect the meaning of the vector it acts on. Therefore let’s introduce a bit of notation:

- Applied force expressed in the Earth basis: .
- Acceleration of the Earth relative to the world expressed in the Earth basis: .
- Angular velocity of the Earth relative to the world expressed in the Earth basis: .
- Angular acceleration of the Earth relative to the world expressed in the Earth basis: .

With this notation, the local acceleration becomes much cleaner:

The local acceleration is therefore given not only by the applied force, but by four additional contributions due to the global dynamics of the parent. The additional four terms are conventionally interpreted as extra forces (by ), and are known to physicists as *inertial forces*. They are regarded as `fictitious’ forces, as they do not result from physical interactions.

- The linear inertial acceleration:
- The Centrifugal acceleration:
- The Coriolis acceleration:
- The Euler acceleration:

This illustrates that in the absence of applied forces an object may still experience local accelerations due to the dynamics of its parent.

Since we have kept this in the -dimensional matrix form, it is now easy to go into the 2- and 3-dimensional specializations.

### In 3D

In 3D, the skew-symmetric matrices are identified with 3-vectors, and their action on a vector becomes the cross product:

- Centrifugal:
- Coriolis:
- Euler:

Since physicists usually operate in 3-dimensions using the vector version of angular velocity, this form may be more familiar.

### In 2D

In 2D, the skew-symmetric matrices are identified with scalars, and their action on a vector becomes scalar multiplication with the perpendicular vector, :

- Centrifugal:
- Coriolis:
- Euler:

## Example: Newtonian Mechanics — Linear Impulses

An impulse is the integral of an applied force over a given time interval. In an inertial frame this is equal to the overall change in momentum produced by that force acting over the time interval. However, when a large force acts over a very small time interval it is often not feasible to simulate the action of the force itself. Instead, the corresponding impulse can be applied as an instantaneous modification to the object’s dynamics. A relevant example is collision response.

An impulse corresponds to a change in velocity, , in the same way that a force corresponds to an acceleration. In order to convert the global change in velocity into a local change in velocity, we use the global-to-local conversion of delta.

Let the global delta be then, applying the formulae above, the local deltas are

This shows that applying an impulse can causes changes in both the local velocity and the local acceleration of an object. The change in acceleration is due to the Coriolis term, which is dependent on velocity.

### Counteracting the Inherited Effect from the Parent

When the parent’s global dynamics have been modified, all of its children (and childrens’ children etc.) will automatically inherit this modification to their own global dynamics thanks to the hierarchy. There may be some applications where this is undesirable and you want to modify an object in isolation. An example is a car crash — the dynamic child objects inside the car should continue globally moving forward when the car crashes, otherwise they will appear to be fixed to the car.

To do this we need to add the opposite global effect to the immediate children of the object that has been modified to counter the inherited changes to their dynamics. The childrens’ children will inherit this correction automatically and do not need to be corrected further. If is the global change in velocity that has been added to the parent, then for each child the local velocity and acceleration need to be updated by

It is especially important to do this when a child collides with its parent (or the parent’s parent etc.) to get the correct collision response.

## Implementation

To implement this approach, you will need not only a Transform class, but also a DynamicTransform class. Both of these will have the group structure of composition, identity and inverse derived in this article. A hierarchy can then be made in the usual way, just using DynamicTransforms in place of Transforms.

Here is a sketch to illustrate.

template<typename T,int N> struct Transform { Vec<T,N> translation; Rotation<T,N> rotation; T scale; // Function evaluation Vec<T,N> operator()( const Vec<T,N>& rhs ) const; // Composition Transform<T,N> operator*( const Transform<T,N>& rhs ) const; Transform<T,N>& operator*=( const Transform<T,N>& rhs ); Transform<T,N> Inverse() const; static const Transform<T,N>& Identity(); // Linear part Transform<T,N> LinearTransform() const; // Inverse transpose of linear part Transform<T,N> NormalTransform() const; // To augmented matrix representation Mat<T,N+1,N+1> ToMatrix() const; }; template<typename T,int N> struct DynamicTransform { Transform<T,N> transform; Vec<T,N> velocity, accel; Skew<T,N> angularVelocity, angularAccel; // Composition DynamicTransform<T,N> operator*( const DynamicTransform<T,N>& rhs ) const; DynamicTransform<T,N>& operator*=( const DynamicTransform<T,N>& rhs ); DynamicTransform<T,N> Inverse() const; static const DynamicTransform<T,N>& Identity(); // Transform deltas using this dynamic transform Vec<T,N> TransformDeltaVel( const Vec<T,N>& dv ) const; Vec<T,N> TransformDeltaAcc( const Vec<T,N>& dv, const Vec<T,N>& da ) const; Skew<T,N> TransformDeltaAngVel( const Skew<T,N>& domega ) const; Skew<T,N> TransformDeltaAngAcc( const Skew<T,N>& domega, const Skew<T,N>& dalpha ) const; };

## A Quick Note On Rigid Body Dynamics

For application to rigid bodies, the `positions’ of objects here correspond to the centre of mass of the rigid body. This is because rigid body motion is decomposed into rotations about the centre of mass and translations of the centre of mass.

## Conclusion

We have discussed the algebraic structure of -dimensional transforms consisting of translation, rotation and scale components, and described their dynamics in terms of linear and angular velocities and accelerations. By extending the algebraic structure to include these velocities and accelerations, we can convert between local and global descriptions of an object’s dynamics. The resulting equations apply to any number of dimensions, to any source of dynamics, and to a hierarchy of arbitrary depth. This in turn allowed us to convert instantaneous changes in velocity and acceleration between local and global frames of reference. We applied these results to the example of Newtonian mechanics, where the global-to-local conversion of acceleration produces the well-known inertial forces, and to the example of linear impulses.