🤔

Quaternion: Multiplication#

Declaration#

Quaternion * Quaternion
Quaternion * Vector3

Description#

Multiplication rotates an orientation or point, combining them in sequence. A * B, A rotates B.

Usage: Rotating vectors#

Local space directions can be multiplied by a world space orientation to produce their world space counterpart.
This is how Transform up, right, and forward work:

// The red axis of the transform in world space.
public Vector3 right { get { return rotation * Vector3.right; } ... }

// The green axis of the transform in world space.
public Vector3 up { get { return rotation * Vector3.up; } ... }

// The blue axis of the transform in world space.
public Vector3 forward { get { return rotation * Vector3.forward; } ... }

Interactive diagram#

Drag the axes to change A, drag the sphere to modify B.
Press X to alternate between local and world space handles.

Reset

Vector3 result = A.rotation * new Vector3(0, 1, 0);

The logic can be applied to rotate any point around its origin.

Rotate around#

RotateAround combines vector arithmetic and AngleAxis with multiplication, here is an annotated version of the logic:

public void RotateAround(Vector3 point, Vector3 axis, float angle)
{
// Create the rotation to transform with
Quaternion q = Quaternion.AngleAxis(angle, axis);
// localPoint is position if point was the new origin
Vector3 localPoint = transform.position - point;
// Rotate localPoint with q around its new origin
localPoint = q * localPoint;
// Reconstruct world space position, and transform our rotation.
transform.SetPositionAndRotation(point + localPoint, q * transform.rotation);
}

Usage: Rotating quaternions#

Quaternion multiplication isn't commutative, A * B != B * A.
Rotating A influences B as a parent rotation.
Rotating B influences A as a local space modification.
To form an intuition about the influence of A or B on the result, interact with the diagram below.

Interactive diagram#

Drag the axes to interact with A or B, press X to alternate between local and world space handles.

Reset

transform.rotation = A.rotation * B.rotation;

Return to Quaternions.
Next, Quaternion.Inverse.