unilab.base.rotation¶
Rotation helpers owned by the base/reset boundary.
The np_* helpers implement the explicit reset/entity host boundary. Task
cold loaders own their data-format conversion locally rather than depending on
these base helpers. quat_apply_inverse is the Torch counterpart used by the
packed reset transaction’s device-side pose/velocity encoding.
Functions
Return flattened first two rotation-matrix columns for quaternions (..., 4). |
|
Convert quaternion(s) to rotation matrix (N, 3, 3) or (3, 3), w-first. |
|
|
Estimate angular velocity from a quaternion time sequence using shortest-arc diffs. |
|
Rotate vector(s) by quaternion(s), supports batched/scalar inputs. |
|
Rotate broadcast-compatible vector arrays by quaternions. |
|
Rotate vector(s) by inverse quaternion(s). |
Rotate broadcast-compatible vector arrays by inverse quaternions. |
|
Flip quaternion signs so the real part is non-negative. |
|
Conjugate of unit quaternions (..., 4), w-first. |
|
Flip quaternion signs in a time sequence to keep adjacent dots non-negative. |
|
|
Angular error magnitude between quaternions (N,) or scalar. |
|
Angular error magnitude for broadcast-compatible quaternions (..., 4). |
Squared angular error for broadcast-compatible quaternions (..., 4). |
|
|
Convert axis-angle pairs to unit quaternions (N, 4), w-first. |
|
Convert Euler angles (XYZ) to quaternions (N, 4) or (4,), w-first. |
|
Multiply quaternions in NumPy, supports (N, 4) and (4,) inputs. |
|
Multiply broadcast-compatible quaternion arrays with shape (..., 4). |
Convert unit quaternion batch (N, 4), w-first, to axis-angle vectors (N, 3). |
|
Compute body transforms relative to per-env anchors. |
|
|
Convert yaw batch (N,) to quaternion batch (N, 4) in NumPy. |
|
Rotate vectors by the inverse of broadcast-compatible wxyz quaternions. |
- unilab.base.rotation.np_quat_mul(q1, q2)[source]¶
Multiply quaternions in NumPy, supports (N, 4) and (4,) inputs.
- unilab.base.rotation.np_quat_mul_batched(q1, q2)[source]¶
Multiply broadcast-compatible quaternion arrays with shape (…, 4).
- unilab.base.rotation.np_quat_canonicalize(q)[source]¶
Flip quaternion signs so the real part is non-negative.
- unilab.base.rotation.np_quat_ensure_continuity(q)[source]¶
Flip quaternion signs in a time sequence to keep adjacent dots non-negative.
- unilab.base.rotation.np_quat_to_axis_angle(q)[source]¶
Convert unit quaternion batch (N, 4), w-first, to axis-angle vectors (N, 3).
Adapted from PyTorch3D. Uses atan2 + Taylor expansion for numerical stability near zero rotation.
- unilab.base.rotation.np_quat_from_angle_axis(angle, axis)[source]¶
Convert axis-angle pairs to unit quaternions (N, 4), w-first.
anglehas shape (N,) andaxishas shape (N, 3); axes are normalized internally. Inverse ofnp_quat_to_axis_angle().
- unilab.base.rotation.np_quat_angular_velocity(q, dt)[source]¶
Estimate angular velocity from a quaternion time sequence using shortest-arc diffs.
- unilab.base.rotation.np_yaw_to_quat(yaw)[source]¶
Convert yaw batch (N,) to quaternion batch (N, 4) in NumPy.
- unilab.base.rotation.np_quat_apply(q, v)[source]¶
Rotate vector(s) by quaternion(s), supports batched/scalar inputs.
- unilab.base.rotation.np_quat_apply_batched(q, v)[source]¶
Rotate broadcast-compatible vector arrays by quaternions.
qhas shape (…, 4),vhas shape (…, 3), and leading dimensions are broadcast. This avoids flattening/tile allocations in hot env paths.
- unilab.base.rotation.np_quat_apply_inverse(q, v)[source]¶
Rotate vector(s) by inverse quaternion(s).
- unilab.base.rotation.np_quat_apply_inverse_batched(q, v)[source]¶
Rotate broadcast-compatible vector arrays by inverse quaternions.
qhas shape (…, 4),vhas shape (…, 3), and leading dimensions are broadcast. Batched counterpart ofnp_quat_apply_inverse.
- unilab.base.rotation.np_quat_error_magnitude(q1, q2)[source]¶
Angular error magnitude between quaternions (N,) or scalar.
- unilab.base.rotation.np_quat_error_magnitude_batched(q1, q2)[source]¶
Angular error magnitude for broadcast-compatible quaternions (…, 4).
- unilab.base.rotation.np_quat_error_magnitude_squared_batched(q1, q2)[source]¶
Squared angular error for broadcast-compatible quaternions (…, 4).
- unilab.base.rotation.np_quat_from_euler_xyz(roll, pitch, yaw)[source]¶
Convert Euler angles (XYZ) to quaternions (N, 4) or (4,), w-first.
- unilab.base.rotation.np_matrix_from_quat(q)[source]¶
Convert quaternion(s) to rotation matrix (N, 3, 3) or (3, 3), w-first.
- unilab.base.rotation.np_matrix_first_two_cols_from_quat(q)[source]¶
Return flattened first two rotation-matrix columns for quaternions (…, 4).
The output order matches
np_matrix_from_quat(q)[:, :, :2].reshape(..., 6).