public function get_distance_to(lat_lng $other) { $x = $this->sin_lat() * $other->sin_lat() + $this->cos_lat() * $other->cos_lat() * cos($this->lng(true) - $other->lng(true)); if (!is_nan($acos = acos($x))) { return $acos * 6371; } else { return 0; } }
private static function __convert(lat_lng $point, $source_ellipse, $target_ellipse, $transform) { $lat = $point->lat(true); $lon = $point->lng(true); $a = $source_ellipse['a']; $b = $source_ellipse['b']; $sinPhi = sin($lat); $cosPhi = cos($lat); $sinLambda = sin($lon); $cosLambda = cos($lon); $H = 0; // for the moment $eSq = ($a * $a - $b * $b) / ($a * $a); $nu = $a / sqrt(1 - $eSq * $sinPhi * $sinPhi); $x1 = ($nu + $H) * $cosPhi * $cosLambda; $y1 = ($nu + $H) * $cosPhi * $sinLambda; $z1 = ((1 - $eSq) * $nu + $H) * $sinPhi; $tx = $transform['tx']; $ty = $transform['ty']; $tz = $transform['tz']; $rx = deg2rad($transform['rx'] / 3600); $ry = deg2rad($transform['ry'] / 3600); $rz = deg2rad($transform['rz'] / 3600); $s1 = $transform['s'] / 1000000 + 1; // normalise ppm to (s+1) $x2 = $tx + $x1 * $s1 - $y1 * $rz + $z1 * $ry; $y2 = $ty + $x1 * $rz + $y1 * $s1 - $z1 * $rx; $z2 = $tz - $x1 * $ry + $y1 * $rx + $z1 * $s1; $a = $target_ellipse['a']; $b = $target_ellipse['b']; $precision = 1 / 3600000000000.0; $eSq = ($a * $a - $b * $b) / ($a * $a); $p = sqrt($x2 * $x2 + $y2 * $y2); $phi = atan2($z2, $p * (1 - $eSq)); $phiP = 2 * M_PI; $iterations = 0; while (abs($phi - $phiP) > $precision && $iterations < 10000000) { $nu = $a / sqrt(1 - $eSq * sin($phi) * sin($phi)); $phiP = $phi; $phi = atan2($z2 + $eSq * $nu * sin($phi), $p); $iterations++; } $lambda = atan2($y2, $x2); $H = $p / cos($phi) - $nu; return new lat_lng(rad2deg($phi), rad2deg($lambda), $H); }
public function contains(lat_lng $lat_lng) { return $this->north_east->lat() > $lat_lng->lat() && $this->south_west->lat() < $lat_lng->lat() && $this->north_east->lng() > $lat_lng->lng() && $this->south_west->lng() < $lat_lng->lng(); }