You are here

function getlocations_earth_xyz in Get Locations 7

Same name and namespace in other branches
  1. 7.2 getlocations.module \getlocations_earth_xyz()

File

./getlocations.module, line 6707
getlocations.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function getlocations_earth_xyz($longitude, $latitude, $height = 0) {

  // Convert longitude and latitude to earth-centered earth-fixed coordinates.
  // X axis is 0 long, 0 lat; Y axis is 90 deg E; Z axis is north pole.
  $long = deg2rad($longitude);
  $lat = deg2rad($latitude);
  $coslong = cos($long);
  $coslat = cos($lat);
  $sinlong = sin($long);
  $sinlat = sin($lat);
  $radius = GETLOCATIONS_EARTH_RADIUS_SEMIMAJOR / sqrt(1 - GETLOCATIONS_EARTH_ECCENTRICITY_SQ * $sinlat * $sinlat);
  $x = ($radius + $height) * $coslat * $coslong;
  $y = ($radius + $height) * $coslat * $sinlong;
  $z = ($radius * (1 - GETLOCATIONS_EARTH_ECCENTRICITY_SQ) + $height) * $sinlat;
  return array(
    $x,
    $y,
    $z,
  );
}