Esempio n. 1
0
 /**
  * Returns (signed) distance from ‘this’ point to great circle defined by start-point and end-point.
  *
  * @param   LatLon $pathStart - Start point of great circle path.
  * @param   LatLon $pathEnd - End point of great circle path.
  * @param   number $radius [radius=6371e3] - (Mean) radius of earth (defaults to radius in metres).
  * @returns number Distance to great circle (-ve if to left, +ve if to right of path).
  *
  * @example
  *   $pCurrent = new LatLon(53.2611, -0.7972);
  *   $p1 = new LatLon(53.3206, -1.7297); $p2 = new LatLon(53.1887, 0.1334);
  *   $d = $pCurrent->crossTrackDistanceTo($p1, $p2);  // round($d, 1): -307.5
  */
 public function crossTrackDistanceTo(LatLon $pathStart, LatLon $pathEnd, $radius = null)
 {
     $radius = $radius === null ? static::RADIUS : (double) $radius;
     $δ13 = $pathStart->distanceTo($this, $radius) / $radius;
     $θ13 = deg2rad($pathStart->bearingTo($this));
     $θ12 = deg2rad($pathStart->bearingTo($pathEnd));
     $dxt = asin(sin($δ13) * sin($θ13 - $θ12)) * $radius;
     return $dxt;
 }