# 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;}

//A structure that represents a set of 4
//vectors
struct xyzVB
{ xyz vect; //vect=Vector from parent
//vect-vect = unit x vector
//vect-vect = unit y vector
//vect-vect = unit z vector
};

xyzVB CoordSys1 = {0,0,0,
1,0,0,
0,1,0,
0,0,1};

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
int AXIS = SELECT_Y_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, c.p, c.p);
//I use a screen 480,480 in size
glDrawWireSphere(22,8,8);

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 ax_deimos@yahoo.com

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,
1,0,0,
0,1,0,
0,0,1};

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.