View Full Version : Direction Vector to Euler Angle

bobGL

01-11-2010, 06:55 PM

I have a direction vector calculated like this:

dir = pos - tar;

And I would like to get the XYZ rotation in angle of this direction vector, assuming that the up vector is 0,0,1 is it possible? If yes how...

I tried a few things but always end up with a gimbal lock... please help!

TIA

Dark Photon

01-12-2010, 04:26 AM

I have a direction vector calculated like this:

dir = pos - tar;

And I would like to get the XYZ rotation in angle of this direction vector, assuming that the up vector is 0,0,1 is it possible? If yes how...

I tried a few things but always end up with a gimbal lock... please help!

So, what do you expect to happen when your direction vector gets very close to your up vector? It seems to me that you may be causing this anomaly by your preconditions of fixing your up vector while allowing your direction vector to float.

If you're just trying to construct a viewing transform, don't do it that way. Just use gluLookAt, or code up the equivalent yourself. See this (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=270073#Post2700 73) for more details. Look ma, no euler angles!

But yes, if you really want to do the euler angles thing, it's of course possible. Pick up a graphics book like Foley and van Dam, IIRC. You rotate the vector into coordinate planes and note the angles.

bobGL

01-12-2010, 07:07 PM

All I want is to get the X and Z rotation angle of the direction vector in degree...

Anybody got a snippet that does that?

TIA

Cheers,

Normalize vector V to get T with coordinates (q,r,s). I can tell you how to rotate the X unit vector (1,0,0) to T. First rotate XU about the Y axis by the angle -arcsin(s). Call this intermediate vector P. Then rotate P around the Z axis by the angle atan2(r,q). That's all there is to it. You can use glRotates to do this graphically, or rotation matrices to do it mathematically (i.e. matrix multiplication). Does that answer your question?

bobGL

01-13-2010, 05:34 PM

Hummmm yes and no (Im a bit confused)... can you please write me a snippet that does that?

The only thing I need is to get the angle X and Z in degree...

ps: I forgot to post above that yes after I get d I normalize it...

bruuntje

01-26-2010, 12:56 AM

Hi,

I have the same question, I have a vector from the origin to a point. From (0,0,0) to (10,20,18).

I draw an arrow in the origin pointing like the x-axis. now I want to move the to the endpoint of my vector and rotate him so that it's pointing the same way as the vector (gltranslate and glrotate).

How can I calculate the angles needed?

It would be great to know!

Dark Photon

01-26-2010, 06:14 AM

I have a vector from ... (0,0,0) to (10,20,18)....now I want to move the to the endpoint of my vector and rotate him so that it's pointing the same way as the vector (gltranslate and glrotate).

How can I calculate the angles needed?

Normalize your vector (10,20,18). Now, pick an axis vector (e.g. 0,0,1), dot product to get the angle to that axis, subtract off that component. Now, repeat for another axis.

I have the same question, I have a vector from the origin to a point. From (0,0,0) to (10,20,18).

I draw an arrow in the origin pointing like the x-axis. now I want to move the to the endpoint of my vector and rotate him so that it's pointing the same way as the vector (gltranslate and glrotate). Sounds like you guys want someone to do your homework for you? Where are you with your graphics? For starters, can you display a unit vector pointing down the X axis? If so, post a screen capture and your code. Show us that you have done some work and are willing to do more. You'll get more help from me that way.

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.