# How can I convert an axis-angle representation to a Euler angle representation

This is a CAD problem but it boils down to just maths I think.

I have a sphere that I need to rotate, and the program I use needs me to give the rotation about 3 fixed axes. This would be easy if I happened to want to rotate about one of those axes, but I don't.

To achieve this, I need a function to transform the axis-angle representation to a Euler angle representation.

The offsets of the axis of rotation from the co-ordinate axes are: -17°, +40° and -30°

The application has symbols like the following next to the angles: I've found this titled "Conversion Axis-Angle to Euler", which looks like what I need, but I'm not sure about the terminology. Do 'heading', 'attitude' and 'bank' relate to the offsets above, and 'angle' to the angle of the desired rotation about the axis?

• First move your fixed axis to one of the coordinate axes, then perform your rotation, then move your fixed axis back to its original location.
– Neal
Oct 3, 2013 at 13:06
• @Neal the package I'm using is not true 3D software and can't do that unfortunately. It does allow me to feed in new offsets and animate in that fashion…
– user76445
Oct 3, 2013 at 13:23
• The key terms I think you're missing are axis-angle and Euler angle representations. There doesn't seem to be an existing question about the conversion from axis-angle to Euler angles, but knowing the terminology is a good starting point when searching. Oct 3, 2013 at 13:28
• @Peter many thanks I've had a go at updating the question with those terms
– user76445
Oct 3, 2013 at 13:33
• This Wikipedia article has a lot of conversion formulae.
– user856
Oct 5, 2013 at 17:21

In the following, we adjust $\delta$ in the range specified by $(2)$, $\sigma_B=\pm1$, and $\sigma_C=\pm1$ until we get the required rotation.

Angles $\alpha$, $\beta$, and $\gamma$

Let $\alpha$, $\beta$, and $\gamma$ be the angles from the $X$, $Y$, and $Z$ axes to the axis of rotation, $A$. These three angles are related by the Pythagorean Theorem: $$\cos^2(\alpha)+\cos^2(\beta)+\cos^2(\gamma)=1\tag{1}$$ These angles, along with the angle $\delta$, will be assumed to be in the range $[0,\pi]$.

Angles $\rho_X$, $\rho_Y$, and $\rho_Z$

Consider the diagram on the sphere

$\hspace{3.2cm}$ For each value of $\delta$ so that $$\sin^2(\delta)\ge\max\left(\cos^2(\alpha),\cos^2(\gamma)\right)\tag{2}$$ the circle of radius $\delta$ about $Y$ intersects both the circle of radius $\alpha$ about $X$ and the circle of radius $\gamma$ about $Z$ at one or two points.

Using the Spherical Law of Cosines, we can compute $$\angle AXY=2\tan^{-1}\left(\frac{\cos(\gamma)}{\sin(\alpha)+\cos(\beta)}\right)\tag{3}$$ For each $\alpha$ and $\delta$, there are one or two solutions for $B$. To account for this, let $\sigma_B=\pm1$. Then \begin{align} \rho_X&=\angle AXY-\sigma_B\cos^{-1}\left(\frac{\cos(\delta)}{\sin(\alpha)}\right)\tag{4}\\ \angle YBX&=\pi-\sigma_B\cos^{-1}(\cot(\alpha)\cot(\delta))\tag{5}\\ \angle XYB&=\sigma_B\cos^{-1}\left(\frac{\cos(\alpha)}{\sin(\delta)}\right)\tag{6} \end{align} Using the Spherical Law of Cosines, we can compute $$\angle YZA=2\tan^{-1}\left(\frac{\cos(\alpha)}{\sin(\gamma)+\cos(\beta)}\right)\tag{7}$$ For each $\gamma$ and $\delta$, there are one or two solutions for $C$. To account for this, let $\sigma_C=\pm1$. Then \begin{align} \rho_Z&=\angle YZA-\sigma_C\cos^{-1}\left(\frac{\cos(\delta)}{\sin(\gamma)}\right)\tag{8}\\ \angle ZCY&=\pi-\sigma_C\cos^{-1}(\cot(\gamma)\cot(\delta))\tag{9}\\ \angle CYZ&=\sigma_C\cos^{-1}\left(\frac{\cos(\gamma)}{\sin(\delta)}\right)\tag{10} \end{align} For consistency, define $\sigma_A=\mathrm{sgn}(\cos(\beta))$. Since $\angle XYZ=\frac\pi2$, \begin{align} \rho_Y&=\frac\pi2-\angle XYB-\angle CYZ\tag{11}\\ \angle XAZ&=\pi-\sigma_A\cos^{-1}(\cot(\alpha)\cot(\gamma))\tag{12} \end{align}

Angle of Rotation

The rotations $\rho_X$, $\rho_Y$, and $\rho_Z$ computed above will fix the axis $A$. Accounting for parallel transport, the rotation about the axis $A$ is equal to the total geodesic curvature $$\rho_X\cos(\alpha)+\rho_Y\cos(\delta)+\rho_Z\cos(\gamma)\tag{13}$$ minus the area of the light red deltoid region (since it is traversed clockwise).

Using Girard's Theorem, the areas of the purple triangles are \begin{align} |\triangle A|&=\angle ZXA+\angle AZX+\angle XAZ-\pi\\ |\triangle B|&=\angle BXY+\angle XYB+\angle YBX-\pi\\ |\triangle C|&=\angle YZC+\angle CYZ+\angle ZCY-\pi \end{align}\tag{14} The areas of the white sectors are \begin{align} |\unicode{x2AA6} X|&=\rho_X\,(1-\cos(\alpha))\\ |\unicode{x2AA6} Y|&=\rho_Y\,(1-\cos(\delta))\\ |\unicode{x2AA6} Z|&=\rho_Z\,(1-\cos(\gamma)) \end{align}\tag{15} The area of the light red deltoid is $$\frac\pi2-|\triangle A|-|\triangle B|-|\triangle C|-|\unicode{x2AA6} X|-|\unicode{x2AA6} Y|-|\unicode{x2AA6} Z|\tag{16}$$ Note that depending on the signs of $\sigma_B$ and $\sigma_C$, the light red deltoid may have one or two lunes attached.

Subtracting $(16)$ from $(13)$ yields a rotation of $$|\triangle A|+|\triangle B|+|\triangle C|+\rho_X+\rho_Y+\rho_Z-\frac\pi2\tag{17}$$ Four applications of Girard's Theorem reduces $(17)$ to $$\angle XBY+\angle YCZ+\angle ZAX-2\pi\tag{18}$$

Example:

Suppose $\alpha=\gamma=\frac\pi3$ and $\beta=\frac\pi4$. Note that $\cos^2(\alpha)+\cos^2(\beta)+\cos^2(\gamma)=1$.

By $(2)$, we can choose any $\delta$ so that $\sin^2(\delta)\ge\frac14$. Let $\delta=\frac\pi6$.

$(3)$: $\angle AXY=0.615479708670388$

$(4)$: $\rho_X=0.615479708670388$

$(5)$: $\angle YBX=\pi$

$(6)$: $\angle XYB=0$

$(7)$: $\angle YZA=0.615479708670388$

$(8)$: $\rho_Z=0.615479708670388$

$(9)$: $\angle ZCY=\pi$

$(10)$: $\angle CYZ=0$

$(11)$: $\rho_Y=\frac\pi2$

$(12)$: $\angle XAZ=1.91063323624902$

$(18)$ says that the rotation is $1.91063323624902$.

Note that the angles specified in your question do not satisfy $(1)$: $$\cos^2(\alpha)+\cos^2(\beta)+\cos^2(\gamma)=2.25134287511099\ne1$$ There is no point that is $-17^\circ$, $+40^\circ$, and $-30^\circ$ from the coordinate axes.

• I really appreciate this answer: from your last statement it looks like I'm misinterpreting the symbols representing the three variables
– user76445
Oct 10, 2013 at 13:37
• @JackDouglas: Perhaps those numbers represent rotations on the coordinate axes?
– robjohn
Oct 10, 2013 at 14:25
• That certainly seems to fit the diagram now I look again, thanks
– user76445
Oct 10, 2013 at 15:31
• @JackDouglas: I think my second answer should cover that case.
– robjohn
Oct 10, 2013 at 17:53

Since your angles do not work with the original interpretation, let's assume that they represent the angle of rotation on each axis. That is, the rotation is given by $$\hspace{-8mm} A=\begin{bmatrix} \cos(\gamma)&\sin(\gamma)&0\\ -\sin(\gamma)&\cos(\gamma)&0\\ 0&0&1 \end{bmatrix} \begin{bmatrix} \cos(\beta)&0&-\sin(\beta)\\ 0&1&0\\ \sin(\beta)&0&\cos(\beta) \end{bmatrix} \begin{bmatrix} 1&0&0\\ 0&\cos(\alpha)&\sin(\alpha)\\ 0&-\sin(\alpha)&\cos(\alpha)\\ \end{bmatrix}\tag{1}$$ I think the easiest way to find the axis for such a rotation is to use the formula I give in this answer to find the axis of rotation, $v$, for a rotation matrix, $A$.

Let $u$ be any column of $A^T-I$. We can find the cosine of the angle of rotation by $$\cos(\theta)=\frac{u\cdot Au}{|u|^2}\tag{2}$$ The sine of the angle of rotation is given by $$\sin(\theta)=\pm\frac{v\cdot u\times Au}{|v||u|^2}\tag{3}$$ The sign used in $(3)$ is dependent on the definition of the cross product and on the orientation of the coordinate axes.

Example:

For $\alpha=-17^\circ$, $\beta=40^\circ$, $\gamma=-30^\circ$, $(1)$ yields $$A=\begin{bmatrix} 0.663413948168938 & -0.640907051572032 & -0.386160697922698 \\ 0.383022221559489 & 0.734217757814514 & -0.560551747746327 \\ 0.642787609686539 & 0.223969719728075 & 0.732571944233734 \end{bmatrix}$$ Using the first formula from the cited answer, we get that the axis of rotation is $$v=\begin{bmatrix} 0.256626911763841\\ -0.336582028018252\\ 0.334940238250282 \end{bmatrix}$$ Let $u$ be the first column of $A^T-I$: $$u=\begin{bmatrix} -0.336586051831062\\ -0.640907051572032\\ -0.386160697922698 \end{bmatrix}$$ $(2)$ says $\cos(\theta)=0.565101825108593$ and $(3)$ gives $\sin(\theta)=0.825021167764159$.

Therefore, $\theta=0.970239657223180=55.59^\circ$.

• forgive my slowness, does this enable me to compute the 'angle of rotation on each [Euler] axis' given an angle of rotation about the axis of rotation?
– user76445
Oct 10, 2013 at 18:10
• The other answer allows you to compute the rotations on the three coordinate axes to make a given rotation on a given axis. This answer allows you to compute the axis and the rotation on that axis given the rotations on the coordinate axes. This is what I thought you were asking for.
– robjohn
Oct 10, 2013 at 18:15
• OK, sorry for the confusion!
– user76445
Oct 11, 2013 at 9:15