title: 3D coordinates on a sphere to Latitude and Longitude
body: <p>I've got the following information:</p>
  
  <p>There exists a sphere with origin (0,0,0) and radius R.
  After doing a ray-sphere intersection I know a point (XYZ) in 3D space that is on the sphere (the exact position in 3D space where the line pierces the sphere hull).</p>
  
  <p>For my program I'd like to calculate the Latitude and Longitude of the XYZ point on the sphere, but I can't think (or Google) up a way to do this easily.</p>
  
  <p>So in short, the function that I'm trying to write is this:</p>
  
  <pre><code>public static LatLon FromVector3(Vector3 position, float sphereRadius)
  {
      return Latitude and Longitude
  }
  </code></pre>
  
  <p>Does anybody know how to do this? As a reference this Wiki SVG file might be helpful:</p>
  
  <p><img src="https://i.stack.imgur.com/63tUo.png" alt="Geographic coordinates"></p>
  
  <p>Update: </p>
  
  <p>Thanks for all the helpful answers, so in the end I went with this code:</p>
  
  <pre><code> public static LatLon FromVector3(Vector3 position, float sphereRadius)
      {
          float lat = (float)Math.Acos(position.Y / sphereRadius); //theta
          float lon = (float)Math.Atan(position.X / position.Z); //phi
          return new LatLon(lat, lon);
      }
  </code></pre>
  
  <p>Now I've got to think of which answer helped me the most to accept :P.</p>