Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Mathematics of rotations, why does this fail?

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2001
    Montreal, Quebec Canada

    Mathematics of rotations, why does this fail?

    Why is it that when I use glRotation I fail to get a rotation around a specified axis?

    I include the following example code

    //A structure that represents either a point
    //or a vector in x,y,z
    struct xyz { double p[3];}

    //A structure that represents a set of 4
    struct xyzVB
    { xyz vect[4]; //vect[0]=Vector from parent
    //vect[1]-vect[0] = unit x vector
    //vect[2]-vect[0] = unit y vector
    //vect[3]-vect[0] = unit z vector

    xyzVB CoordSys1 = {0,0,0,

    const int SELECT_X_AXIS = 1;
    const int SELECT_Y_AXIS = 2;
    const int SELECT_Z_AXIS = 3;

    //This is used to select the current axis
    xyzVB CoordSys2 = {0,0,0,
    (Arbitrary set of
    Orthogonal unit vectors)};
    xyz a = CoordSys1.vect[AXIS];
    // A unit vector
    xyz b = CoordSys2.vect[AXIS];
    // A unit vector
    //Note that DotProduct(a, b) is not zero

    //'c' is the unit normal of 'a x b'
    //It serves as the axis of rotation
    xyz c = CrossProduct(a,b);

    //The angle between vectors 'a' and 'b' is
    //the arc_cos (in degrees) of the dot
    //product of 'a' & 'b'
    //I know it will only get CCW angles ranging
    //from 0 to 180 degrees
    //* note: DotProduct(a,b) != 0)
    double ang = ArcCos_degrees(DotProduct(a,b));

    glRotate(angle, c.p[0], c.p[1], c.p[2]);
    //I use a screen 480,480 in size

    Using this code I can rotate about any axis other than the one specified by the variable AXIS. Why is this so?

    email me a

  2. #2
    Intern Contributor
    Join Date
    Aug 2000

    Re: Mathematics of rotations, why does this fail?

    What in Gods name are trying to do man!

    You have a set of vectors representing to main X,Y & Z axis :

    xyzVB CoordSys1 = {0,0,0,

    Then you have another set of three vectors all at right angles to each other. What I gather you want to do is to pick a pair of vectors; one which is a main X, Y / Z, ther other on eof the arbitary ones.

    Your code then calculate the angle between them and works out a vector their both Orthogonal to and uses thatose in a glRotate. what this will effectivly do is rotate the main axis to the arbitary one.

    Thats what the code does, assuming the functions DotProduct, etc do what they're supposed to.

    However your question makes no sense whatsoever. Why? We ll there is no axis specified by AXIS, it specifies two and as said abvoe they're used to calculate a thrid one and an angle.

    Did you write this code? You don't seen to know what its used for.

    PS, surely you should know that if you can specify any three arbitary vectors, then you can rotate about any axis. It just depends on the vectors chosen.

    The other possibility is that you asked the wrong question, if so please clarify.

    Best of luck.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts