Skip to content
Rotation Converter3D ORIENTATION / TECHNICAL REFERENCE

Numerical checks

Conversion preserves orientation within the precision of the input and numerical representation. Check data validity, conventions, rounding, and Euler singularities.

Component order and input parsing

Quaternion input and MATLAB output use scalar-last order [x,y,z,w][x,y,z,w]. Eigen and Python constructors place ww first. The Quaternion (xx, yy, zz, ww) heading stays fixed; read copied constructor values in argument order.

Bulk Import extracts numeric tokens, including scientific notation, in their written order. Enter a bare numeric array and evaluate expressions first: 1/2 supplies 11 and 22; 0.5 supplies their quotient. Digits in comments or type names such as Matrix3d also count as values.

Python output provides constructor syntax. Add the required imports and check the receiving library’s matrix and quaternion conventions for every target language.

Quaternion component order at each interface.
InterfaceOrder
Interactive or bulk quaternion inputxx, yy, zz, ww
MATLAB quaternion output[x,y,z,w][x, y, z, w]
Eigen quaternion outputEigen::Quaterniond q(w, x, y, z)
Python quaternion outputquaternion.Quaternion(w, x, y, z)

Angle units and displayed precision

Input and output angle units are independent. Degrees or radians apply to Euler angles and the axis-angle angle. Matrix, quaternion, and axis components are dimensionless. A quarter-turn is 90∘=π/290^\circ=\pi/2 radians.

Changing input units rescales interactive Euler and axis-angle fields, including individual sequence entries. Pasted numbers remain unchanged and use the selected units on the next parse. Set units before pasting or verify the numbers afterward.

Output units control Euler and axis-angle formatting, including the Eigen constructor. Select Radians when copying Eigen::AngleAxisd, which requires radians.

Decimal Places sets copied values to 1–16 places; the default is 4 and worked examples use 6. The stored matrix retains its precision. Re-entered rounded text has the copied precision. Matrix Determinant uses six decimals; the orthogonality residual uses scientific notation.

θrad=π180θdeg,θdeg=180πθrad\theta_{\mathrm{rad}}=\frac{\pi}{180}\theta_{\mathrm{deg}},\qquad\theta_{\mathrm{deg}}=\frac{180}{\pi}\theta_{\mathrm{rad}}
Degree-radian conversion.

Quaternion normalization and equivalence

Normalize nonzero input as q^=q/∥q∥\hat q=q/\lVert q\rVert. For example, [0,0,1,1][0,0,1,1] has norm 2\sqrt2. Its normalized form [0,0,1/2,1/2][0,0,1/\sqrt2,1/\sqrt2] represents a quarter-turn about ZZ. Evaluate the square roots numerically before entry.

Manual quaternion-to-matrix conversion uses supplied components. Matrix-to-quaternion conversion normalizes its result; verify source-matrix orthogonality separately. ROS Bag normalizes quaternions for replay and reports materially nonunit inputs in Import notes.

For unit quaternions, ∣q1⋅q2∣=1|q_1\cdot q_2|=1 identifies the same rotation, including the sign pair qq, −q-q. Compare with a tolerance suited to the source precision, or compare reconstructed matrices under the same convention. Source precision limits meaningful output digits.

∥q∥=x2+y2+z2+w2q^=q∥q∥,∥q∥>0C(q^)=C(−q^)\begin{aligned}\lVert q\rVert&=\sqrt{x^2+y^2+z^2+w^2} \\ \hat q&=\frac{q}{\lVert q\rVert}, & \lVert q\rVert&>0 \\ C(\hat q)&=C(-\hat q)\end{aligned}
Normalization and quaternion sign equivalence.

Matrix determinant and orthogonality

A proper rotation satisfies both det⁡(C)=1\det(C)=1 and CCT=ICC^{\mathsf T}=I. The shear matrix below has determinant 11 and nonorthogonal first and second rows.

The residual is the largest absolute entry of MMT−IMM^{\mathsf T}-I, using stored matrix MM. It triggers a warning above 10−410^{-4}. The determinant warning requires ∣det⁡(M)−1∣>0.1|\det(M)-1|>0.1. Transposition preserves determinants. For invalid matrices, entrywise residuals of MMT−IMM^{\mathsf T}-I and MTM−IM^{\mathsf T}M-I may differ; the display always uses stored MM.

Conversion rejects non-finite matrix entries. Finite invalid matrices are used directly and may produce output and warnings. A zero axis produces non-finite entries and is rejected. Enter identity with a nonzero axis and zero angle.

After a failed check, inspect quaternion norm, source precision, component order, scale, and shear. A reflection has determinant −1-1 and reverses orientation. Confirm the intended frame mapping from the source conventions.

ρ(M)=max⁡i,j∣(MMT−I)ij∣S=[10.20010001]det⁡(S)=1,ρ(S)=0.2\begin{aligned}\rho(M)&=\max_{i,j}\left|(MM^{\mathsf T}-I)_{ij}\right| \\ S&=\begin{bmatrix}1&0.2&0\\0&1&0\\0&0&1\end{bmatrix} \\ \det(S)&=1, & \rho(S)&=0.2\end{aligned}
Orthogonality residual and a determinant-one counterexample.

Euler singularities and the extraction branch

Every supported sequence is singular at middle angle β=±90∘\beta=\pm90^\circ. The first and third rotations are coupled, so many outer-angle pairs represent one orientation. Matrix and quaternion representations remain valid.

The solver obtains sβ=sin⁡(β)s_\beta=\sin(\beta) from a sequence-dependent matrix entry. The regular branch computes β\beta with atan2⁡\operatorname{atan2}, using sβs_\beta and a nonnegative square-root denominator from two other entries. Its range is −90∘-90^\circ to +90∘+90^\circ. Sequence-specific atan2⁡\operatorname{atan2} expressions give the outer angles.

The regular branch requires ∣sβ∣<1−10−6|s_\beta|<1-10^{-6}. Otherwise, the solver sets α=0\alpha=0, sets β=±90∘\beta=\pm90^\circ with the sign of sβs_\beta, and computes the remaining angle from the table below. For valid matrices, this threshold is approximately ∣β∣=89.918972∘|\beta|=89.918972^\circ.

Near singularity appears when the extracted middle angle lies strictly within 2∘2^\circ of ±90∘\pm90^\circ. This warning also covers regular-branch values. In Active mode, both rules apply to the reversed extraction sequence.

For ZYX\mathrm{ZYX} input [0,89.95,0][0,89.95,0] degrees, matrix and quaternion retain 89.95∘89.95^\circ; Euler extraction returns [0,90,0][0,90,0]. Reconstruction from that triple changes the largest matrix entry by about 0.0008730.000873. Use the matrix or quaternion when this difference matters. Worked example 3 derives it.

Sequence-dependent sine and final angle in the singular branch. Entries refer to the matrix being decomposed; atan2⁡\operatorname{atan2} arguments are (y,x)(y, x).
Sequencesβs_\betaγ\gamma when ∣sβ∣≥1−10−6|s_\beta | \ge 1 - 10^{-6}
123123 / XYZ\mathrm{XYZ}c31c_{31}atan2⁡(c12,c22)\operatorname{atan2}(c_{12}, c_{22})
132132 / XZY\mathrm{XZY}−c21-c_{21}atan2⁡(−c13,c33)\operatorname{atan2}(-c_{13}, c_{33})
213213 / YXZ\mathrm{YXZ}−c32-c_{32}atan2⁡(−c21,c11)\operatorname{atan2}(-c_{21}, c_{11})
231231 / YZX\mathrm{YZX}c12c_{12}atan2⁡(c23,c33)\operatorname{atan2}(c_{23}, c_{33})
312312 / ZXY\mathrm{ZXY}c23c_{23}atan2⁡(c31,c11)\operatorname{atan2}(c_{31}, c_{11})
321321 / ZYX\mathrm{ZYX}−c13-c_{13}atan2⁡(−c32,c22)\operatorname{atan2}(-c_{32}, c_{22})