Home > Software engineering >  Calculating 3D rotation angle to set one coordinate to 0
Calculating 3D rotation angle to set one coordinate to 0

Time:09-30

I am trying to solve a problem, but I am not sure how, or if there is even a solution.

I have a vector in 3D space with coordinates x, y, z. I want to rotate this vector around the z-axis such that the y coordinate becomes 0. I know from trigonometry the following for rotation around the z-axis:

|cos θ   −sin θ   0| |x|   |x cos θ − y sin θ|   |x'|
|sin θ    cos θ   0| |y| = |x sin θ   y cos θ| = |y'|
|  0       0      1| |z|   |        z        |   |z'|

For my problem I know that z' = z (rotation around an axis does not change that axis' coordinate). I want find a θ for y' = 0.

I got as far as this:

y' = x sin θ   y cos θ = 0
x sin θ = y cos θ
sin θ / cos θ = y / x

My math is rusty and I don't know how to go from here or if this is even possible. Is this solvable, and if so, how?

CodePudding user response:

You can find θ angle using arctangent function (perhaps math.atan2 in your language)

θ = arctan2(y, x)
  • Related