Skip to content
Rotation Converter3D ORIENTATION / TECHNICAL REFERENCE

Worked rotation examples

Each solution constructs a rotation matrix and derives its representations. Checks cover rounding and Euler branch error.

Worked solutions

These examples use Passive (CC), degrees, ZYX\mathrm{ZYX} (321321), and scalar-last quaternions. Results are rounded to six decimal places. See Conventions for symbols and signs.

Example 1. A passive quarter-turn about ZZ

Find the matrix, quaternion, and axis-angle forms of a passive rotation with ZYX\mathrm{ZYX} angles [90∘,0∘,0∘][90^\circ, 0^\circ, 0^\circ]. The matrix maps coordinates by vB=CvAv_B = C v_A; quaternion order is q=[x,y,z,w]q = [x, y, z, w].

Given: the sequence and angle values

Select Passive (CC), degrees, and ZYX\mathrm{ZYX} (321321). The angle vector is [α,β,γ]=[90∘,0∘,0∘][\alpha,\beta,\gamma]=[90^\circ,0^\circ,0^\circ] in [Z,Y,X][Z,Y,X] order.

C=CX(γ)CY(β)CZ(α)=CX(0∘)CY(0∘)CZ(90∘)\begin{aligned}C&=C_X(\gamma)C_Y(\beta)C_Z(\alpha)\\&=C_X(0^\circ)C_Y(0^\circ)C_Z(90^\circ)\end{aligned}
Specified passive matrix product

Construct the direction cosine matrix

The zero-angle factors are identity matrices. Substitute cos⁡(90∘)=0\cos(90^\circ)=0 and sin⁡(90∘)=1\sin(90^\circ)=1 into CZC_Z. In the passive convention, the positive off-diagonal entry occupies row 1, column 2.

A vector along the first axis of frame AA has coordinates [0,−1,0]T[0,-1,0]^{\mathsf T} in frame BB. Both coordinate sets describe the same physical vector. The paired active matrix is CTC^{\mathsf T}.

CZ(α)=[cos⁡αsin⁡α0−sin⁡αcos⁡α0001]C=[010−100001]\begin{aligned}C_Z(\alpha)&=\begin{bmatrix}\cos\alpha&\sin\alpha&0\\-\sin\alpha&\cos\alpha&0\\0&0&1\end{bmatrix}\\C&=\begin{bmatrix}0&1&0\\-1&0&0\\0&0&1\end{bmatrix}\end{aligned}
Quarter-turn matrix
vA=[100],vB=CvA=[0−10]v_A=\begin{bmatrix}1\\0\\0\end{bmatrix},\qquad v_B=Cv_A=\begin{bmatrix}0\\-1\\0\end{bmatrix}
Coordinate transformation of a basis vector

Obtain the quaternion and axis-angle pair

For u=[0,0,1]Tu=[0,0,1]^{\mathsf T} and θ=90∘\theta=90^\circ, the quaternion has vector part usin⁡(θ/2)u\sin(\theta/2) and scalar part cos⁡(θ/2)\cos(\theta/2). Its zz and ww components are positive. Both qq and −q-q yield the same matrix.

Axis-angle order is [ux,uy,uz,θ][u_x,u_y,u_z,\theta], with θ\theta in the selected unit. In degrees, the result is [0,0,1,90][0,0,1,90].

q=[uxsin⁡θ2,  uysin⁡θ2,  uzsin⁡θ2,  cos⁡θ2]=[0,0,12,12]\begin{aligned}q&=\left[u_x\sin\frac\theta2,\;u_y\sin\frac\theta2,\;u_z\sin\frac\theta2,\;\cos\frac\theta2\right]\\&=\left[0,0,\frac{1}{\sqrt2},\frac{1}{\sqrt2}\right]\end{aligned}
Scalar-last unit quaternion
∥q∥2=02+02+(12)2+(12)2=1det⁡(C)=1,CCT=I\begin{aligned}\lVert q\rVert^2&=0^2+0^2+\left(\frac1{\sqrt2}\right)^2+\left(\frac1{\sqrt2}\right)^2=1\\\det(C)&=1,\qquad CC^{\mathsf T}=I\end{aligned}
Independent normalization and matrix checks

Input · Passive, ZYX, degrees

Z = 90°, Y = 0°, X = 0°

Expected passive matrix

C = [
0.000000 1.000000 0.000000;
-1.000000 0.000000 0.000000;
0.000000 0.000000 1.000000
]

Quaternion · x, y, z, w

q = [0.000000, 0.000000, 0.707107, 0.707107]

Euler · Z, Y, X · degrees

[90.000000°, 0.000000°, 0.000000°]

Axis-angle · u_x, u_y, u_z, θ · degrees

[0.000000, 0.000000, 1.000000, 90.000000°]

Verification. The exact matrix has det⁡(C)=1\det(C) = 1, CCT=ICC^{\mathsf T} = I, and zero orthogonality residual. Allow for numerical roundoff. Check quaternion normalization with full-precision components.

Load this example

Example 2. Composition of three passive rotations

Find the passive orientation for ZYX\mathrm{ZYX} angles [10∘,20∘,30∘][10^\circ,20^\circ,30^\circ]. Use vB=CvAv_B=Cv_A and scalar-last quaternion order q=[x,y,z,w]q=[x,y,z,w].

Given: three angles in sequence order

For ZYX\mathrm{ZYX} (321321), assign α=10∘\alpha=10^\circ to ZZ, β=20∘\beta=20^\circ to YY, and γ=30∘\gamma=30^\circ to XX. Set both unit selectors to degrees. The factors act on a column vector from right to left: ZZ, then YY, then XX.

In Sequence mode, enter Step 1: Z=10∘Z=10^\circ, Step 2: Y=20∘Y=20^\circ, and Step 3: X=30∘X=30^\circ. Set the other angles in each step to zero. Reversing the steps generally changes the orientation.

C=CX(30∘)CY(20∘)CZ(10∘)vB=CX(30∘)[CY(20∘)(CZ(10∘)vA)]\begin{aligned}C&=C_X(30^\circ)C_Y(20^\circ)C_Z(10^\circ)\\v_B&=C_X(30^\circ)\left[C_Y(20^\circ)\left(C_Z(10^\circ)v_A\right)\right]\end{aligned}
Order of composition and application

Multiply the elementary matrices

Write cα=cos⁡αc_\alpha=\cos\alpha and sα=sin⁡αs_\alpha=\sin\alpha, likewise for β\beta and γ\gamma. Expand CX(γ)CY(β)CZ(α)C_X(\gamma)C_Y(\beta)C_Z(\alpha) to obtain the matrix below.

Substitute the given angles. Check the signs and assignments using c13=−sin⁡(20∘)=−0.3420201433c_{13}=-\sin(20^\circ)=-0.3420201433 and c23=sin⁡(30∘)cos⁡(20∘)=0.4698463104c_{23}=\sin(30^\circ)\cos(20^\circ)=0.4698463104.

C=[cβcαcβsα−sβsγsβcα−cγsαsγsβsα+cγcαsγcβcγsβcα+sγsαcγsβsα−sγcαcγcβ]C=\begin{bmatrix}c_\beta c_\alpha&c_\beta s_\alpha&-s_\beta\\s_\gamma s_\beta c_\alpha-c_\gamma s_\alpha&s_\gamma s_\beta s_\alpha+c_\gamma c_\alpha&s_\gamma c_\beta\\c_\gamma s_\beta c_\alpha+s_\gamma s_\alpha&c_\gamma s_\beta s_\alpha-s_\gamma c_\alpha&c_\gamma c_\beta\end{bmatrix}
Expanded passive ZYX\mathrm{ZYX} matrix

Extract the quaternion and rotation axis

Compare the four squared quaternion components derived from the diagonal of CC. Here w2w^2 is largest. Calculate ww from tr⁡(C)=c11+c22+c33\operatorname{tr}(C)=c_{11}+c_{22}+c_{33}, then obtain the vector components from the antisymmetric entries.

Normalize the quaternion and set s=x2+y2+z2s=\sqrt{x^2+y^2+z^2}. Compute u=[x,y,z]T/su=[x,y,z]^{\mathsf T}/s and θ=2atan2⁡(s,w)\theta=2\operatorname{atan2}(s,w), then convert θ\theta to degrees.

w=121+tr⁡(C)x=c23−c324w,y=c31−c134w,z=c12−c214wq≈[0.239298,0.189308,0.038135,0.951549]\begin{aligned}w&=\tfrac12\sqrt{1+\operatorname{tr}(C)}\\x&=\frac{c_{23}-c_{32}}{4w},\quad y=\frac{c_{31}-c_{13}}{4w},\quad z=\frac{c_{12}-c_{21}}{4w}\\q&\approx[0.239298,0.189308,0.038135,0.951549]\end{aligned}
Quaternion extraction through the largest component
u≈[0.778209,0.615638,0.124015]T,θ≈35.817101∘u\approx[0.778209,0.615638,0.124015]^{\mathsf T},\qquad\theta\approx35.817101^\circ
Equivalent single-axis rotation

Recover the Euler angles and verify the result

Since ∣−c13∣<1−10−6|-c_{13}|<1-10^{-6}, use the nonsingular ZYX\mathrm{ZYX} formulas. Convert their atan2⁡\operatorname{atan2} results from radians to degrees. The output order is [Z,Y,X][Z,Y,X].

The matrix has determinant 1 and CCT=ICC^{\mathsf T}=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∘\begin{aligned}\alpha&=\operatorname{atan2}(c_{12},c_{11})=10^\circ\\\beta&=\operatorname{atan2}\left(-c_{13},\sqrt{c_{11}^2+c_{12}^2}\right)=20^\circ\\\gamma&=\operatorname{atan2}(c_{23},c_{33})=30^\circ\end{aligned}
Nonsingular ZYX\mathrm{ZYX} angle extraction, expressed in degrees

Input · Passive, ZYX, degrees

Z = 10°, Y = 20°, X = 30°

Expected passive matrix

C = [
0.925417 0.163176 -0.342020;
0.018028 0.882564 0.469846;
0.378522 -0.440970 0.813798
]

Quaternion · x, y, z, w

q = [0.239298, 0.189308, 0.038135, 0.951549]

Euler · Z, Y, X · degrees

[10.000000°, 20.000000°, 30.000000°]

Axis-angle · u_x, u_y, u_z, θ · degrees

[0.778209, 0.615638, 0.124015, 35.817101°]

Verification. Euler extraction returns [Z,Y,X]=[10∘,20∘,30∘][Z,Y,X]=[10^\circ,20^\circ,30^\circ]. Unrounded Euler and quaternion outputs reconstruct CC to floating-point precision. Rounded components introduce reconstruction error.

Load this example

Example 3. Euler extraction near a singularity

Examine a passive YY rotation of 89.95∘89.95^\circ using ZYX\mathrm{ZYX}, vB=CvAv_B=Cv_A, and q=[x,y,z,w]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∘90^\circ

Select Passive (CC), degrees, and ZYX\mathrm{ZYX} (321321). Set α=0∘\alpha=0^\circ about ZZ, β=89.95∘\beta=89.95^\circ about YY, and γ=0∘\gamma=0^\circ about XX. The zero outer angles reduce the product to CY(β)C_Y(\beta).

C=CX(0∘)CY(89.95∘)CZ(0∘)=CY(89.95∘)CY(β)=[cos⁡β0−sin⁡β010sin⁡β0cos⁡β]\begin{aligned}C&=C_X(0^\circ)C_Y(89.95^\circ)C_Z(0^\circ)=C_Y(89.95^\circ)\\C_Y(\beta)&=\begin{bmatrix}\cos\beta&0&-\sin\beta\\0&1&0\\\sin\beta&0&\cos\beta\end{bmatrix}\end{aligned}
Matrix construction near the Euler singularity

Obtain the quaternion and axis-angle forms

The axis u=[0,1,0]Tu=[0,1,0]^{\mathsf T} gives a quaternion with only yy and ww components. Compute them from β/2=44.975∘\beta/2=44.975^\circ. These half-angle expressions remain well conditioned as β\beta approaches 90∘90^\circ.

Quaternion-derived axis-angle output gives the YY axis and 89.95∘89.95^\circ, independently of Euler branch selection.

q=[0,sin⁡(44.975∘),0,cos⁡(44.975∘)]≈[0.000000,0.706798,0.000000,0.707415]u=[0,1,0]T,θ=89.95∘\begin{aligned}q&=[0,\sin(44.975^\circ),0,\cos(44.975^\circ)]\\&\approx[0.000000,0.706798,0.000000,0.707415]\\u&=[0,1,0]^{\mathsf T},\qquad\theta=89.95^\circ\end{aligned}
Quaternion and axis-angle forms of the specified rotation

Apply the Euler solver’s branch criterion

For ZYX\mathrm{ZYX}, set sβ=−c13s_\beta=-c_{13}. Nonsingular extraction requires ∣sβ∣<1−10−6|s_\beta|<1-10^{-6}. At 89.95∘89.95^\circ, the threshold selects the singular branch: the first angle becomes zero and the middle angle becomes +90∘+90^\circ.

The remaining angle is γ=atan2⁡(−c32,c22)\gamma=\operatorname{atan2}(-c_{32},c_{22}). With c32=0c_{32}=0 and c22=1c_{22}=1, γ=0∘\gamma=0^\circ. The converter displays [0∘,90∘,0∘][0^\circ,90^\circ,0^\circ] and a near-singularity warning.

∣sβ∣=sin⁡(89.95∘)≈0.9999996192281−10−6=0.999999∣sβ∣≥1−10−6α=0∘,β=90∘,γ=0∘\begin{aligned}|s_\beta|&=\sin(89.95^\circ)\approx0.999999619228\\1-10^{-6}&=0.999999\\|s_\beta|&\ge1-10^{-6}\\\alpha&=0^\circ,\qquad\beta=90^\circ,\qquad\gamma=0^\circ\end{aligned}
Evaluation of the singular-branch threshold

Measure the effect of the selected branch

The displayed Euler triple reconstructs C^=CY(90∘)\hat C=C_Y(90^\circ). The original is C=CY(89.95∘)C=C_Y(89.95^\circ). Their largest entrywise difference lies on the diagonal and equals cos⁡(89.95∘)\cos(89.95^\circ) 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.

C^=CY(90∘)max⁡i,j∣C^ij−Cij∣≈0.000872664515≈8.72665×10−4\begin{aligned}\hat C&=C_Y(90^\circ)\\\max_{i,j}|\hat C_{ij}-C_{ij}|&\approx0.000872664515\\&\approx8.72665\times10^{-4}\end{aligned}
Largest entrywise reconstruction error

Input · Passive, ZYX, degrees

Z = 0°, Y = 89.95°, X = 0°

Expected passive matrix

C = [
0.000873 0.000000 -1.000000;
0.000000 1.000000 0.000000;
1.000000 0.000000 0.000873
]

Quaternion · x, y, z, w

q = [0.000000, 0.706798, 0.000000, 0.707415]

Euler · Z, Y, X · degrees

[0.000000°, 90.000000°, 0.000000°]

Axis-angle · u_x, u_y, u_z, θ · degrees

[0.000000, 1.000000, 0.000000, 89.950000°]

Verification. Euler output is [0∘,90∘,0∘][0^\circ,90^\circ,0^\circ]; axis-angle output is [0,1,0,89.95∘][0,1,0,89.95^\circ]. Euler reconstruction gives a maximum entrywise error of approximately 8.72665×10−48.72665\times10^{-4}. Preserve the original matrix or quaternion when this error matters.

Load this example

Comparing equivalent representations

Quaternions qq and −q-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.