Conversions¶
Pure conversion functions between attitude representations.
All functions operate on raw JAX arrays (no class instances) to avoid
circular imports between class modules. The classes in quaternion.py,
rotation_matrix.py, euler_angle.py, and euler_axis.py call
these kernels and wrap the results.
Convention
Quaternion layout is scalar-first: [w, x, y, z] (shape (4,)).
Rotation matrix layout is row-major: shape (3, 3).
Euler axis is (axis(3,), angle_scalar).
euler_angle_to_quaternion(order_idx, phi, theta, psi)
¶
Convert Euler angles to a quaternion via jax.lax.switch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order_idx
|
Array
|
Integer index 0--11 matching |
required |
phi
|
Array
|
First rotation angle in radians. |
required |
theta
|
Array
|
Second rotation angle in radians. |
required |
psi
|
Array
|
Third rotation angle in radians. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
jnp.ndarray: Quaternion of shape |
euler_axis_to_quaternion(axis, angle)
¶
Convert an Euler axis-angle representation to a quaternion.
The axis is used as-is with half-angle trig, then the result is
normalized. This matches the brahe Rust convention where
Quaternion::new normalizes after construction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis
|
Array
|
Rotation axis vector of shape |
required |
angle
|
Array
|
Rotation angle in radians (scalar). |
required |
Returns:
| Type | Description |
|---|---|
Array
|
jnp.ndarray: Unit quaternion of shape |
quaternion_multiply(q1, q2)
¶
Hamilton product of two quaternions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q1
|
Array
|
First quaternion of shape |
required |
q2
|
Array
|
Second quaternion of shape |
required |
Returns:
| Type | Description |
|---|---|
Array
|
jnp.ndarray: Product quaternion of shape |
quaternion_slerp(q1, q2, t)
¶
Spherical linear interpolation between two quaternions.
Falls back to linear interpolation when the quaternions are nearly parallel (dot product > 0.9995).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q1
|
Array
|
Start quaternion of shape |
required |
q2
|
Array
|
End quaternion of shape |
required |
t
|
float | Array
|
Interpolation parameter in |
required |
Returns:
| Type | Description |
|---|---|
Array
|
jnp.ndarray: Interpolated quaternion of shape |
quaternion_to_euler_axis(q)
¶
Convert a unit quaternion to Euler axis-angle representation.
When the rotation angle is zero the axis is undefined; the default
axis [1, 0, 0] is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
Array
|
Quaternion of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
Array
|
|
Array
|
|
quaternion_to_rotation_matrix(q)
¶
Convert a unit quaternion to a 3x3 rotation matrix.
Uses the bilinear product form (Diebel eq. 125).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
Array
|
Quaternion array of shape |
required |
Returns:
| Type | Description |
|---|---|
Array
|
jnp.ndarray: Rotation matrix of shape |
rotation_matrix_to_euler_angle(order_idx, R)
¶
Extract Euler angles from a rotation matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order_idx
|
Array
|
Integer index 0--11 matching |
required |
R
|
Array
|
Rotation matrix of shape |
required |
Returns:
| Type | Description |
|---|---|
Array
|
jnp.ndarray: Array |
rotation_matrix_to_quaternion(R)
¶
Convert a 3x3 rotation matrix to a unit quaternion.
Uses Shepperd's method with jax.lax.switch on argmax for
numerical stability and JIT compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
R
|
Array
|
Rotation matrix of shape |
required |
Returns:
| Type | Description |
|---|---|
Array
|
jnp.ndarray: Quaternion array of shape |