# Retrieving angles from a rotation matrix

I'm working with rotations in n dimensions. I represent these rotations as a sequence of $(n^2 - n)/2$ angles, one for each pair of axes, in a fixed order. I can easily compute a rotation matrix from this, by generating the Givens matrix for each angle, and multiplying these matrices.

The problem is doing it the other way around. Given an orthogonal matrix, how can I retrieve the angles in the right order? I'm using an evolutionary algorithm at the moment, which works reasonably well, but is very slow. It would be good if there were a fast method for calculating an exact solution. Unfortunately, most things I find are limited to the 3d case.

My linear algebra is limited to the very practical. I'm willing to learn, of course, but I need to know where to look first.

-

## 1 Answer

I assume your orthogonal matrix $R$ has determinant 1, so it is possible to write it as a product of rotations. Let $e_j$, $j=1\ldots n$, be the standard unit vectors in ${\mathbb R}^n$.

Here's one possible strategy. Take a rotation $R_{1,n}$ in coordinates $1$ and $n$ such that $(R_{1,n} R^{-1} e_n)_1 = 0$, then $R_{2,n}$ in coordinates $2$ and $n$ such that $(R_{2,n} R_{1,n} R^{-1} e_n)_2 = 0$ (noting that you'll still have $(R_{2,n} R_{1,n} R^{-1} e_n)_1 = 0$, and so on until $(R_{n-1,n} \ldots R_{1,n} R^{-1} e_n)_i = 0$ for $i=1,2,\ldots,n-1$. Then $(R_{n-1,n} \ldots R_{1,n} R^{-1} e_n)_n$ must be $\pm 1$. If it's $-1$, change $R_{n-1,n}$ by angle $\pi$ to make it $+1$. Note that, by orthogonality, $R_{n-1,n} \ldots R_{1,n} R^{-1} e_j)_n = 0$ for all $j < n$. Proceed in the same way on the $n-1$ component: $R_{n-2,n-1} \ldots R_{1,n-1} R_{n-1,n} \ldots R_{1,n} R^{-1} e_j = e_j$ for $j=n-1$ and $j=n$. Continue iterating down to $j=2$, obtaining finally $R_{1,2} R{2,3} R_{1,3} \ldots R_{1,n} R^{-1} e_j = e_j$ for $j = 2,3, \ldots, n$. Since, by assumption, the determinant is $1$, this will also be true for $j=1$. Thus $R_{1,2} R_{2,3} R_{1,3} \ldots R_{1,n} R^{-1} = I$, i.e. $R_{1,2} R_{2,3} R_{1,3} \ldots R_{1,n} = R$.

-

That's great. It seems to do exactly what I want (and yes, the determinant is 1, I thought orthogonality=rotation, but apparently that's not true).   Can you comment on how you came up with this? Is this a specific instance of a standard method, or is this sort of stuff just plainly obvious once you reach a certain level of understanding of Linear Algebra? And in the case of the latter, could you suggest a textbook at about that level? – Peter Mar 14 '12 at 10:52
– Robert Israel Mar 14 '12 at 16:55
– Peter Apr 5 at 14:19
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 35, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9434067606925964, "perplexity_flag": "head"}