You are here

function earth_xyz in Location 7.3

Same name and namespace in other branches
  1. 5.3 earth.inc \earth_xyz()
  2. 5 earth.inc \earth_xyz()
  3. 6.3 earth.inc \earth_xyz()
  4. 7.5 earth.inc \earth_xyz()
  5. 7.4 earth.inc \earth_xyz()

Earth xyz.

1 call to earth_xyz()
LocationEarthTest::testXYZ in tests/earth.test

File

./earth.inc, line 82
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.
  $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,
  );
}