NovaSolver›Spacecraft Attitude Quaternion Rotation Simulator Back
Space Engineering
Spacecraft Attitude Quaternion Rotation Simulator
Compose a spacecraft's 3D attitude from Euler angles (roll / pitch / yaw) and a rotation about an arbitrary axis, then read the resulting quaternion q=(w,x,y,z), its norm, and the equivalent Euler angles in real time. Learn the Hamilton-convention quaternions widely used in attitude determination and control systems (ADCS) without falling into the gimbal-lock singularity.
Parameters
Roll φ
°
Rotation about the body X axis (fore-aft)
Pitch θ
°
Rotation about the body Y axis (lateral). Gimbal lock at ±90°.
Yaw ψ
°
Rotation about the body Z axis (vertical)
Rotation axis n_x
Rotation axis n_y
Rotation axis n_z
Axis vector is automatically normalised to unit length
Rotation angle α
°
Magnitude of the axis-angle rotation
Results
—
Quaternion w
—
Quaternion x
—
Quaternion y
—
Quaternion z
—
Norm |q|
—
Combined Euler (φ,θ,ψ) °
—
3D spacecraft model — attitude and rotation axis
The spacecraft follows the composed attitude q_total. Thick arrows are the body axes (X = red, Y = green, Z = blue), thin arrows the inertial axes X₀Y₀Z₀, and dashed arrows the body axes before the axis-angle rotation (q_euler). The yellow arrow is the rotation axis n drawn in the body frame after the Euler rotation, as the composition q_total = q_euler·q_axis requires; the yellow arc and the dotted trace show the sense of the rotation by α about n and the path swept by the nose (tip of the X axis). Drag the figure to orbit the view; double-click (double-tap) restores the initial view.
Unit-quaternion condition and the inverse via the conjugate q*. In flight code, renormalise q ← q/|q| every step.
Spacecraft attitude representation with quaternions
🙋
A spacecraft's attitude is just roll, pitch and yaw, right? Why bother with a four-component quaternion when three numbers already cover the three degrees of freedom?
🎓
Good question. The degrees of freedom really are three, so three Euler angles could describe the attitude. But in practice there is a fatal problem called "gimbal lock". When the pitch hits exactly ±90°, the roll and yaw axes line up and the roll-vs-yaw distinction collapses. The Apollo inertial platform used three gimbals, so the crew had to keep the spacecraft away from the gimbal-lock attitude during flight. By carrying one extra dimension, a quaternion physically removes this singularity.
🙋
So avoiding the singularity is the main point. But quaternions look intimidating — i² = −1 and so on. Intuitively, what do they represent?
🎓
Loosely speaking, q = (cos(α/2), sin(α/2)·n) packs the operation "rotate by angle α about axis n" into a single number. The half angle α/2 is surprising at first, but it appears because the quaternion acts on a vector v as v' = q·v·q*, sandwiching it from both sides. Without halving, the rotation would be applied twice. That is also why q and −q describe the same physical rotation — the "double cover". Set roll, pitch and yaw to 0 in the left panel, with axis = (0,0,1) and α = 90°, and the displayed q = (cos 45°, 0, 0, sin 45°) = (0.7071, 0, 0, 0.7071) with a combined yaw of 90° (the tool shows q_total, so you need zero Euler angles to see q_axis alone).
🙋
You combine two rotations with "multiplication". Is that different from ordinary multiplication?
🎓
Yes — quaternion multiplication is the non-commutative algebra Hamilton discovered in 1843: q1·q2 ≠ q2·q1, exactly mirroring the fact that swapping the order of two rotations gives a different result. This tool composes the attitude quaternion built from Euler angles (q_euler) with the axis-angle quaternion (q_axis) as q_total = q_euler · q_axis. A typical use is taking an absolute attitude from a star tracker and applying a small delta from a reaction-wheel manoeuvre. The state transition in attitude-EKF / UKF and Quaternion-SLAM is written with this same product.
🙋
You said the top-right "Norm |q|" stat should stay at 1. What goes wrong if it drifts away?
🎓
Only a unit quaternion |q|=1 represents a pure rotation. If the norm becomes 1.05, you get a rotation plus a 5% scaling — an unwanted similarity transform. Flight attitude systems typically renormalise q ← q/|q| every control cycle, or use a multiplicative EKF (MEKF) whose error quaternion is centred at unity by construction. When integrating angular velocity into attitude, round-off and truncation errors make the norm drift slowly away from 1 whatever integrator is used, so long-duration operation needs the correction.
🙋
It's handy that the "Combined Euler" updates in real time. But in the α-sweep chart below, the pitch jumps suddenly at certain α values. Is that gimbal lock too?
🎓
Sharp eye — that is a property of converting a quaternion back to Euler angles. Near pitch = ±90°, the atan2 denominator approaches zero and roll and yaw become interchangeable. On the quaternion side nothing singular happens; the four components vary smoothly. That is exactly why attitude integrators are kept in quaternion space and Euler angles are only produced when a human reads a display.
Frequently Asked Questions
A quaternion represents a 3D rotation uniquely with four components (w,x,y,z) and completely avoids the gimbal-lock singularity of Euler angles, where roll and yaw collapse at pitch = ±90°. Composition of two rotations becomes a single multiplication, and interpolation (SLERP) is smooth at constant angular speed. For these reasons quaternions are widely used wherever attitude is handled continuously in time: spacecraft ADCS, star trackers, MEMS-IMU fusion and robot-arm trajectory planning.
Using the Tait-Bryan ZYX order (yaw → pitch → roll) and the shorthand cy=cos(ψ/2), sy=sin(ψ/2), cp=cos(θ/2), sp=sin(θ/2), cr=cos(φ/2), sr=sin(φ/2), the unit quaternion is q_w=cr·cp·cy+sr·sp·sy, q_x=sr·cp·cy−cr·sp·sy, q_y=cr·sp·cy+sr·cp·sy, q_z=cr·cp·sy−sr·sp·cy with φ=roll, θ=pitch, ψ=yaw. Two sign conventions exist, Hamilton (i²=j²=k²=ijk=−1) and JPL; this tool follows the Hamilton convention.
Only a unit quaternion with |q|=1 represents a pure rotation. If numerical integration or sensor fusion (extended Kalman filter) lets the norm drift away from 1, converting back to a rotation matrix introduces a scaling component and the rotated vectors change length. This tool warns when |q|−1| > 0.01. Real ADCS firmware either renormalizes q ← q/|q| every control step, or uses an error-quaternion formulation (multiplicative EKF, MEKF) so error growth is bounded by construction.
A rotation by angle α about the unit axis n=(n_x,n_y,n_z) is q=(cos(α/2), sin(α/2)·n_x, sin(α/2)·n_y, sin(α/2)·n_z). This form is physically intuitive and maps directly to Rodrigues' rotation formula. The half-angle α/2 appears because when q rotates a vector v via v' = q·v·q*, the quaternion acts on both sides; without halving, the rotation would be applied twice. This is also why q and −q describe the same physical rotation — the famous 'double cover' of SO(3) by the unit quaternions.
Real-World Applications
Spacecraft and satellite ADCS: Satellite and probe ADCS commonly represent attitude as a quaternion internally. Star trackers deliver an absolute attitude q_ref; the gyros are integrated via q̇ = ½·q·ω; an error quaternion δq drives commands to the reaction wheels and thrusters. Euler angles only show up at the human-readable telemetry layer.
Drone and UAV attitude control: Many drone flight controllers fuse MEMS IMU data (accelerometer + gyro + magnetometer) with a complementary filter or MEKF that stores attitude as a quaternion. During acrobatic flight, the moment the body transitions from vertical climb to inverted flight, an Euler-angle controller would break down at pitch ±90°; a quaternion controller tracks the attitude continuously without any special-case handling.
3D graphics, game engines and VR/AR: Most real-time 3D applications keep their internal Transform rotations as quaternions. Character animation keyframes are interpolated with SLERP (spherical linear interpolation) for a constant-angular-speed feel. VR headsets likewise handle head pose from the 6-DoF tracker as a quaternion and convert it to a view matrix only at the very last stage of the renderer.
Robotics and motion capture: Industrial-arm trajectory planning, humanoid balance control and motion-capture rigid-body output use quaternions when interpolating or differentiating joint or body orientations. Even the Jacobian for inverse kinematics is built from quaternion tangent spaces (angular-velocity vectors), keeping the rotational degrees of freedom singularity-free.
Common Misconceptions and Pitfalls
The biggest source of confusion is the quaternion sign convention. The Hamilton convention (ij = k) and the JPL convention (ij = −k) flip the sign of quaternion multiplication. The graphics field mostly uses Hamilton; the JPL convention, as its name says, appears in JPL-lineage literature. Mixing libraries of different convention silently rotates the attitude in the opposite direction. This tool is Hamilton. Storage order is a second trap: (w,x,y,z) vs (x,y,z,w) differ between libraries; this tool and most textbooks are (w,x,y,z). Always double-check both when porting code.
Next, assuming "the quaternion has no singularity" implies "the inverse mapping has no singularity". A unit quaternion lives smoothly on the four-dimensional sphere S³, with no singular points. The conversion back to Euler angles via (asin, atan2), however, develops an indeterminate atan2(0,0) at pitch = ±90°, and roll and yaw become exchangeable. That is exactly why the pitchOut computation in this tool clamps |sin p| at 1 and, at exactly ±90°, reports roll = 0 with the whole heading placed in yaw. The design principle "integrate and control in quaternion space; convert to Euler only for human displays" follows directly from this.
Finally, expecting "the quaternion will stay unit-norm by itself". When angular velocity is integrated numerically, round-off and truncation errors make the norm drift slowly away from 1 whatever the integrator, and without correction the attitude estimate becomes biased. Flight firmware either runs q ← q/|q| every step or uses a multiplicative EKF (MEKF) that keeps the error quaternion infinitesimal by construction. This tool computes from Euler and axis-angle in closed form, so the norm shown here is always 1.000000 to the six digits displayed; in any long-duration integrator you must normalise.
How to Use
Enter the Euler angles in degrees with the sliders or number fields: roll φ (−180…180), pitch θ (−90…90), yaw ψ (−180…180).
Set the rotation axis components n_x, n_y, n_z (normalised automatically) and the angle α (0…360°). Set α = 0 if you only want the Euler-angle quaternion.
Every change recomputes q_total = q_euler · q_axis automatically (there is no run button): read w, x, y, z, the norm |q| and the combined Euler angles (φ,θ,ψ) in degrees from the Results card; the α-sweep chart shows how the combined Euler angles change with α.
Worked Example
Enter roll 45°, pitch 30°, yaw 60° and set α = 0° so that the axis-angle part is the identity. The tool shows q = (0.8224, 0.2006, 0.3919, 0.3604) with norm 1.000000, and the combined Euler angles come back as φ=45.0°, θ=30.0°, ψ=60.0°. You can check w by hand: cos(22.5°)·cos(15°)·cos(30°) + sin(22.5°)·sin(15°)·sin(30°) = 0.7728 + 0.0495 = 0.8224. A second check: roll 30°, pitch 0°, yaw 0°, axis (1,0,0), α = 30° gives q = (0.8660, 0.5000, 0, 0) and a combined roll of 60.0°, i.e. two rotations about the same axis add their angles.
Practical Notes
Gimbal lock avoidance: when pitch approaches ±90°, Euler angles become singular (roll and yaw couple); quaternions handle this seamlessly since w² + x² + y² + z² = 1 eliminates geometric degeneracy.
Spacecraft maneuver planning: use quaternion SLERP (spherical linear interpolation) for smooth attitude transitions between target orientations instead of linear Euler angle blending.
Pitch input is limited to ±90°; at exactly ±90° the combined roll and yaw are not unique, so the tool clamps |sin p| to 1 and shows roll = 0 with the whole heading in yaw; the roll and yaw traces in the α-sweep chart jump across that point.
🎬 Watch it in motion
Euler's Disk | Spin That Races Before It Stops #Shorts
The Coriolis Force | Why Straight Looks Curved #Shorts