Author: Marcus Jaschen (mjaschen@gmail.com)
Inheritance: implements location\GeometryInterface
コード例 #1
0
 /**
  * @param Coordinate $point
  * @param Line $line
  *
  * @return float
  */
 public function getPerpendicularDistance(Coordinate $point, Line $line)
 {
     $ellipsoid = $point->getEllipsoid();
     $ellipsoidRadius = $ellipsoid->getArithmeticMeanRadius();
     $firstLinePointLat = $this->deg2radLatitude($line->getPoint1()->getLat());
     $firstLinePointLng = $this->deg2radLongitude($line->getPoint1()->getLng());
     $firstLinePointX = $ellipsoidRadius * cos($firstLinePointLng) * sin($firstLinePointLat);
     $firstLinePointY = $ellipsoidRadius * sin($firstLinePointLng) * sin($firstLinePointLat);
     $firstLinePointZ = $ellipsoidRadius * cos($firstLinePointLat);
     $secondLinePointLat = $this->deg2radLatitude($line->getPoint2()->getLat());
     $secondLinePointLng = $this->deg2radLongitude($line->getPoint2()->getLng());
     $secondLinePointX = $ellipsoidRadius * cos($secondLinePointLng) * sin($secondLinePointLat);
     $secondLinePointY = $ellipsoidRadius * sin($secondLinePointLng) * sin($secondLinePointLat);
     $secondLinePointZ = $ellipsoidRadius * cos($secondLinePointLat);
     $pointLat = $this->deg2radLatitude($point->getLat());
     $pointLng = $this->deg2radLongitude($point->getLng());
     $pointX = $ellipsoidRadius * cos($pointLng) * sin($pointLat);
     $pointY = $ellipsoidRadius * sin($pointLng) * sin($pointLat);
     $pointZ = $ellipsoidRadius * cos($pointLat);
     $normalizedX = $firstLinePointY * $secondLinePointZ - $firstLinePointZ * $secondLinePointY;
     $normalizedY = $firstLinePointZ * $secondLinePointX - $firstLinePointX * $secondLinePointZ;
     $normalizedZ = $firstLinePointX * $secondLinePointY - $firstLinePointY * $secondLinePointX;
     $length = sqrt($normalizedX * $normalizedX + $normalizedY * $normalizedY + $normalizedZ * $normalizedZ);
     $normalizedX /= $length;
     $normalizedY /= $length;
     $normalizedZ /= $length;
     $thetaPoint = $normalizedX * $pointX + $normalizedY * $pointY + $normalizedZ * $pointZ;
     $length = sqrt($pointX * $pointX + $pointY * $pointY + $pointZ * $pointZ);
     $thetaPoint /= $length;
     $distance = abs(M_PI / 2 - acos($thetaPoint));
     return $distance * $ellipsoidRadius;
 }
コード例 #2
0
ファイル: LineTest.php プロジェクト: jasonshaw/phpgeo
 public function testCalculateLength()
 {
     $point1 = new Coordinate(52.5, 13.5);
     $point2 = new Coordinate(64.09999999999999, -21.9);
     $line = new Line($point1, $point2);
     $this->assertEquals(2397867.8, $line->getLength(new Vincenty()), '', 0.01);
 }
コード例 #3
0
ファイル: xmaps-geo.php プロジェクト: horizon-institute/xmaps
 /**
  * Calculates the bearing between 2 geometries.
  *
  * @param Geometry $point_a The first point.
  * @param Geometry $point_b The second point.
  * @return float Bearing in degrees.
  */
 public static function bearing($point_a, $point_b)
 {
     return self::apply($point_a, $point_b, function ($coor_a, $coor_b) {
         $line = new Line($coor_a, $coor_b);
         return $line->getBearing(new BearingEllipsoidal());
     });
 }
コード例 #4
0
ファイル: LineTest.php プロジェクト: horizon-institute/xmaps
 public function testIfGetBearingReversedWorksAsExpected()
 {
     $point1 = new Coordinate(0, 0);
     $point2 = new Coordinate(0, 10);
     $line = new Line($point2, $point1);
     $bearingCalculator = new BearingEllipsoidal();
     $this->assertEquals(270.0, $line->getBearing($bearingCalculator));
 }