Jump to content
  • Advertisement

Archived

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

PixolMaster

Rotation/Angle Calculation

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I have a class that needs to take the following information: - Starting Point - Length - Rotation along X, Y and Z Axis and calculate the point at the end of the line. I remember learning how to do something similar 2D, but I can''t recall how I did it. I''ve been fighting with the problem all afternoon (in my head as well as in code). Any help would be incredibly, greatly, wonderfully appreciated. Thanks ahead of time. - Alex Broadwin - Domini Noctum Games - My Journal - The All-Knowing One

Share this post


Link to post
Share on other sites
Advertisement
Well, using matrices, you could rotate a matrix by X, then Y, then Z (or in another order). Which would give you a matrix that you can just multiply by the length (which is a
x length vector in some specific direction) ...

Or you could use the much more 'usefull' quaterions, which for me was easier to get pointing where i wanted them. (simply axis, and angle around axis). But this depends on what exactly you were doing...

Quick way I'd try it (dunno how your angles come together, but watch out for gimbal lock if you do it like this) Saying that length is in X-axis, your starting vector would be:
V.X = Length
V.Y = 0
V.Z = 0

Then Rotate by X,Y and Z angles one after the other

(Vector O is old vector, Vector V is new vector)
Rotate around X axis by Angle A
V.X = O.X
V.Y = Cos(A)*O.Y - Sin(A)*O.Z
V.Z = Cos(A)*O.Z + Sin(A)*O.Y

Rotate around Y axis by Angle A
(remember that O should now be the V from the previous step)
V.X = Cos(A)*O.X - Sin(A)*O.Z
V.Y = O.Z
V.Z = Cos(A)*O.Z + Sin(A)*O.X

Rotate around Z axis by Angle A
(Again O = old V)
V.X = Cos(A)*O.X - Sin(A)*O.Y
V.Y = Cos(A)*O.Y + Sin(A)*O.X
V.Z = O.Z

Finally, add the starting Point vector (S)
V.X = O.X + S.X
V.Y = O.Y + S.Y
V.Z = O.Z + S.Z

[edited by - PyroSA on February 27, 2004 2:41:30 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!