I'm moving a point in 3D. Just to be clear from the beginning, according to Matlab documentation that "azimuth and elevation are angular displacements in radians. azimuth is the counterclockwise angle in the x-y plane measured from the positive x-axis. elevation is the elevation angle from the x-y plane. r is the distance from the origin to a point." I will call azimuth angle as Theta and elevation angle as Phi. Now, I want to make sure that Theta and Phi angles in their proper range(in radians). According to this book "3D Math Primer for Graphics and Game Development" states the following
- If p < −90, then add 360 to p until p ≥ −90.
- If p > 270, then subtract 360 from p until p ≤ 270.
- If p > 90, then add 180 to h and set p = 180 − p.
- If h ≤ −180, then add 360 to h until h > −180.
- If h > 180, then subtract 360 from h until h ≤ 180.
where p is Phi and h is Theta in my case. The book uses the left-hand rule. My implementation code in Matlab is
if Theta > pi
Theta = Theta - 2*pi;
end
if Theta <= -pi
Theta = Theta + 2*pi;
end
if Phi < -pi/2
Phi = Phi + 2*pi;
end
if Phi > (3*pi)/2
Phi = Phi - 2*pi;
end
if Phi > pi/2 <-------- here the problem
Theta = Theta + pi;
Phi = pi - Phi;
end
My problem is that once Phi = 1.6 (in radians) my point can't go further and sticks in its position with stepping back and forth one step.