Each solution constructs a rotation matrix and derives its representations. Checks cover rounding and Euler branch error.
Worked solutions
These examples use Passive (C), degrees, ZYX (321), and scalar-last quaternions. Results are rounded to six decimal places. See Conventions for symbols and signs.
Example 1. A passive quarter-turn about Z
Find the matrix, quaternion, and axis-angle forms of a passive rotation with ZYX angles [90∘,0∘,0∘]. The matrix maps coordinates by vB=CvA; quaternion order is q=[x,y,z,w].
Given: the sequence and angle values
Select Passive (C), degrees, and ZYX (321). The angle vector is [α,β,γ]=[90∘,0∘,0∘] in [Z,Y,X] order.
The zero-angle factors are identity matrices. Substitute cos(90∘)=0 and sin(90∘)=1 into CZ. In the passive convention, the positive off-diagonal entry occupies row 1, column 2.
A vector along the first axis of frame A has coordinates [0,−1,0]T in frame B. Both coordinate sets describe the same physical vector. The paired active matrix is CT.
CZ(α)C=cosα−sinα0sinαcosα0001=0−10100001Quarter-turn matrixvA=100,vB=CvA=0−10Coordinate transformation of a basis vector
Obtain the quaternion and axis-angle pair
For u=[0,0,1]T and θ=90∘, the quaternion has vector part usin(θ/2) and scalar part cos(θ/2). Its z and w components are positive. Both q and −q yield the same matrix.
Axis-angle order is [ux,uy,uz,θ], with θ in the selected unit. In degrees, the result is [0,0,1,90].
q=[uxsin2θ,uysin2θ,uzsin2θ,cos2θ]=[0,0,21,21]Scalar-last unit quaternion∥q∥2det(C)=02+02+(21)2+(21)2=1=1,CCT=IIndependent normalization and matrix checks
Verification. The exact matrix has det(C)=1, CCT=I, and zero orthogonality residual. Allow for numerical roundoff. Check quaternion normalization with full-precision components.
Find the passive orientation for ZYX angles [10∘,20∘,30∘]. Use vB=CvA and scalar-last quaternion order q=[x,y,z,w].
Given: three angles in sequence order
For ZYX (321), assign α=10∘ to Z, β=20∘ to Y, and γ=30∘ to X. Set both unit selectors to degrees. The factors act on a column vector from right to left: Z, then Y, then X.
In Sequence mode, enter Step 1: Z=10∘, Step 2: Y=20∘, and Step 3: X=30∘. Set the other angles in each step to zero. Reversing the steps generally changes the orientation.
CvB=CX(30∘)CY(20∘)CZ(10∘)=CX(30∘)[CY(20∘)(CZ(10∘)vA)]Order of composition and application
Multiply the elementary matrices
Write cα=cosα and sα=sinα, likewise for β and γ. Expand CX(γ)CY(β)CZ(α) to obtain the matrix below.
Substitute the given angles. Check the signs and assignments using c13=−sin(20∘)=−0.3420201433 and c23=sin(30∘)cos(20∘)=0.4698463104.
Compare the four squared quaternion components derived from the diagonal of C. Here w2 is largest. Calculate w from tr(C)=c11+c22+c33, then obtain the vector components from the antisymmetric entries.
Normalize the quaternion and set s=x2+y2+z2. Compute u=[x,y,z]T/s and θ=2atan2(s,w), then convert θ to degrees.
wxq=211+tr(C)=4wc23−c32,y=4wc31−c13,z=4wc12−c21≈[0.239298,0.189308,0.038135,0.951549]Quaternion extraction through the largest componentu≈[0.778209,0.615638,0.124015]T,θ≈35.817101∘Equivalent single-axis rotation
Recover the Euler angles and verify the result
Since ∣−c13∣<1−10−6, use the nonsingular ZYX formulas. Convert their atan2 results from radians to degrees. The output order is [Z,Y,X].
The matrix has determinant 1 and CCT=I up to roundoff. Recovering the original angles verifies the sequence and multiplication order.
αβγ=atan2(c12,c11)=10∘=atan2(−c13,c112+c122)=20∘=atan2(c23,c33)=30∘Nonsingular ZYX angle extraction, expressed in degrees
Examine a passive Y rotation of 89.95∘ using ZYX, vB=CvA, and q=[x,y,z,w]. The matrix and quaternion retain the input angle. The Euler tolerance selects a singular branch.
Given: a middle angle close to 90∘
Select Passive (C), degrees, and ZYX (321). Set α=0∘ about Z, β=89.95∘ about Y, and γ=0∘ about X. The zero outer angles reduce the product to CY(β).
CCY(β)=CX(0∘)CY(89.95∘)CZ(0∘)=CY(89.95∘)=cosβ0sinβ010−sinβ0cosβMatrix construction near the Euler singularity
Obtain the quaternion and axis-angle forms
The axis u=[0,1,0]T gives a quaternion with only y and w components. Compute them from β/2=44.975∘. These half-angle expressions remain well conditioned as β approaches 90∘.
Quaternion-derived axis-angle output gives the Y axis and 89.95∘, independently of Euler branch selection.
qu=[0,sin(44.975∘),0,cos(44.975∘)]≈[0.000000,0.706798,0.000000,0.707415]=[0,1,0]T,θ=89.95∘Quaternion and axis-angle forms of the specified rotation
Apply the Euler solver’s branch criterion
For ZYX, set sβ=−c13. Nonsingular extraction requires ∣sβ∣<1−10−6. At 89.95∘, the threshold selects the singular branch: the first angle becomes zero and the middle angle becomes +90∘.
The remaining angle is γ=atan2(−c32,c22). With c32=0 and c22=1, γ=0∘. The converter displays [0∘,90∘,0∘] and a near-singularity warning.
∣sβ∣1−10−6∣sβ∣α=sin(89.95∘)≈0.999999619228=0.999999≥1−10−6=0∘,β=90∘,γ=0∘Evaluation of the singular-branch threshold
Measure the effect of the selected branch
The displayed Euler triple reconstructs C^=CY(90∘). The original is C=CY(89.95∘). Their largest entrywise difference lies on the diagonal and equals cos(89.95∘) up to roundoff.
Both matrices describe valid rotations separated by a small angle. At exact gimbal lock, the first and third angles are coupled. Retain the matrix or quaternion to preserve the input orientation near the Euler branch threshold.
Verification. Euler output is [0∘,90∘,0∘]; axis-angle output is [0,1,0,89.95∘]. Euler reconstruction gives a maximum entrywise error of approximately 8.72665×10−4. Preserve the original matrix or quaternion when this error matters.
Quaternions q and −q give the same matrix. Euler triples may differ by full turns or equivalent branches. At gimbal lock, the first and third angles are coupled. Test equivalence by comparing reconstructed matrices under the same convention.
Reconstruction from displayed values includes rounding and any Euler branch error. Loading an example applies its stated settings and full matrix precision. See Numerical checks for the implemented tolerances.