How to calculate angles of an object relative to gravity based on rotation

725 Views Asked by At

Considering a cube which is along $x,y,z$ axes, $y$ being parallel with gravity, at its "resting" point, $x$ and $z$ will be running at 90 degrees relative to gravity, and $y$ will be $0$ (parallel).

enter image description here

If I rotate this cube 30 degrees around the $z$ axis, those angles will now be: $x: 60, y: 30, z: 90$. Simple calculation...

enter image description here

My question is, if I then perform another rotation through a different axis, how do I now calculate these angles? My basic trigonometry is ok but I don't even know where to start with 3D geometry.

enter image description here

1

There are 1 best solutions below

4
On BEST ANSWER

First, let's vectorize our points: x = (1, 0, 0); y = (0, 1, 0); z = (0, 0, 1); The force of gravity is (0, 1, 0) = g; As @Aretino points out, we can use the 3D rotation matrices. So, if we want to rotate a degrees around the x-axis, b degrees around the y-axis, and c degrees around the z-axis, we can do the following: x * Rx(a) = x' //note here x' is not a derivative but the new value of the vector x. x' * Ry(b) = x'' x'' * Rz(c) = x''' Now we can take the dot product of x''' * g = |x'''| * |g| * cos(theta). Divide the dot product by the product of both vector's lengths. Then take the arccos of that and you will get the angle in-between the two vectors. You can repeat this process for the y and z vectors. Hope this helps.