/**
  * @param LatLon $min
  * @param LatLon $max
  *
  * @throws GeocodingException
  */
 public function __construct($min, $max)
 {
     if (!$min instanceof LatLon) {
         throw new GeocodingException('Minimum value is not a LatLon object.');
     }
     if (!$max instanceof LatLon) {
         throw new GeocodingException('Maximum value is not a LatLon object.');
     }
     if (!($min->get_lat() <= $max->get_lat())) {
         throw new GeocodingException('Minimum latitude is larger than maximum latitude.');
     }
     if (!($min->get_lon() <= $max->get_lon())) {
         throw new GeocodingException('Minimum longitude is larger than maximum longitude.');
     }
     $this->min = $min;
     $this->max = $max;
 }
Esempio n. 2
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;
 }