The following gets you pretty close (answer in km). If you need to be better than this, you have to work harder at the math - for example by following some of the links given.
import math
dx = (lon1-lon2)*40000*math.cos((lat1+lat2)*math.pi/360)/360
dy = (lat1-lat2)*40000/360
Variable names should be pretty obvious. This gives you
dx = 66.299 km (your link gives 66.577)
dy = 2.222 km (link gives 2.225)
Once you pick coordinates (for example, lon1, lat1
) as your origin, it should be easy to see how to compute all the other XY coordinates.
Note - the factor 40,000 is the circumference of the earth in km (measured across the poles). This gets you close. If you look at the source of the link you provided (you have to dig around a bit to find the javascript which is in a separate file) you find that they use a more complex equation:
function METERS_DEGLON(x)
{
with (Math)
{
var d2r=DEG_TO_RADIANS(x);
return((111415.13 * cos(d2r))- (94.55 * cos(3.0*d2r)) + (0.12 * cos(5.0*d2r)));
}
}
function METERS_DEGLAT(x)
{
with (Math)
{
var d2r=DEG_TO_RADIANS(x);
return(111132.09 - (566.05 * cos(2.0*d2r))+ (1.20 * cos(4.0*d2r)) - (0.002 * cos(6.0*d2r)));
}
}
It looks to me like they are actually taking account of the fact that the earth is not exactly a sphere... but even so when you are making the assumption you can treat a bit of the earth as a plane you are going to have some errors. I'm sure with their formulas the errors are smaller...
HTML
andjs
you could translate it to python? – Noelkd