public function testSetSemiMinorAxis() { $referenceEllipsoidObject = new ReferenceEllipsoid(ReferenceEllipsoid::WGS_1984); $referenceEllipsoidObject->setSemiMinorAxis(6356752.5); $semiMinorAxis = $referenceEllipsoidObject->getSemiMinorAxis(); $this->assertEquals(6356752.5, $semiMinorAxis, '', 1.0E-7); }
/** * Get the distance between two Latitude/Longitude objects using the Vincenty formula * * The Vincenty Formula calculates the distance to your destination point based on the specified ellipsoid * * @param LatLong $endPoint The destination point * @param ReferenceEllipsoid $ellipsoid * @return Distance The great circle distance between this Lat/Long and the $endpoint Lat/Long * @throws Exception */ public function getDistanceVincenty(LatLong $endPoint, ReferenceEllipsoid $ellipsoid = null) { if (is_null($ellipsoid)) { $ellipsoid = new ReferenceEllipsoid(ReferenceEllipsoid::WGS_84); } $semiMinor = $ellipsoid->getSemiMinorAxis(); $flattening = $ellipsoid->getFlattening(); $lDifference = $this->longitude->getValue(Angle::RADIANS) - $endPoint->getLongitude()->getValue(Angle::RADIANS); $U1Value = atan((1 - $flattening) * tan($endPoint->getLatitude()->getValue(Angle::RADIANS))); $U2Value = atan((1 - $flattening) * tan($this->latitude->getValue(Angle::RADIANS))); $sinU1 = sin($U1Value); $cosU1 = cos($U1Value); $sinU2 = sin($U2Value); $cosU2 = cos($U2Value); $lambda = $lDifference; $lambdaP = 2 * M_PI; $iterLimit = 20; while (abs($lambda - $lambdaP) > 1.0E-12 && $iterLimit > 0) { $sinLambda = sin($lambda); $cosLambda = cos($lambda); $sinSigma = sqrt($cosU2 * $sinLambda * ($cosU2 * $sinLambda) + ($cosU1 * $sinU2 - $sinU1 * $cosU2 * $cosLambda) * ($cosU1 * $sinU2 - $sinU1 * $cosU2 * $cosLambda)); if ($sinSigma == 0.0) { // co-incident points return new Distance(); } $cosSigma = $sinU1 * $sinU2 + $cosU1 * $cosU2 * $cosLambda; $sigma = atan2($sinSigma, $cosSigma); $alpha = asin($cosU1 * $cosU2 * $sinLambda / $sinSigma); $cosSqAlpha = cos($alpha) * cos($alpha); $cos2SigmaM = $cosSigma - 2 * $sinU1 * $sinU2 / $cosSqAlpha; $cValue = $flattening / 16 * $cosSqAlpha * (4 + $flattening * (4 - 3 * $cosSqAlpha)); $lambdaP = $lambda; $lambda = $lDifference + (1 - $cValue) * $flattening * sin($alpha) * ($sigma + $cValue * $sinSigma * ($cos2SigmaM + $cValue * $cosSigma * (-1 + 2 * $cos2SigmaM * $cos2SigmaM))); } $uSq = $cosSqAlpha * $ellipsoid->getSecondEccentricitySquared(); $aValue = 1 + $uSq / 16384 * (4096 + $uSq * (-768 + $uSq * (320 - 175 * $uSq))); $bValue = $uSq / 1024 * (256 + $uSq * (-128 + $uSq * (74 - 47 * $uSq))); $deltaSigma = $bValue * $sinSigma * ($cos2SigmaM + $bValue / 4 * ($cosSigma * (-1 + 2 * $cos2SigmaM * $cos2SigmaM) - $bValue / 6 * $cos2SigmaM * (-3 + 4 * $sinSigma * $sinSigma) * (-3 + 4 * $cos2SigmaM * $cos2SigmaM))); return new Distance($semiMinor * $aValue * ($sigma - $deltaSigma)); }