public static function interpolate($from, $to, $fraction) {
        // http://en.wikipedia.org/wiki/Slerp
        $fromLat = deg2rad($from['lat']);
        $fromLng = deg2rad($from['lng']);
        $toLat = deg2rad($to['lat']);
        $toLng = deg2rad($to['lng']);
        $cosFromLat = cos($fromLat);
        $cosToLat = cos($toLat);

        // Computes Spherical interpolation coefficients.
        $angle = self::computeAngleBetween($from, $to);
        $sinAngle = sin($angle);
        if ($sinAngle < 1E-6) {
            return $from;
        }
        $a = sin((1 - $fraction) * $angle) / $sinAngle;
        $b = sin($fraction * $angle) / $sinAngle;

        // Converts from polar to vector and interpolate.
        $x = $a * $cosFromLat * cos($fromLng) + $b * $cosToLat * cos($toLng);
        $y = $a * $cosFromLat * sin($fromLng) + $b * $cosToLat * sin($toLng);
        $z = $a * sin($fromLat) + $b * sin($toLat);

        // Converts interpolated vector back to polar.
        $lat = atan2($z, sqrt($x * $x + $y * $y));
        $lng = atan2($y, $x);
        return [ 'lat' => rad2deg($lat), 'lng' => rad2deg($lng)];
    }
public static function interpolate($from, $to, $fraction) {
        // http://en.wikipedia.org/wiki/Slerp
        $fromLat = deg2rad($from['lat']);
        $fromLng = deg2rad($from['lng']);
        $toLat = deg2rad($to['lat']);
        $toLng = deg2rad($to['lng']);
        $cosFromLat = cos($fromLat);
        $cosToLat = cos($toLat);

        // Computes Spherical interpolation coefficients.
        $angle = self::computeAngleBetween($from, $to);
        $sinAngle = sin($angle);
        if ($sinAngle < 1E-6) {
            return $from;
        }
        $a = sin((1 - $fraction) * $angle) / $sinAngle;
        $b = sin($fraction * $angle) / $sinAngle;

        // Converts from polar to vector and interpolate.
        $x = $a * $cosFromLat * cos($fromLng) + $b * $cosToLat * cos($toLng);
        $y = $a * $cosFromLat * sin($fromLng) + $b * $cosToLat * sin($toLng);
        $z = $a * sin($fromLat) + $b * sin($toLat);

        // Converts interpolated vector back to polar.
        $lat = atan2($z, sqrt($x * $x + $y * $y));
        $lng = atan2($y, $x);
        return [ 'lat' => rad2deg($lat), 'lng' => rad2deg($lng)];
    }
public static function interpolate ( $ from , $ to , $ fraction ) { // http://en.wikipedia.org/wiki/Slerp $ fromLat = deg2rad ( $ from [ 'lat' ] ) ; $ fromLng = deg2rad ( $ from [ 'lng' ] ) ; $ toLat = deg2rad ( $ to [ 'lat' ] ) ; $ toLng = deg2rad ( $ to [ 'lng' ] ) ; $ cosFromLat = cos ( $ fromLat ) ; $ cosToLat = cos ( $ toLat ) ; // Computes Spherical interpolation coefficients. $ angle = self :: computeAngleBetween ( $ from , $ to ) ; $ sinAngle = sin ( $ angle ) ; if ( $ sinAngle < 1E-6 ) { return $ from ; } $ a = sin ( ( 1 - $ fraction ) * $ angle ) / $ sinAngle ; $ b = sin ( $ fraction * $ angle ) / $ sinAngle ; // Converts from polar to vector and interpolate. $ x = $ a * $ cosFromLat * cos ( $ fromLng ) + $ b * $ cosToLat * cos ( $ toLng ) ; $ y = $ a * $ cosFromLat * sin ( $ fromLng ) + $ b * $ cosToLat * sin ( $ toLng ) ; $ z = $ a * sin ( $ fromLat ) + $ b * sin ( $ toLat ) ; // Converts interpolated vector back to polar. $ lat = atan2 ( $ z , sqrt ( $ x * $ x + $ y * $ y ) ) ; $ lng = atan2 ( $ y , $ x ) ; return [ 'lat' => rad2deg ( $ lat ) , 'lng' => rad2deg ( $ lng ) ] ; }
Returns the LatLng which lies the given fraction of the way between the
origin LatLng and the destination LatLng.
@param from     The LatLng from which to start.
@param to       The LatLng toward which to travel.
@param fraction A fraction of the distance to travel.
@return The interpolated LatLng.
Returns the LatLng which lies the given fraction of the way between the origin LatLng and the destination LatLng .