This example and java script code refer to link text
Take a look at the section on edge lines.
Given the starting point and the distance d along the constant bearing θ, this will calculate the destination. If you maintain a constant bearing along the line of the stream, you will gradually scroll to one of the poles.
Formula
α = d/R (angular distance) lat2 = lat1 + α.cos(θ) Δφ = ln(tan(lat2/2+π/4)/tan(lat1/2+π/4)) [= the 'stretched' latitude difference] if E:W line q = cos(lat1) otherwise q = Δlat/Δφ Δlon = α.sin(θ)/q lon2 = (lon1+Δlon+π) % 2.π − π where ln is natural log and % is modulo, Δlon is taking shortest route (<180°), and R is the earth's radius
JavaScript :
lat2 = lat1 + d*Math.cos(brng); var dPhi = Math.log(Math.tan(lat2/2+Math.PI/4)/Math.tan(lat1/2+Math.PI/4)); var q = (!isNaN(dLat/dPhi)) ? dLat/dPhi : Math.cos(lat1);
I am trying to convert it to php syntax, but I am not getting the desired result. My latitudinal part is working fine. I also included my test data.
MY PHP CODE
// test data $R = 6371; $tlatitude = 50.7; $tlongitude = -105.214; $theading = 124; $d = 50; $projlat = $tlatitude + rad2deg(($d/$R)*COS(deg2rad($theading))); //Δφ = ln(tan(lat2/2+π/4)/tan(lat1/2+π/4)) $delta_phi = log(tan(deg2rad($projlat/2) + pi()/4)/(tan(deg2rad($tlatitude/2) + pi()/4))); //q = Δlat/Δφ $delta_lat = deg2rad($projlat - $tlatitude); $q = $delta_lat/$delta_phi; //Δlon = α.sin(θ)/q $delta_long = rad2deg($d/$R*sin(deg2rad($theading))/$q); $projlong = $tlongitude + $delta_long;
I get $projlong = -104.84
according to the link page, the answer should be -104.63
.
Now I am trying to get this to work, ignoring the east-west and the pole possibilities.
javascript php
brian
source share