Quaternion Class¶
The Quaternion class provides a compact, singularity-free representation of 3D rotations for spacecraft attitude determination and control.
Quaternion
¶
Represents a quaternion for 3D rotations.
Quaternions provide a compact, singularity-free representation of rotations. The quaternion is stored as [w, x, y, z] where w is the scalar part and [x, y, z] is the vector part.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Scalar component |
required |
x
|
float
|
X component of vector part |
required |
y
|
float
|
Y component of vector part |
required |
z
|
float
|
Z component of vector part |
required |
Example
import brahe as bh
import numpy as np
# Create identity quaternion
q = bh.Quaternion(1.0, 0.0, 0.0, 0.0)
print(f"Norm: {q.norm()}")
# Create from array
q_vec = np.array([1.0, 0.0, 0.0, 0.0])
q2 = bh.Quaternion.from_vector(q_vec, scalar_first=True)
# Convert to rotation matrix
dcm = q.to_rotation_matrix()
# Quaternion multiplication
q3 = q * q2
# Normalize
q3.normalize()
Initialize instance.
__doc__
class-attribute
¶
__doc__ = 'Represents a quaternion for 3D rotations.\n\nQuaternions provide a compact, singularity-free representation of rotations.\nThe quaternion is stored as [w, x, y, z] where w is the scalar part and\n[x, y, z] is the vector part.\n\nArgs:\n w (float): Scalar component\n x (float): X component of vector part\n y (float): Y component of vector part\n z (float): Z component of vector part\n\nExample:\n ```python\n import brahe as bh\n import numpy as np\n\n # Create identity quaternion\n q = bh.Quaternion(1.0, 0.0, 0.0, 0.0)\n print(f"Norm: {q.norm()}")\n\n # Create from array\n q_vec = np.array([1.0, 0.0, 0.0, 0.0])\n q2 = bh.Quaternion.from_vector(q_vec, scalar_first=True)\n\n # Convert to rotation matrix\n dcm = q.to_rotation_matrix()\n\n # Quaternion multiplication\n q3 = q * q2\n\n # Normalize\n q3.normalize()\n ```'
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__module__
class-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
data
property
¶
data: ndarray
Get the quaternion components as a numpy array [w, x, y, z].
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: 4-element array containing quaternion components |
__new__
builtin
¶
Create and return a new object. See help(type) for accurate signature.
conjugate
method descriptor
¶
conjugate() -> Quaternion
Compute the conjugate of the quaternion.
Returns:
| Name | Type | Description |
|---|---|---|
Quaternion |
Quaternion
|
Conjugate quaternion with negated vector part |
from_euler_angle
builtin
¶
from_euler_angle(e: EulerAngle) -> Quaternion
Create a quaternion from an Euler angle representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
e
|
EulerAngle
|
Euler angle representation |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Quaternion |
Quaternion
|
Equivalent quaternion |
from_euler_axis
builtin
¶
from_euler_axis(e: EulerAxis) -> Quaternion
Create a quaternion from an Euler axis representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
e
|
EulerAxis
|
Euler axis representation |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Quaternion |
Quaternion
|
Equivalent quaternion |
from_quaternion
builtin
¶
from_quaternion(q: Quaternion) -> Quaternion
Create a quaternion from another quaternion (copy constructor).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
Quaternion
|
Source quaternion |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Quaternion |
Quaternion
|
New quaternion instance |
from_rotation_matrix
builtin
¶
from_rotation_matrix(r: RotationMatrix) -> Quaternion
Create a quaternion from a rotation matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
RotationMatrix
|
Rotation matrix |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Quaternion |
Quaternion
|
Equivalent quaternion |
from_vector
builtin
¶
from_vector(v: ndarray, scalar_first: bool) -> Quaternion
Create a quaternion from a numpy array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
ndarray
|
4-element array containing quaternion components |
required |
scalar_first
|
bool
|
If True, array is [w, x, y, z], else [x, y, z, w] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Quaternion |
Quaternion
|
New quaternion instance |
inverse
method descriptor
¶
inverse() -> Quaternion
Compute the inverse of the quaternion.
Returns:
| Name | Type | Description |
|---|---|---|
Quaternion |
Quaternion
|
Inverse quaternion |
norm
method descriptor
¶
norm() -> float
Calculate the norm (magnitude) of the quaternion.
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Euclidean norm of the quaternion |
slerp
method descriptor
¶
slerp(other: Quaternion, t: float) -> Quaternion
Perform spherical linear interpolation (SLERP) between two quaternions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Quaternion
|
Target quaternion |
required |
t
|
float
|
Interpolation parameter in [0, 1] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Quaternion |
Quaternion
|
Interpolated quaternion |
to_euler_angle
method descriptor
¶
to_euler_angle(order: str) -> EulerAngle
Convert to Euler angle representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order
|
str
|
Rotation sequence (e.g., "XYZ", "ZYX") |
required |
Returns:
| Name | Type | Description |
|---|---|---|
EulerAngle |
EulerAngle
|
Equivalent Euler angles |
to_euler_axis
method descriptor
¶
to_euler_axis() -> EulerAxis
Convert to Euler axis representation.
Returns:
| Name | Type | Description |
|---|---|---|
EulerAxis |
EulerAxis
|
Equivalent Euler axis |
to_quaternion
method descriptor
¶
to_quaternion() -> Quaternion
Convert to quaternion representation (returns self).
Returns:
| Name | Type | Description |
|---|---|---|
Quaternion |
Quaternion
|
This quaternion |
to_rotation_matrix
method descriptor
¶
to_rotation_matrix() -> RotationMatrix
Convert to rotation matrix representation.
Returns:
| Name | Type | Description |
|---|---|---|
RotationMatrix |
RotationMatrix
|
Equivalent rotation matrix |