Geografische functie werkt incorrect

Status
Niet open voor verdere reacties.

bn2vs

Terugkerende gebruiker
Lid geworden
18 aug 2007
Berichten
1.705
Ik heb een functie geschreven om een eindpunt te vinden als je een startpunt, richting en afstand opgeeft. Er zit blijkbaar ergens een fout in, want ik krijg verkeerde waarden terug. Iemand een idee wat er mis gaat?

PHP:
        /**
         * Finds a destination given a starting location, bearing and distance.
         * 
         * @param array $startingCoordinates The starting coordinates, as non-directional floats in an array with lat and lon keys.
         * @param float $bearing The initial bearing in degrees.
         * @param float $distance The distance to travel in km.
         * 
         * @return array The desitination coordinates, as non-directional floats in an array with lat and lon keys.
         */
        public static function findDestination( array $startingCoordinates, $bearing, $distance ) {
                $startingCoordinates['lat'] = (float)$startingCoordinates['lat'];
                $startingCoordinates['lon'] = (float)$startingCoordinates['lon'];
                $angularDistance = $distance / Maps_EARTH_RADIUS;
                $lat = asin(
                                sin( $startingCoordinates['lat'] ) * cos( $angularDistance ) +
                                cos( $startingCoordinates['lat'] ) * sin( $angularDistance ) * cos( $bearing )
                );
                return array(
                        'lat' => $lat,
                        'lon' => $startingCoordinates['lon'] + atan2(
                                sin( $bearing ) * sin( $angularDistance ) * cos( $startingCoordinates['lat'] ),
                                cos( $angularDistance ) - sin( $startingCoordinates['lat'] ) * sin( $lat )
                        )
                );
        }
 
Als ik deze functie uitvoer voor new york (40.7142691, -74.0059729), en verschillende afstanden en oriëntaties, krijg ik steeds hetzelfde resultaat.

0 deg, 10km -> 0.12643539666731,-74.0059729
0 deg, 100km -> 0.12643539666731, -74.0059729
0 deg, 100km -> 0.12643539666731, -74.0059729

90 deg, 10km -> 0.12643539666731, -74.0059729
90 deg, 100km -> 0.12643539666731, -74.0059729
90 deg, 100km -> 0.12643539666731, -74.0059729
 
Bij mijn test kunt u enkele realistisch waarden geven
PHP:
<?php
	/**
         * Finds a destination given a starting location, bearing and distance.
         * 
         * @param array $startingCoordinates The starting coordinates, as non-directional floats in an array with lat and lon keys.
         * @param float $bearing The initial bearing in degrees.
         * @param float $distance The distance to travel in km.
         * 
         * @return array The desitination coordinates, as non-directional floats in an array with lat and lon keys.
         */
 class cord {
        public static function findDestination( array $startingCoordinates, $bearing, $distance ) {
                $startingCoordinates['lat'] = (float)$startingCoordinates['lat'];
                $startingCoordinates['lon'] = (float)$startingCoordinates['lon'];
                
                $angularDistance = $distance / Maps_EARTH_RADIUS;
                $lat = asin(
                                sin( $startingCoordinates['lat'] ) * cos( $angularDistance ) +
                                cos( $startingCoordinates['lat'] ) * sin( $angularDistance ) * cos( $bearing )
                );
                return array(
                        'lat' => $lat,
                        'lon' => $startingCoordinates['lon'] + atan2(
                                sin( $bearing ) * sin( $angularDistance ) * cos( $startingCoordinates['lat'] ),
                                cos( $angularDistance ) - sin( $startingCoordinates['lat'] ) * sin( $lat )
                        )
                );
        }
}
$cord = new cord();
$startingCordinates['lat'] = 10;
$startingCordinates['lon'] = 10;
$cord->findDestination($startingCordinates,90,50);
?>
( ! ) Warning: Division by zero in E:\_A_servers\xampp\htdocs\automaticsitev2.5\intersante scripts\phpdesigner_output_tmp.php on line 16
Call Stack
# Time Memory Function Location
1 0.0019 71336 {main}( ) ..\phpdesigner_output_tmp.php:0
2 0.0019 72096 cord::findDestination( ) ..\phpdesigner_output_tmp.php:33

$angularDistance = $distance / Maps_EARTH_RADIUS;
wat is de constante earth_radius
 
Maps_EARTH_RADIUS = 20000 / pi
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan