Sign in to follow this  

Trig in 3D Rotations?

This topic is 4821 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

Say I was going to rotate a 3D field...like a fighting arena, on its y axis. I know that the matrix for y rotations involves trigonomic functions...but for that to happen, you need a right triangle and a reference angle. My question is: if it's not clearly a triangle...and it's something like a character, or an entire level....how you do determine its reference angle, and the size and location of the triangle?

Share this post


Link to post
Share on other sites
Define everything by points, say the midpoint of a character, the middle of a level etc. Once you have everything as a point, you can find the angles between them (3 points defines a triangle). I usually use the origin (0,0) as the reference point, so the other 2 are just the objects:


A(-6,1)
O(0,0)

B(-3,3)

Need A-O-B. Law of Cosines:
AB2 = AO2 + BO2 - 2 * AO * BO * cos(A-O-B)

Where AO = sqr(62 + 12)
BO = sqr(32 + 32)
AB = sqr(32 + 22)
(distance formula to find distance between points)
(don't forget this still works with 3 dimensions: dist=sqr(x2+y2+z2)!

Therefore,
cos(A-O-B) = AB2 -AO2 - BO2/-2 * AO * BO

And voila! You have your angle!
...I hate trig.

If I got that wrong, someone please correct me. It's been awhile! [lol]

Share this post


Link to post
Share on other sites
The relation to a right triangle can be seen by rotating the coordinate axes, i.e. (1,0,0), (0,1,0) and (0,0,1). What happens to (1,0,0) tells you what the first column should be assuming it is a matrix times a vector. So a rotation by t around the z axis take (1,0,0) to (cos(t),sin(t)) and (0,1,0) to (-sin(t),cos(t)).

Share this post


Link to post
Share on other sites

This topic is 4821 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this