Mike Day: Extracting Euler Angles from a Rotation Matrix

This article attempts to fix a problem which came up when implementing Ken Shoemake’s Euler angle extraction in the context of a single-precision floating point library. The original Shoemake code uses double precision, which presumably maintains sufficient precision for the problem not to arise.

euler angles.pdf (Updated 2/24/2014 with typo noted by John-Michael Fischer below fixed.)

  • John-Michael Fischer

    Hi Mike, in reviewing your pdf today I noticed there may be a typo. On page three you compute M’. The second line in the first matrix appears to confuse two coefficients. They are listed as c0 and -s0, when I believe they should be c1 and -s1. Regards.

    • Mike Day

      Thanks, John-Michael! We fixed the typo; sorry it took us a while.

  • Chris Burel

    Hi Mike,
    I’m wondering about how you calculate c2. In the pdf you have this as:
    c2 = sqrt(m[0][0]^2 + m[0][1]^2)

    However, you already know that m[0][2] is equal to -s2. So wouldn’t it be one less operation to do:
    c2 = sqrt(1 + m[0][2]^2)

    • Mike Day

      Hi Chris,
      I’m no longer with Insomniac, so I’ve only just noticed your question! You are right about your method reducing the instruction count. However, I suspect the reason I chose the same method for c2 as the original Shoemake code is that it maintains better precision when m02 is close to 1.0f or -1.0f. In these cases, when you subtract m02^2 from 1.0f (I assume you meant ‘-‘ where you wrote ‘+’), catastrophic cancellation occurs and you’re left with a small number of significant bits, almost none in the most extreme cases. On the other hand, although m00^2 and m01^2 will both be very small in these cases, being floating point numbers they still maintain their full precision, and adding them yields an accurate result.
      Hope that helps!