Quaternion
Unit quaternions are rotations; the fields are stored exactly as given.
Full docstring
WHY not normalised at construction: a stored property must read back as authored. Every operation that needs a rotation (`rotate`, `to_matrix`, `multiply`, ...) normalises first; `normalized()` and `is_unit()` are there when you want the unit value yourself.
Fields
| Name | Type | Default |
|---|---|---|
x | float | 0.0 |
y | float | 0.0 |
z | float | 0.0 |
w | float | 1.0 |
Example
One instance from the package's own test catalog; the output is its real repr().
Quaternion(x=0.034270798550482096, y=0.10602051106179562, z=0.1435721750273919, w=0.9833474432563558)to_dict() as JSON
{
"_type": "geometry/Quaternion",
"x": 0.034270798550482096,
"y": 0.10602051106179562,
"z": 0.1435721750273919,
"w": 0.9833474432563558
}Long arrays are cut after 16 values and say so with “…”.
Functions
Constructors
Classmethods and staticmethods: ways to build one.
from_axis_angle(axis: Any, angle: float) -> Quaternionaxis need not be unit length, but must be non-zero. Radians.
from_euler(roll: float, pitch: float, yaw: float) -> QuaternionROS RPY: fixed axes X, then Y, then Z (R = Rz·Ry·Rx).
Methods
Return new values; messages are never mutated.
angle_to(other: Quaternion) -> floatRadians in [0, π] of the rotation that takes self to other.
multiply(other: Quaternion) -> QuaternionHamilton product of the unit rotations: apply other first, then self.
slerp(other: Quaternion, alpha: float) -> QuaternionAlong the shorter arc; 0 gives self, 1 gives other, outside [0, 1] extrapolates.
to_dict
from Msgto_dict() -> dict[str, Any]JSON-safe dict with a "_type" key; arrays keep their dtype and shape.