Original Post
Hey all, Ok, so I'm working on 3D rotations. Thanks to various online resources, I was able to understand these basic formulas: x = cos(phi)*sin(theta) y = sin(phi)*sin(theta) z = cos(theta) And then you times them by rho to scale of course. Anyways, I'm trying to take it a little further. I'm trying to do some rotations without phi and theta - and then calculate the phi and theta again. This is for rotating around the Y axis. Basically - I'm stuck when it comes to calculating phi. Using the above equations, I naturally got: phi = acos( x / sin(theta) ) Providing I'm not making some elementary mistake when reformatting the equation (wouldn't be the first time) that SHOULD calculate phi. HOWEVER, when I plug that into my c++ code - it, well... doesn't work. And I plug it in before I times it by Rho - so that's not the problem. Looking at it again, I thought that it obviously wouldn't work as it would only work well when sin(theta) was ~1 or ~-1. If its a small number, then its going to divide x multiple times - and thus the value would be greater than 1 (or less than -1) and thus acos wouldn't work. If sin(theta) returns 0 - I get a divide by zero error... So - how do I calculate this angle? Is there another equation - if so please describe in detail or provide good resource on the subject. Thank you, Ryan