You are here

function earth_xyz in Location 5.3

Same name and namespace in other branches
  1. 5 earth.inc \earth_xyz()
  2. 6.3 earth.inc \earth_xyz()
  3. 7.5 earth.inc \earth_xyz()
  4. 7.3 earth.inc \earth_xyz()
  5. 7.4 earth.inc \earth_xyz()
1 call to earth_xyz()
LocationEarthTest::testXYZ in tests/earth.test

File

./earth.inc, line 63
Trigonometry for calculating geographical distances. All function arguments and return values measure distances in metres and angles in degrees. The ellipsoid model is from the WGS-84 datum. Ka-Ping Yee, 2003-08-11

Code

function 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.

  //global $earth_radius_semimajor, $earth_eccentricity_sq;
  $long = deg2rad($longitude);
  $lat = deg2rad($latitude);
  $coslong = cos($long);
  $coslat = cos($lat);
  $sinlong = sin($long);
  $sinlat = sin($lat);
  $radius = earth_radius_semimajor() / sqrt(1 - earth_eccentricity_sq() * $sinlat * $sinlat);
  $x = ($radius + $height) * $coslat * $coslong;
  $y = ($radius + $height) * $coslat * $sinlong;
  $z = ($radius * (1 - earth_eccentricity_sq()) + $height) * $sinlat;
  return array(
    $x,
    $y,
    $z,
  );
}