Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Isaac sim IsaacGymEnvs 3D Rotation Mathematics

From Leeroopedia
Knowledge Sources
Domains 3D_Mathematics, GPU_Computing
Last Updated 2026-02-15 11:00 GMT

Overview

3D rotation mathematics encompasses the theory and operations for representing and manipulating orientations in three-dimensional space using quaternions, rotation matrices, Euler angles, exponential maps, and axis-angle representations, with quaternions being the preferred representation for GPU-accelerated physics simulation.

Description

In robotics simulation and character animation, representing the orientation of rigid bodies efficiently and correctly is fundamental. Several mathematical representations exist, each with distinct trade-offs. Rotation matrices (3x3 orthogonal matrices with determinant 1) are intuitive and compose via matrix multiplication, but require 9 parameters with 6 constraints and are expensive to normalize. Euler angles (roll, pitch, yaw) are compact with only 3 parameters but suffer from gimbal lock -- a singularity where two rotation axes align, causing loss of a degree of freedom. Axis-angle representation encodes rotation as a unit axis vector and a scalar angle, which is geometrically intuitive but awkward for composition.

Quaternions are the preferred representation in IsaacGym and GPU-accelerated simulation. A unit quaternion q = (w, x, y, z) with ||q|| = 1 represents a rotation using only 4 parameters with a single unit-norm constraint. Quaternions avoid gimbal lock entirely, compose efficiently via the Hamilton product (quaternion multiplication), and interpolate smoothly via spherical linear interpolation (SLERP). The key operations are: quat_mul(q1, q2) for composing rotations, quat_apply(q, v) for rotating a 3D vector, quat_conjugate(q) for computing the inverse rotation, and quat_slerp(q1, q2, t) for smooth interpolation between two orientations.

Exponential maps provide a bijective mapping between the Lie algebra so(3) (tangent space of rotations) and the rotation group SO(3). An exponential map vector e = theta * axis encodes both the rotation axis and angle in a single 3D vector. This representation is particularly useful for neural network outputs because it is unconstrained (any 3D vector maps to a valid rotation) and locally smooth. Conversions between all representations are essential utilities -- from quaternion to rotation matrix, from Euler angles to quaternion, from exponential map to axis-angle, and vice versa.

Usage

Use quaternion-based rotation mathematics whenever working with rigid body orientations in GPU-accelerated environments. Prefer quaternions for storing and composing rotations in tensor-based computations. Use rotation matrices when interfacing with linear algebra operations that expect matrix form. Use exponential maps as network outputs for rotation prediction. Use axis-angle or Euler angles only when required by specific APIs or for human-readable configuration.

Theoretical Basis

Quaternion multiplication (Hamilton product):

q1 * q2 = (w1*w2 - x1*x2 - y1*y2 - z1*z2, w1*x2 + x1*w2 + y1*z2 - z1*y2, w1*y2 - x1*z2 + y1*w2 + z1*x2, w1*z2 + x1*y2 - y1*x2 + z1*w2)

Rotating a vector by a quaternion:

v' = q * (0, v) * q_conjugate

SLERP interpolation:

slerp(q1, q2, t) = q1 * (q1_inv * q2)^t

Exponential map to quaternion:

theta = ||e||, axis = e / theta, q = (cos(theta/2), axis * sin(theta/2))

# Abstract 3D Rotation Operations (pseudo-code)

def quat_mul(q1, q2):
    """Compose two rotations via Hamilton product."""
    w1, x1, y1, z1 = unpack(q1)
    w2, x2, y2, z2 = unpack(q2)
    w = w1*w2 - x1*x2 - y1*y2 - z1*z2
    x = w1*x2 + x1*w2 + y1*z2 - z1*y2
    y = w1*y2 - x1*z2 + y1*w2 + z1*x2
    z = w1*z2 + x1*y2 - y1*x2 + z1*w2
    return stack(w, x, y, z)

def quat_apply(q, v):
    """Rotate vector v by quaternion q."""
    q_vec = imaginary_part(q)
    q_w = scalar_part(q)
    # Optimized formula avoiding full quaternion multiplication
    t = 2.0 * cross(q_vec, v)
    return v + q_w * t + cross(q_vec, t)

def quat_slerp(q1, q2, t):
    """Spherical linear interpolation between two quaternions."""
    cos_half_angle = dot(q1, q2)
    # Ensure shortest path
    if cos_half_angle < 0:
        q2 = -q2
        cos_half_angle = -cos_half_angle
    half_angle = arccos(clamp(cos_half_angle, -1, 1))
    sin_half_angle = sin(half_angle)
    ratio_a = sin((1 - t) * half_angle) / sin_half_angle
    ratio_b = sin(t * half_angle) / sin_half_angle
    return ratio_a * q1 + ratio_b * q2

def exp_map_to_quat(exp_map):
    """Convert exponential map (3D vector) to unit quaternion."""
    theta = norm(exp_map)
    axis = exp_map / (theta + epsilon)
    half_theta = theta / 2.0
    w = cos(half_theta)
    xyz = axis * sin(half_theta)
    return normalize(concat(w, xyz))

def quat_to_rotation_matrix(q):
    """Convert unit quaternion to 3x3 rotation matrix."""
    w, x, y, z = unpack(q)
    return matrix([
        [1 - 2*(y*y + z*z),  2*(x*y - w*z),      2*(x*z + w*y)],
        [2*(x*y + w*z),      1 - 2*(x*x + z*z),  2*(y*z - w*x)],
        [2*(x*z - w*y),      2*(y*z + w*x),       1 - 2*(x*x + y*y)]
    ])

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment