# Math

Math is actually fairly easy to understand when an easy-to-understand explanation is provided.

*This is a quick review of basic math often used in VFX.*

**Vector**

A vector has three parts: x, y, z In Maxscript this is expressed as: [x, y, z]

Think of vectors as being described relative to the origin.

The origin is 0, 0, 0.

A vector of [10, -20, 50] represents a line from the origin to x: 10, y: -20, z: 50

In essence the position is the sum of the distance in each of the 3 axes.

A vector usually has a direction component (normalized/unit vector) and a magnitude amount (length, displacement amount, speed). This can be thought of as a displacement value in a specific direction. The magnitude or length of the vector can be thought of as its speed or amount of displacement.

However, a vector can also have a magnitude of zero, in which case the vector will be [0, 0, 0]. This vector has no offset from the origin and simply represents a point in space - it has no length, speed, magnitude, displacement.

Normalized Vector (aka "Unit Vector")

A normalized or unit vector has a length or magnitude of 1.0 In TP, this is the same as "Direction" – a vector that indicates a direction but always has a length or magnitude of 1. A "normal" (direction a triangle face is pointing) is also a normalized vector.

Dot Product (aka "Scalar Product")

The dot product is a float (scalar) value that provides information about the relationship between two vectors. When dealing with normalized vectors the dot product tells us how similar is the direction between two vectors. If the dot product is 1.0 then the normalized vectors are pointing in exactly the same direction. If the dot product is 0.0 the normalized vectors are perpendicular. At -1.0 the normalized vectors are pointing in opposite directions.

This is useful when determining if two particles are heading in the same direction or not.

**Quaternion**

A quat is a representation of rotation and contains an axis and rotation amount. Quats cover the range between Pi and -Pi. Quats do smooth rotation whereas Euler Angles can flip their axes and return bad rotations. Most rotations in 3dsmax are handled internally with quaternions. The Maxscript help file has a good discussion of quats and their available functions. Quat Slerp Slerp = Spherical Linear Interpolation Slerp allows us to take two quats and blending value between 0 and 1 to return a new quat who is blended between the two starting quats. This is useful for smoothly blending between two directions over time.

**AngleAxis**

An AngleAxis contains a vector and a scalar (float) and represents a rotation around an axis. Position values rotate clockwise around the axis, and negative values are counter-clockwise. AngleAxes are not limited between Pi and -Pi, and as such they can describe rotations that contain more than one revolution. The Maxscript help file has a good discussion of angleaxes and their available functions.

**Matrix**

A matrix is a table of data with variable dimensions. The Matrix3 class in 3dsmax contains four vectors. The first three vectors contain rotation and scale data, and the last vector contains translation (position) data. The Matrix3 is commonly known as an object's "transform". It describes where the object is in space, how it is oriented and how it is scaled.

Note: in TP, a particle does not have a single "transform" – instead, the components exist as Position, Alignment and Scale.

Inverse Matrix

The inverse matrix is the matrix that describes the exact opposite of the current matrix. If my matrix describes a point in space at [100, 0, 0] then the inverse matrix returns a point in space at [-100, 0, 0] If you add the first matrix with its inverse, you get a zeroed-out matrix, (aka the "identity matrix"): matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,0]

**Putting an object into the space of another object:**

*First, we need to find the "offset matrix" of the child object (the child's transform in the inverse of the parent's transform (zeroed out) child xform in parent space:*

** offset matrix = child xform * inverse parent xform**

*if you know the offset matrix and want to move an object to a parent with that offset: e.g. "apply the offset to an object child matrix in parent space:*

** offset matrix * parent matrix**

Node Transform Matrix

The "Node Transform Matrix" is how an object's transform is calculated. It is the product of multiple parts:

**Node Transform Matrix = Controller Scale * Controller Rotation * Controller Position * Parent Transform Matrix**