Translate posts to Experimental | Feedback
Google
Official Google Earth Download Site
Topic Options
Rate This Topic
Previous Topic
View All Topics Index
Next Topic
#185502 - 10/21/05 06:57 PM NetworkLink: How to calculate unknown coordinates *****
TJ1 Offline
Traveler

Registered: 09/28/05
Posts: 162
Loc: Nottingham, UK
This is my 2nd in a series of three articles that shows how to use trigonometry to gain useful information about the Google Earth user environment.

In this article I'm providing the code for a PHP function to calculate the coordinates of an unknown point from a known position, range and bearing. This can be used with the LookAt variables sent to the server by NetworkLink to calculate the coordinates of the viewer, especially when the viewpoint is tilted and skewed and the viewpoint is far away from the BBOX.

My 3rd article shows a single PHP function to calculate both the location and altitude of the unknown viewpoint from just the LookAt data, and is a combination of this function and my previously published altitude() function.
Code:
/**
* Calculate the unknown coordinates at bearing and distance from known coordinates
*
* Developed by TJ (http://tjworld.net/software/kml/) for Google Earth applications
*
* @param float long Longitude of known point (decimal degreees)
* @param float lat Latitude of known point (decimal degrees)
* @param float distance Distance to unknown point (meters)
* @param float bearing Bearing (angle in degrees) to unknown point.
* Measured from North=0, -ve going to west (-90), +ve going to east (90)
* @returns array Associative array containing unknown 'longitude' and 'latitude'
*/
$EARTH_RADIUS_EQUATOR = 6378140.0;
$RADIAN = 180 / pi();

function calcLatLong($long, $lat, $distance, $bearing) {
global $EARTH_RADIUS_EQUATOR, $RADIAN;
$b = $bearing / $RADIAN;
$long = $long / $RADIAN;
$lat = $lat / $RADIAN;
$f = 1/298.257;
$e = 0.08181922;

$R = $EARTH_RADIUS_EQUATOR * (1 - $e * $e) / pow( (1 - $e*$e * pow(sin($lat),2)), 1.5);
$psi = $distance/$R;
$phi = pi()/2 - $lat;
$arccos = cos($psi) * cos($phi) + sin($psi) * sin($phi) * cos($b);
$latA = (pi()/2 - acos($arccos)) * $RADIAN;

$arcsin = sin($b) * sin($psi) / sin($phi);
$longA = ($long - asin($arcsin)) * $RADIAN;
return array('longitude' => $longA, 'latitude' => $latA);
}

_________________________
TJ.

Top
#185503 - 07/13/06 10:59 AM Re: NetworkLink: How to calculate unknown coordina [Re: TJ1]
gnlnx Offline
Traveler

Registered: 06/01/06
Posts: 21
on this line:

Code:
$psi = $distance/$R;



what is $R? can you explain your code a bit or point to the formula? I'm having trouble following it. Thanks.


-gnlnx

Top