4x4 matrix Q

edited November 2007 in Chit chat
I have a 4x4 matrix used for rotating a 3D object to rotate to face any point in one simple step, and looks something like:
a b c 0
e f g 0
h i j 0
0 0 0 1

This rotates in X, Y and Z simultaneously (no translation in these particular matrices).

Do any of you Maths whizzes know how to extract just the Y-rotation angle out of that?
Post edited by NickH on

Comments

  • edited November 2007
    smoke the fucker out.
  • edited November 2007
    mile wrote: »
    smoke the fucker out.

    You know you don't have to respond to every thread, right? ;)
  • edited November 2007
    NickH wrote: »
    You know you don't have to respond to every thread, right? ;)

    i don't even look at the boring threads, but i thought this was going to be about the matrix film. you decived me, so i thought i'd spoil your thread. :lol:
  • edited November 2007
    I'm a bit rusty with matrix algebra, but I don't think it's possible... there isn't one unique way to decompose a rotation into X, Y and Z components.

    For example, a 90-degree rotation about the Y axis is exactly equivalent to 90 degrees about X followed by 90 degrees about Z. I suspect there's an infinite number of ways to decompose any rotation, but don't quote me on that...
  • edited November 2007
    gasman wrote: »
    I'm a bit rusty with matrix algebra, but I don't think it's possible... there isn't one unique way to decompose a rotation into X, Y and Z components.

    For example, a 90-degree rotation about the Y axis is exactly equivalent to 90 degrees about X followed by 90 degrees about Z. I suspect there's an infinite number of ways to decompose any rotation, but don't quote me on that...

    I had a feeling that would be the case... currently trying to figure it out myself, and it's a complete headflip[1]...

    [1] Self-censorship is fun.
  • edited November 2007
    It's incredibly yucky, but here's the hack I just knocked up.

    For background, I have a list of object positions over time (x,y,z) and a 4x4 rotation matrix.

    For rotation matrices (from an FAQ):
             |  CE      -CF       D   0 |
        M  = |  BDE+AF  -BDF+AE  -BC  0 |
             | -ADE+BF   ADF+BE   AC  0 |
             |  0        0        0   1 |
    
      where A,B are the cosine and sine of the X-axis rotation axis,
            C,D are the cosine and sine of the Y-axis rotation axis,
            E,F are the cosine and sine of the Z-axis rotation axis.
    

    Now, sin(rotY) = matrix[0][2] - and of course, asin(matrix[0][2]) really returns two values.

    (forgive the poor variable names)
    lx = 0
    lz = 0
    for (n=0; n<len(list); n++) {
        d = matrix[0][2]
        a = rad2deg(asin(d))
        # now find other solution
        if (a <= 180) {
            b = 180 -a
        } else {
            b = a -180
            b = 180 -b
            b = b + 180
        }
        if (n==0) {
            #guess
            roty = a
        } else {
            if (list[n].z < lz) {
                roty = a
            } else {
                roty = b
            }
        }
        lx = list[n].x
        lz = list[n].z
    }
    

    Very kludgy, but works for finding the Y-rotation angle, providing you have a stream of co-ordinates to work with (as I do).

    If anyone's interesteg, I'm using all this for collision detection for positioning the elements of the 1989 chapter intro animation. (Teaser)
Sign In or Register to comment.