unilab.envs.common.rotation¶
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). |
Flip quaternion signs so the real part is non-negative. |
|
Conjugate of unit quaternions (N, 4) or (4,), w-first. |
|
Conjugate quaternions with shape (..., 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 Euler angles (XYZ) to quaternions (N, 4) or (4,), w-first. |
|
Inverse of unit 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. |
|
|
Compute relative transform from frame 1 to frame 2 in frame-1 coordinates. |
|
Wrap angle(s) into (-pi, pi]. |
|
Yaw angle (N,) from quaternion batch (N, 4), w-first. |
|
Extract yaw-only quaternion from full quaternion(s), w-first. |
|
Convert yaw batch (N,) to quaternion batch (N, 4) in NumPy. |
- unilab.envs.common.rotation.np_quat_mul(q1, q2)[source]¶
Multiply quaternions in NumPy, supports (N, 4) and (4,) inputs.
- unilab.envs.common.rotation.np_quat_conjugate_batched(q)[source]¶
Conjugate quaternions with shape (…, 4), w-first.
- unilab.envs.common.rotation.np_quat_mul_batched(q1, q2)[source]¶
Multiply broadcast-compatible quaternion arrays with shape (…, 4).
- unilab.envs.common.rotation.np_quat_conjugate(q)[source]¶
Conjugate of unit quaternions (N, 4) or (4,), w-first.
- unilab.envs.common.rotation.np_quat_canonicalize(q)[source]¶
Flip quaternion signs so the real part is non-negative.
- unilab.envs.common.rotation.np_quat_ensure_continuity(q)[source]¶
Flip quaternion signs in a time sequence to keep adjacent dots non-negative.
- unilab.envs.common.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.envs.common.rotation.np_quat_angular_velocity(q, dt)[source]¶
Estimate angular velocity from a quaternion time sequence using shortest-arc diffs.
- unilab.envs.common.rotation.np_yaw_to_quat(yaw)[source]¶
Convert yaw batch (N,) to quaternion batch (N, 4) in NumPy.
- unilab.envs.common.rotation.np_yaw_from_quat(quat)[source]¶
Yaw angle (N,) from quaternion batch (N, 4), w-first.
- unilab.envs.common.rotation.np_quat_inv(q)[source]¶
Inverse of unit quaternions (N, 4) or (4,), w-first.
- unilab.envs.common.rotation.np_quat_apply(q, v)[source]¶
Rotate vector(s) by quaternion(s), supports batched/scalar inputs.
- unilab.envs.common.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.envs.common.rotation.np_quat_apply_inverse(q, v)[source]¶
Rotate vector(s) by inverse quaternion(s).
- unilab.envs.common.rotation.np_quat_error_magnitude(q1, q2)[source]¶
Angular error magnitude between quaternions (N,) or scalar.
- unilab.envs.common.rotation.np_quat_error_magnitude_batched(q1, q2)[source]¶
Angular error magnitude for broadcast-compatible quaternions (…, 4).
- unilab.envs.common.rotation.np_quat_error_magnitude_squared_batched(q1, q2)[source]¶
Squared angular error for broadcast-compatible quaternions (…, 4).
- unilab.envs.common.rotation.np_quat_from_euler_xyz(roll, pitch, yaw)[source]¶
Convert Euler angles (XYZ) to quaternions (N, 4) or (4,), w-first.
- unilab.envs.common.rotation.np_yaw_quat(q)[source]¶
Extract yaw-only quaternion from full quaternion(s), w-first.
- unilab.envs.common.rotation.np_matrix_from_quat(q)[source]¶
Convert quaternion(s) to rotation matrix (N, 3, 3) or (3, 3), w-first.
- unilab.envs.common.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).
- unilab.envs.common.rotation.np_subtract_frame_transforms(pos1, quat1, pos2, quat2)[source]¶
Compute relative transform from frame 1 to frame 2 in frame-1 coordinates.