This example and java script code is from link text
Look at the section on rhumb lines.
Given a start point and a distance d along constant bearing θ, this will calculate the destination point. If you maintain a constant bearing along a rhumb line, you will gradually spiral in towards 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); // E-W line gives dPhi=0
var dLon = d*Math.sin(brng)/q;
// check for some daft bugger going past the pole, normalise latitude if so
if (Math.abs(lat2) > Math.PI/2) lat2 = lat2>0 ? Math.PI-lat2 : -(Math.PI-lat2);
lon2 = (lon1+dLon+Math.PI)%(2*Math.PI) - Math.PI;
I am trying to convert it into php syntax but I am not getting the desired result. I have the latitude part 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 referenced page the answer should be -104.63
.
Now I am trying to get this to work disregarding the east-west and over the pole possibilities.