Implementation:Isaac sim IsaacGymEnvs Rotation3D
| Knowledge Sources | |
|---|---|
| Domains | 3D_Mathematics, Quaternion_Operations |
| Last Updated | 2026-02-15 11:00 GMT |
Overview
The rotation3d module provides a comprehensive library of @torch.jit.script-decorated functions for 3D rotation mathematics, including quaternion arithmetic, conversion between rotation representations, and interpolation operations.
Description
The module at isaacgymenvs/tasks/amp/poselib/poselib/core/rotation3d.py implements a complete set of JIT-compiled 3D rotation utilities built on PyTorch tensors. All functions use the @torch.jit.script decorator, enabling TorchScript compilation for optimized GPU execution. The quaternion convention used is (x, y, z, w) ordering throughout the module.
The core quaternion operations include quat_mul() for quaternion multiplication, quat_inverse() for computing the conjugate/inverse, quat_rotate() for rotating 3D vectors, and quat_unit() for normalization. The module also provides quat_slerp() for spherical linear interpolation between quaternions, which is essential for smooth motion blending in character animation pipelines.
Conversion functions bridge between multiple rotation representations: quat_from_angle_axis() and its inverse, quat_to_rotation_matrix() and rotation_matrix_to_quat(), euler_to_quat() and quat_to_euler(). Additional utilities include quat_between() for computing the rotation between two vectors, quat_pos() for ensuring positive real parts, and quat_abs() for computing quaternion norms. All functions operate on batched tensors, supporting parallel computation across thousands of environments simultaneously.
Usage
Use these rotation functions throughout the AMP and poselib pipeline for skeleton pose manipulation, motion retargeting, and any task requiring efficient batched 3D rotation math on the GPU. They are the primary rotation utilities for the poselib skeleton system.
Code Reference
Source Location
- Repository: IsaacGymEnvs
- File: isaacgymenvs/tasks/amp/poselib/poselib/core/rotation3d.py
- Lines: 1-472
Signature
@torch.jit.script
def quat_mul(a, b):
"""Quaternion multiplication (x, y, z, w) convention."""
@torch.jit.script
def quat_pos(x):
"""Ensure positive real (w) component of quaternion."""
@torch.jit.script
def quat_abs(x):
"""Compute quaternion norm (L2)."""
@torch.jit.script
def quat_unit(x):
"""Normalize quaternion to unit length."""
@torch.jit.script
def quat_from_angle_axis(angle, axis):
"""Create quaternion from angle-axis representation."""
@torch.jit.script
def quat_inverse(x):
"""Compute quaternion inverse (conjugate for unit quaternions)."""
@torch.jit.script
def quat_between(v0, v1):
"""Compute rotation quaternion that rotates v0 to v1."""
@torch.jit.script
def quat_rotate(rot, v):
"""Rotate 3D vector by quaternion."""
@torch.jit.script
def quat_slerp(q0, q1, t):
"""Spherical linear interpolation between two quaternions."""
@torch.jit.script
def quat_to_rotation_matrix(q):
"""Convert quaternion to 3x3 rotation matrix."""
@torch.jit.script
def rotation_matrix_to_quat(m):
"""Convert 3x3 rotation matrix to quaternion."""
@torch.jit.script
def euler_to_quat(e):
"""Convert Euler angles to quaternion."""
@torch.jit.script
def quat_to_euler(q):
"""Convert quaternion to Euler angles."""
Import
from isaacgymenvs.tasks.amp.poselib.poselib.core.rotation3d import quat_mul, quat_rotate, quat_slerp
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| a, b | Tensor(..., 4) | Yes | Quaternion tensors in (x, y, z, w) format for multiplication and related operations |
| angle | Tensor(...) | Yes | Rotation angles in radians for angle-axis conversion |
| axis | Tensor(..., 3) | Yes | Unit rotation axis vectors for angle-axis conversion |
| v, v0, v1 | Tensor(..., 3) | Yes | 3D vectors for rotation or between-vector computation |
| q, q0, q1 | Tensor(..., 4) | Yes | Quaternion tensors for slerp and conversion operations |
| t | Tensor(...) | Yes | Interpolation parameter in [0, 1] for slerp |
| m | Tensor(..., 3, 3) | Yes | 3x3 rotation matrix for matrix-to-quaternion conversion |
| e | Tensor(..., 3) | Yes | Euler angles (roll, pitch, yaw) for Euler-to-quaternion conversion |
Outputs
| Name | Type | Description |
|---|---|---|
| quaternion | Tensor(..., 4) | Resulting quaternion in (x, y, z, w) format |
| vector | Tensor(..., 3) | Rotated 3D vector |
| matrix | Tensor(..., 3, 3) | 3x3 rotation matrix |
| scalar | Tensor(...) | Quaternion norm or angle value |
Usage Examples
import torch
from isaacgymenvs.tasks.amp.poselib.poselib.core.rotation3d import (
quat_mul, quat_rotate, quat_slerp, quat_from_angle_axis, quat_unit
)
# Create a batch of quaternions from angle-axis
angles = torch.tensor([0.5, 1.0, 1.5]) # radians
axes = torch.tensor([[0.0, 0.0, 1.0],
[0.0, 1.0, 0.0],
[1.0, 0.0, 0.0]])
quats = quat_from_angle_axis(angles, axes)
# Compose two rotations
q_combined = quat_mul(quats, quats)
# Rotate a batch of vectors
vectors = torch.randn(3, 3)
rotated = quat_rotate(quats, vectors)
# Interpolate between two quaternion poses
q0 = quat_unit(torch.randn(10, 4))
q1 = quat_unit(torch.randn(10, 4))
t = torch.tensor([0.5]).expand(10)
q_interp = quat_slerp(q0, q1, t)