title: direction vector between two geolocations
body: <p>I'm building an Android AR-App (yes, another one), but I'm more interested in understanding the math behind it than using frameworks (knowing <a href="https://stackoverflow.com/questions/6494069/ios-augmented-reality-with-compass-and-location">this</a> and <a href="https://code.google.com/p/android-augment-reality-framework/wiki/HowItWorks" rel="nofollow noreferrer">this</a>). </p>
  
  <p>Given to locations (lat1,long1) and (lat2,long2) I'm searching for the direction vector (x,y,z) from Location1 to Location2.</p>
  
  <p>Using this <a href="http://www.yourhomenow.com/house/haversine.html" rel="nofollow noreferrer">Site</a> I can calculate the distance and (inital) bearing between Location1 and Location2.</p>
  
  <p>Now I develop two approaches (neglecting altitude)</p>
  
  <pre><code>x = distHaversine(lat1,long1,lat1,long2);
  z = distHaversine(lat1,long1,lat2,long1);
  if (lat1 &lt; lat2)
    z *= -1;
  if (long1 &gt; long2)
    x *= -1;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>distance = distHaversine(lat1,long1,lat2,long2);
  angle = 90.0-bearing(lat1,long1,lat2,long2);
  x = cos(angle)*distance;
  z = sin(angle)*distance;
  </code></pre>
  
  <p>but now I'm stucked and irritated... shouldnt' the result be the same?
  Where do I find my error in reasoning? How do I calcuate the direction vector (or rather: Why didnt work my second approach?)?</p>
  
  <p>Thanks for your help</p>