calculate the 3D angle of an object (knowing its orientation)

299 Views Asked by At

I'm not a mathematician, but I'm trying to solve a (javascript) code problem. What I need, if I express correctly, is a formula to get the angles of a 3D object,..knowing its rotation ?

Well, maybe it would be easier to understand with pictures :

enter image description here

I'm working on a javascript animation which consists of a fake 3D cylinder rotating on its Z axis. I've done it within After Effects but whatever, this is a code/maths question.

I have a "Zrot" variable driving some shapes changes, which "simulates" a rotating 3D object on one axis - so this is not 3D but 2D.

Now I need to be able to rotate my layer, but when doing it, the angle looks weird.

enter image description here

What I'm searching for is a formula to calculate a "zrot" offset based on the layer rotation.

var frontRot = 78;
var zRot = -33;

var zRotOffset = frontRot * ...
zRot = zRot + zRotOffset;

enter image description here

If you know some 3D softwares, it is kind of like local rotation VS global rotation.

enter image description here

Can anyone help ? I need something that could be coded in javascript.

Thanks !