How to get angle of rotation in Y axis for an Offset

289 Views Asked by At

I am trying to get the angle of rotation for an offset rotated in the Y-axis. Say When an offset(400, 0, 0) is rotated in Y-axis, I need to find the right angle so that the new offset x intersect with pre-known x-axis value (in my case it is 350) enter image description here

1

There are 1 best solutions below

0
MBo On

Let initial coordinates were (x0, z0), new coordinates are (x1, z1). Using formulas for rotation about axis OY by (unknown yet) angle fi

x1 = x0 * cos(fi) - z0 * sin(fi)
z1 = x0 * sin(fi) + z0 * cos(fi)

We can find (solving this system of linear equations) that

sin(fi) = (z1 * x0 - z0 * x1) / (x0*x0 + z0*z0)
cos(fi) = (x1 * x0 + z0 * z1) / (x0*x0 + z0*z0)

and get rotation angle

fi = math.atan2(z1 * x0 - z0 * x1, x1 * x0 + z0 * z1)