Homogeneous transformation matrix (7)

Kinematics & Universal Numerics
July 28, 2019

Conversion between rotation matrix and its axis-angle representation.

In the past two blogs, we have shown how to convert a rotation in the axis-angle representation (𝐝,θ) into the matrix representation. We summarize the steps here:

  • β€’

    Find Ο•βˆˆ[0,Ο€],ψ∈(-Ο€,Ο€] that parametrize a normalized (unit) vector 𝐝:

    𝐝=[dxdydz]=[sϕ⁒cψsϕ⁒sψcΟ•].
  • β€’

    Use Ο•,ψ to construct

    𝐒0=[sψcϕ⁒cψsϕ⁒cψ-cψcϕ⁒sψsϕ⁒sψ-sΟ•cΟ•]. (1)
  • β€’

    The rotation matrix is hence

    𝐑=𝐒0⁒[cΞΈ-sΞΈsΞΈcΞΈ1]⁒𝐒0T. (2)

Conversely, given a rotation matrix 𝐑=(ri⁒j), how can we find its axis-angle representation (𝐝,ΞΈ)? Assume Ξ»1,Ξ»2,Ξ»3 are the three eigenvalues of 𝐑. Then for each eigenvalue of 𝐑, i=1,2,3,

0 =det⁑(𝐑-Ξ»i⁒𝐈)
=det⁑(𝐒0β‹…Rotz⁒(ΞΈ)⋅𝐒0T-Ξ»i⁒𝐒0⁒𝐒0T)
=det⁑(𝐒0β‹…(Rotz⁒(ΞΈ)-Ξ»i⁒𝐈)⋅𝐒0T)
=det⁑(𝐒0)β‹…det⁑(Rotz⁒(ΞΈ)-Ξ»i⁒𝐈)β‹…det⁑(𝐒0T)
=1β‹…det⁑(Rotz⁒(ΞΈ)-Ξ»i⁒𝐈)β‹…1
=det⁑(Rotz⁒(θ)-λi⁒𝐈),

which means Ξ»i is also an eigenvalue of Rotz⁒(ΞΈ). In other words, 𝐑 is obtained by performing a similarity transform 𝐒0 on Rotz⁒(ΞΈ), so matrices 𝐑 and Rotz⁒(ΞΈ) have the same eigenvalues.

The sum of eigenvalues of an nΓ—n matrix 𝐀=(ai⁒j) equals its matrix trace, that is the sum of diagonal elements of 𝐀:

tr⁒(𝐀)=βˆ‘i=1nai⁒i.

Having the same eigenvalues, matrices 𝐑 and Rotz⁒(ΞΈ) also have the same trace

r11+r22+r33=tr⁒(𝐑)=Ξ»1+Ξ»2+Ξ»3=tr⁒(Rotz⁒(ΞΈ))=2⁒cΞΈ+1.

Since entries of 𝐑 are given, we can calculate ΞΈ by

θ=arccos⁑r11+r22+r33-12. (3)

To derive the rotation axis 𝐝=𝐒0⁒𝐞1,3, we may first try to eliminate one of the two trigonometric terms sΞΈ and cΞΈ. In our first attempt, we get rid of cΞΈ by taking the difference of 𝐑 and its transpose:

𝐑-𝐑T =𝐒0⁒[cΞΈ-sΞΈsΞΈcΞΈ1]⁒𝐒0T-𝐒0⁒[c-ΞΈ-s-ΞΈs-ΞΈc-ΞΈ1]⁒𝐒0T
=2⋅𝐒0⁒[-sΞΈsΞΈ0]⁒𝐒0T
=2⁒sθ⋅𝐒0⁒[-110]⁒𝐒0T. (4)

We claim this is exactly 2⁒sθ⋅𝐝×, where β€œ(β‹…)×” is an operator on a directional vector 𝐝 such that

𝐝×=[dxdydz]Γ—:=[-dzdydz-dx-dydx].

Then the cross product can be also written as

𝐝×𝐯=𝐝×⁒𝐯.

To show (4) is indeed 2⁒sθ⋅𝐝×, we first write (using subscripts in column major form)

𝐒0=[𝐬1,𝐬2,𝐝]:=[s1,1s2,1dxs1,2s2,2dys1,3s2,3dz],

and the matrix product becomes

𝐒0⁒[-110]⁒𝐒0T=[𝐬2,-𝐬1, 0]⁒[𝐬1T𝐬2T𝐝T]=𝐬2⁒𝐬1T-𝐬1⁒𝐬2T=𝐝×.

The last step can be verified by writing 𝐬2⁒𝐬1T-𝐬1⁒𝐬2T into the full 3Γ—3 matrix, for example, on position (1,2),

s2,1⁒s1,2-s1,1⁒s2,2=-dz.

So far we have shown

𝐑-𝐑T=2⁒sθ⁒𝐝×=2⁒sθ⁒[-dzdydz-dx-dydx]. (5)

We have three cases to discuss:

  1. Case 1: ΞΈβ‰ 0 and ΞΈβ‰ Ο€. This is the regular case: sΞΈβ‰ 0. Getting 𝐝 is by simply matching both hand sides in (5):

    𝐝=[dxdydz]=12⁒sθ⁒[r32-r23r13-r31r21-r12], (6)

    where 𝐑=(ri⁒j).

  2. Case 2: θ=0. Then the rotation is trivial so the rotation axis can be arbitrary. In such a case we choose the default 𝐝=[001] in our convention.

  3. Case 3: ΞΈ=Ο€. This occurs only when (tr⁒(𝐑)-1)/2=sΞΈ=sin⁑π=-1, so tr⁒(𝐑)=r11+r22+r33=-1. In this case, 𝐑=𝐑T, so we cannot use (6) to determine 𝐝. By plugging in 𝐒0 from (1) and ΞΈ=Ο€ in (2), we obtain

    𝐑=[-2⁒sΟ•2⁒sψ2-c2⁒ϕsΟ•2⁒s2⁒ψcψ⁒s2⁒ϕsΟ•2⁒s2⁒ψ2⁒sΟ•2⁒sψ2-1sψ⁒s2⁒ϕcψ⁒s2⁒ϕsψ⁒s2⁒ϕc2⁒ϕ].

    Then

    Ο• =12⁒arccos⁑r33∈[0,Ο€/2]
    ψ ={arbitraryifΒ Ο•=0, so ⁒𝐝=[001]r22+12ifΒ Ο•=Ο€/2, so ⁒𝐝=[cψsψ0]atan2⁒(r23,r13)ifΒ s2⁒ϕ≠0, soΒ Ο•β‰ 0Β andΒ Ο•β‰ Ο€/2.

We remind ourselves that

𝐝=[sϕ⁒cψsϕ⁒sψcΟ•].