1
votes

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

  1. If p < −90, then add 360 to p until p ≥ −90.
  2. If p > 270, then subtract 360 from p until p ≤ 270.
  3. If p > 90, then add 180 to h and set p = 180 − p.
  4. If h ≤ −180, then add 360 to h until h > −180.
  5. 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.

1
It's not obvious where the problem is from the code supplied so far. I presume you are going around in some sort of loop - how have you set that up? What do you mean by "stepping back and forth" - between which values?nkjt
@nkjt, both angles increment by 1 radians. Once the Phi reaches 1.6, everything goes wrong. My question is is my code correct for the angle Phi? I'm sure about the Theta because I've tested in 2D and it is working fine.CroCo

1 Answers

1
votes

I've solved the problem by modifying the code as following

if Phi > pi
    Phi = 0;
end
if Phi < 0
    Phi = pi;
end