#### Archived

This topic is now archived and is closed to further replies.

# Arbitrary Axis 3D rotation

This topic is 5218 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''ved narrowed down one problem to this rotate function. As it rotates, it elongates, until it hits pi radians, after which it starts to come back to normal.
/*
FUNC: rotate
PRE:  [x y z] NOT zero vector
POST: scene will be rotated by theta degrees about an arbitrary axis
*/
typedef float real;
void rotate(const real theta,
const real ax, const real ay, const real az){
real c=cos(theta);
real s=sin(theta);
real t=1-c;
matrix rot;
identMatrix(rot);
rot.a[0][0]=ax*ax*t + c;
rot.a[0][1]=ax*ay*t + az*s;
rot.a[0][2]=ax*az*t - ay*s;

rot.a[1][0]=ay*ax*t - az*s;
rot.a[1][1]=ay*ay*t + c;
rot.a[1][2]=ay*az*t + ax*s;

rot.a[2][0]=az*ax*t + ay*s;
rot.a[2][1]=az*ay*t - ax*s;
rot.a[2][2]=az*az*t + c;

multMatrix(transMatrix, rot);
}

my complete code and an example
capn_midnight | Captain Midnight | deviantArt ACM | SIGGRAPH | Generation5

##### Share on other sites
Check out: MathWorld: Axis-Angle Form.

EDIT:
Oops, i had my cross product wrong. Capn_midnight, you're cross product is correct, pardon my mistake. I forgot that a the k cofactor of the determinant is negative by definition of determinant, lol. Actually, i tried my incorrect cross product and the rotation had some strange effect of squashing the diamond to a flat planar object, lol.
....

Nope, you're NOT normalizing your axis vector: *checks main.cpp* Yep, this my friend, is not a vector of length 1:
//main.cpp rotate(3.14159*angle/20, 1, -1, 1);

a vector of (1, 1, 1) has a magnitude sqrt(3).

Check the derivation of the axis-angle formula in the provided link, it uses a vector of lenght one, and you're using that formula. Hope that helps Cheers.

Edit: I make so many mistakes it's not even funny.

[edited by - temp_ie_cant_thinkof_name on April 4, 2004 10:05:23 PM]

##### Share on other sites
well, I''ll try that. I have recently changed the code to use a normalized axis of rotation, but it still did the exact same thing without change.

##### Share on other sites
Tell me if it works, i''m curious. A last resort would be to go through each operation one-by-one in the debugger and have the correct result of each be done on paper.

##### Share on other sites
well, I explicitly wrote out the math (the math is not a problem for me), and checked my code, found the changes you suggested. However, it still has the same effect. Now that I am absolutely certain that my rotation matrix is correct (it cannot mathematically be wrong), then I know it has to be somewhere else.

anyway, code has been updated in the dl.

capn_midnight | Captain Midnight | deviantArt
ACM | SIGGRAPH | Generation5

##### Share on other sites
Me thinks you redistributed the same executable. I got your code to compile and the diamond isn''t experiencing ANY elongation as shown in the exe in the dl. Btw, i''m using the latest glut header, and i had to change the declaration of the "exit(int)" in it to match the one in stdlib.h to get the thing to compile.

*disables the normalization in rotate()*

Well, i''m correct in saying that you redistributed the same exec b/c i just disabled normalization as you had it b4, and the problem of elongation was back. So, normalization is your problem. ''Clean '' your build and rebuild and run it with normalization and w/o to see.

<>

##### Share on other sites
strangeness indeed, because I have normalized my vector, even passed in a unit vector, and I still get the problem.

if I replace my transforms (translate, rotate, etc) with the opengl transforms, then it works fine.

I have no clue what the hell is going on. The ONLY thing I use glut for is to create a window to which I can draw lines. I transform, projection, clip, and map them to my own viewport, and then draw the lines as they would appear in the viewport.

the ONLY thing I use opengl for is to draw lines from point A to point B. I figure out what those points should be in order to give the scene the proper perspective.

So, it MUST be something wrong with my code. The fact that using opengl transforms actually shows the proper tetrahedron is indication of this.

Oh well, doubt anyone else in the class has it working either, considering they always come to ME for help. Hope I didn''t stear them wrong.

capn_midnight | Captain Midnight | deviantArt
ACM | SIGGRAPH | Generation5

##### Share on other sites
Hmmm... Did you check again, b/c i got it working by building your source code. You must be somehow recompiling the old version of the code b/c the fixed version, the one where you''re normalizing within rotate() works fine; that fixed the problem. I could send you the exe that works, hold on i''ll email it to ya. Take away the normalization code and the problem is replicated exactly. So you fixed it, it works! I don''t understand why it''s not working for you...

##### Share on other sites
I''ve sent you an email with the exe gfxapi2 attached. I sent it to this acct: webspynner_99@yahoo.com

1. 1
Rutin
26
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 10
• 9
• 9
• 46
• 41
• ### Forum Statistics

• Total Topics
631751
• Total Posts
3002076
×