# Determining axis of rotation

1. Sep 24, 2011

### JamesGoh

Given the matrix of rotation, what is the procedure to determine the axis of rotation ?

Is there a set mathematical way to do it (like a formula), or is it something that you need to

2. Sep 24, 2011

### CompuChip

If A is a rotation matrix and v is along the axis of rotation, then what should Av be?
What is the mathematical name for this property?

3. Sep 24, 2011

### JamesGoh

Okay, from a non-mathematical reasoning, would Av be the rotation of v ?

The name of this property is mapping/transformation ?

Im guessing that we can use eigenvalues and eigenvectors to be able to determine v

4. Sep 24, 2011

### D H

Staff Emeritus
I assume you are talking about a 3x3 matrix rather than some arbitrary NxN matrix. The three dimensional space R3 is the only space in which you can legitimately talk about an "axis of rotation". For R2, the "axis of rotation" isn't in the space, rotation is rather weird for R4, weirder yet for R5 and higher.

To start, look at the reverse situation. Given a rotation by an angle $\phi$ about an axis $\hat{\mathbf u}$, the [j] element of the transformation matrix is given by

$$T_{ij} = \cos\phi\,\delta_{ij} + (1-\cos\phi)\,\hat u_i \hat u_j + \epsilon_{ijk}\sin\phi\,\hat u_k$$
where $\delta_{ij}$ is the Kronecker delta, $k \equiv i+j \bmod 3$, and $\epsilon_{ijk}$ is the Levi-Civita symbol.

The problem is to find the inverse of this: Given a transformation matrix $\boldsymbol T$, solve for $\phi$ and $\hat{\mathbf u}$ given a transformation matrix $\boldsymbol T$. I'll call this phi and uhat the eigen rotation.

There are several alternate expressions for computing the eigen rotation from a transformation matrix, all of which are equivalent in infinite precision arithmetic. The use of finite precision arithmetic means that care must be taken in choosing the algorithm to be used. The starting point is the above equation that takes us from phi and uhat to a transformation matrix.

From this, the trace of the matrix and the difference between and sum of pairs of off-diagonal elements are

\begin{align} \mathrm{tr}(T) &= 2\cos\phi + 1 \\ T_{ij}-T_{ji} &= 2\epsilon_{ijk}\sin\phi\,\hat u_k \\ T_{ij}+T_{ji} &= 2(1-\cos\phi)\,\hat u_i \hat u_j \end{align}

Method 1
One approach to determining the eigen rotation involves the construction of a vector of differences between pairs of off-diagonal elements of the transformation matrix,

$$d_k \equiv T_{ij}-T_{ji} = 2 \sin\phi\,\hat u_k$$

where (i,j,k) is an even permutation of (0,1,2). With this,

\begin{align} \sin\phi &= \frac{||\mathbf d||} 2 \\ \\ \hat{\mathbf u} &= \frac{\mathbf d}{||\mathbf d||} \end{align}

Note that in the above, the use of the inverse sine will restrict the rotation angle to be between 0 and 90 degrees. Special processing is needed when the rotation angle is between 90 and 180 degrees. Note also that the symmetric difference vector will be identically zero if the rotation angle is 0 or 180 degrees and will be very small for rotation angles close to 0 or 180 degrees.

The precision loss for rotation angles near 0 and 180 degrees means the individual components of the eigen axis will not be as precise with this approach compared to alternatives.

Method 2
The diagonal elements of the matrix yields another method for determining the eigen angle and eigen axis:

\begin{align} \phi &=\arccos\left(\frac{\mathrm{tr}(T)-1} 2\right) \\ |\hat u_i| &= \sqrt{\frac{T_{ii} - \cos \phi}{1-\cos\phi}} \end{align}

Note that this approach determines the magnitudes but not the signs of the components of the eigen axis vector. Because this method is based on the inverse cosine, the calculated phi angle will be less precise than that obtained by method 1 for angles near 0 or 180 degrees. The component of the unit vector however will be more accurate than that obtained from method 1 in the case of large $T_{ii}$.

Method 3
Yet another alternative for computing components of the eigen axis is to use the sum of pairs of off-diagonal elements of the transformation matrix,

\begin{align} T_{ij}+T_{ji} &=2(1-\cos\phi)\,\hat u_i \hat u_j \\ T_{ik}+T_{ki} &=2(1-\cos\phi)\,\hat u_i \hat u_k \end{align}

This enables the calculation of two components of the unit vector. One component needs to be computed by one of the two previous methods.

How to apply these techniques?
The above techniques provide two ways to compute the rotation angle, three to compute the rotation axis. Which is best depends on the angle. There are four cases.

Case 1: The trivial rotation, rotation angle = 0.
The rotation axis is ill-defined in the the case of an identity matrix. This case is evidenced by $\sin\phi = 0, \cos\phi > 0$. Set the rotation angle to zero and pick an arbitrary axis.

Case 2: Rotation angle between 0 and 45 degrees (exclusive).
This case is evidenced by $-\cos\phi < \sin\phi < \cos\phi$. Here method #1 provides the best accuracy for both the rotation angle and the rotation axis.

Case 3: Rotation angle between 45 and 135 degrees (inclusive).
This case is evidenced by $\sin\phi \ge |\cos\phi|$. Here method #2 provides the best accuracy for the rotation angle but method #1 is still the best (most accurate) approach for determining the rotation axis.

Case 4: Rotation angle greater than 135 degrees.
Here the sine will once again provide better accuracy than does cosine, but you can't just use inverse sine. Instead use $\phi = \pi - \arcsin(\sin\phi)$. The rotation axis is a bit of a bear in this case. A combination of all three methods is needed. Method #2 provides the best accuracy for the component corresponding to the largest diagonal element, but method #2 is ambiguous regarding sign. Method #1, while inaccurate, is good enough to indicate the sign of this component. (Note: If method #1 says the component is zero we're at a 180 degree rotation. Pick any sign. The direction is arbitrary here.) Now use method #3 to determine the other two components.

Last edited: Sep 24, 2011
5. Sep 24, 2011

### CompuChip

Yep, that's what I meant by the notation Av, but that's not really what I tried to ask :)
What I meant is: what do you get when you apply the rotation to a vector along the rotation axis?

Is that guess based on anything rational? :)