Quaternion
四元数EssentialA four-number representation of 3D rotation, the most common orientation format in robotics software.
Quaternions were introduced by William Rowan Hamilton in 1843, in the form w + xi + yj + zk. A unit quaternion — one with length 1 — can represent a 3D rotation: rotating by angle θ about a unit axis u corresponds to q = (cos(θ/2), u·sin(θ/2)), where the first term is the real part w and the remaining three are the imaginary parts x, y, z. Unlike Euler angles, quaternions have no gimbal lock (the loss of a rotational degree of freedom at certain angles), and compared with a 9-number rotation matrix they're more compact and interpolate smoothly — both ROS and MuJoCo store orientation this way. One catch: q and −q represent the exact same rotation. Component ordering also varies between tools — MuJoCo uses wxyz, ROS messages use xyzw — and mixing the two up is a common bug.
ExampleA 90° rotation about the z-axis: θ/2 = 45°, which in wxyz order is (0.707, 0, 0, 0.707); filled into a ROS Quaternion message, that becomes x=0, y=0, z=0.707, w=0.707.
- Also called
- Unit Quaternion
- Related
- Rotation Matrix · Euler Angles · Gimbal Lock · Quaternion Double Cover · Spherical Linear Interpolation (SLERP) · Quaternion Component Order (wxyz vs. xyzw)
- Sources
- Wikipedia: Quaternions and spatial rotation
Wikipedia: Quaternion(History)
ROS 2 common_interfaces: geometry_msgs/msg/Quaternion.msg
MuJoCo Documentation: Modeling(Frame orientations:quat 默认 1 0 0 0,实部在前) (Chinese)