Original Post
Hello world, I'm currently developing my first 3D-game using DirectX. Unfortunately I have stumbled upon a seemingly simple mathematical problem that I have not been able to solve properly so far. Note: This is a left-handed coordinate system (X to the right, Y upwards and Z "into" the monitor) I have a 3D-Vector with its X, Y and Z components. Now I would like to calculate the horizontal and vertical angles of the resulting “arrow”. In other words I need to determine the yaw and pitch of a vector. Additionally I need to reverse this operation: Take two angles and a length and build a 3D-Vector from it. This is what I have done so far: Vector to Angles: Yaw = Atan2(Z, X) Pitch = Atan2(Z, Sqrt(X² + Y²)) Length = Sqrt(X² + Y² + Z²) Angles to Vector: X = Cos(Yaw) * Cos(Pitch) * Length Y = Sin(Pitch) * Length Z = Sin(Yaw) * Cos(Pitch) * Length Sqrt = square root Atan = Inverse tangent At first these calculations seemed to be correct. However, after implementing them in the game, I noticed that the Vector to Angles calculation wasn’t giving me the expected results. Can anybody tell me what I have done wrong and how to fix it? Regards, Bastian [Edited by - transwarp on August 23, 2006 4:16:33 PM]