title: Converting from Cartesian to Spherical matlab?
body: <p>I'm getting confused with the variety of names for angles in Spherical Coordinates. 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." </p>
  
  <p>Ok, I will call azimuth angle as Theta and elevation angle as Phi. Now, I want to build a function that convert Cartesian to Spherical. This is what I did</p>
  
  <pre><code>function [y] = my_car2sph(x)
      d = sqrt(x(1)^2 + x(2)^2 + x(3)^2);
    Phi = acos(x(3)/d);   % elevation angle 
  Theta = atan2(x(2),x(1)); % azimuth
  y = [d; Theta; Phi];
  </code></pre>
  
  <p>Now, the output of this function </p>
  
  <pre><code>&gt;&gt; my_car2sph([1; 1; 1])
  
  ans =
  
      1.7321   &lt;--- d
      0.7854   &lt;--- Theta (azimuth)
      0.9553   &lt;--- Phi (elevation)
  </code></pre>
  
  <p>Now, if I use the Matlab's function, this is what I'm getting</p>
  
  <pre><code>&gt;&gt; [azimuth,elevation,r] = cart2sph(1,1,1)
  
  azimuth =
  
      0.7854
  
  
  elevation =
  
      0.6155
  
  
  r =
  
      1.7321
  
  &gt;&gt; 
  </code></pre>
  
  <p>Why the elevation angle (Phi) is not the same?</p>