ax_deimos

11-20-2001, 05:22 AM

My program rotates 3D (x,y,z) cartesian coordinate systems. I'm trying to find an algorithm that can rotate a shape (in this case a wireframe sphere) which was originally placed in one coordinate system (lets say coordinate systam 1) so that it will be oriented along the previous coordinate system when placed inside a new coordinate system (called coordinate system 2)

example of coordinate systems:

(Both coordinate systems are RHS unit orthogonal coordinate systems. RHS means right hand side (right thumb points along x, right index finger points along y, right middle finger points along z)

coordinate system 1:

x1 = [(sqrt(3)/2)i, (1/2)j, 0k]

y1 = [(1/2)i, -(sqrt(3)/2)j, 0k]

z1 = [0i, 0j, 1k]

coordinate system 2:

x2 = [1i, 0j, 0k]

y2 = [0i, (sqrt(2)/2)j, (sqrt(2)/2)k]

z2 = [0i, -(sqrt(2)/2)j, (sqrt(2)/2)k]

*Note that sqrt means square root

*Note that these vectors are defined as i,j,k

I've got a partial algorithm which works half way. (It rotates my shape about the x2 axis)

glPushMatrix();

{

//Defines a vector

struct ijk {

// double vect[3];

double i;

double j;

double k;

};

//coordinate system 1

ijk x1 = { (sqrt(3)/2), (1/2), 0};

ijk y1 = {(1/2), -(sqrt(3)/2), 0};

ijk z1 = {0, 0, 1};

//coordinate system 2:

ijk x2 = {1, 0, 0};

ijk y2 = {0, (sqrt(2)/2), (sqrt(2)/2)};

ijk z2 = {0, -(sqrt(2)/2), (sqrt(2)/2)};

//A normal vector generated by crossing

//two equivalent coordinates

ijk normal = CrossProduct(x1, x2);

//Remember that a, b are unit vectors

double cosine_of_a_dot_b = DotProduct(x1,x2);

int angle = ArcCos(cosine_of_a_dot_b);

glRotated(angle,

normal.i, normal.j, normal.k);

glutWireSphere(22, 8,8);

}

glPopMatrix()

//END OF CODE

Try changing the normal from

CrossProduct(x1,x2)

to

CrossProduct(y1,y2)

or

CrossProduct(z1,z2)

ALSO If anyone can come up with a good arccos function for vectors for returning the angle from 0 to 360 degrees CCW I would appreciate that

email me at ax_deimos@yahoo.com

example of coordinate systems:

(Both coordinate systems are RHS unit orthogonal coordinate systems. RHS means right hand side (right thumb points along x, right index finger points along y, right middle finger points along z)

coordinate system 1:

x1 = [(sqrt(3)/2)i, (1/2)j, 0k]

y1 = [(1/2)i, -(sqrt(3)/2)j, 0k]

z1 = [0i, 0j, 1k]

coordinate system 2:

x2 = [1i, 0j, 0k]

y2 = [0i, (sqrt(2)/2)j, (sqrt(2)/2)k]

z2 = [0i, -(sqrt(2)/2)j, (sqrt(2)/2)k]

*Note that sqrt means square root

*Note that these vectors are defined as i,j,k

I've got a partial algorithm which works half way. (It rotates my shape about the x2 axis)

glPushMatrix();

{

//Defines a vector

struct ijk {

// double vect[3];

double i;

double j;

double k;

};

//coordinate system 1

ijk x1 = { (sqrt(3)/2), (1/2), 0};

ijk y1 = {(1/2), -(sqrt(3)/2), 0};

ijk z1 = {0, 0, 1};

//coordinate system 2:

ijk x2 = {1, 0, 0};

ijk y2 = {0, (sqrt(2)/2), (sqrt(2)/2)};

ijk z2 = {0, -(sqrt(2)/2), (sqrt(2)/2)};

//A normal vector generated by crossing

//two equivalent coordinates

ijk normal = CrossProduct(x1, x2);

//Remember that a, b are unit vectors

double cosine_of_a_dot_b = DotProduct(x1,x2);

int angle = ArcCos(cosine_of_a_dot_b);

glRotated(angle,

normal.i, normal.j, normal.k);

glutWireSphere(22, 8,8);

}

glPopMatrix()

//END OF CODE

Try changing the normal from

CrossProduct(x1,x2)

to

CrossProduct(y1,y2)

or

CrossProduct(z1,z2)

ALSO If anyone can come up with a good arccos function for vectors for returning the angle from 0 to 360 degrees CCW I would appreciate that

email me at ax_deimos@yahoo.com