# Trig in 3D Rotations?

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

## 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 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 * BOAnd voila! You have your angle!...I hate trig.

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

##### 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)).

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 22
• 17
• 46