How do I calculate x and y in km, between two points?

Several threads show how to calculate the distance between two lat-lon addresses. eg here.

I want something similar but different: distance in km between point A and point B on the x axis, positive if B is to the east of A and neg if it’s to the west.

The y-delta is relatively easy, because 1deg is always ~111km (right?)

Does anyone know how I can calculate this for the x-delta?

If I interpret your question correctly, you most likely want “how far do I need to go east (or west) along my current latitude to reach the same longitude as the other point?”.

Be aware that the answer will be slightly different depending on whether you start from A or B if their latitudes are different. Be also aware that it is subtly different from “how far do I need to walk to reach the same longitude as the other point”, since this will follow a great circle not exactly due east (or west). (Extreme case: consider antipodal points on the equator)

But what you want to know is: on a sphere, the distance between longitudes scales with the cosine of latitude. X-delta = longitude-delta * cos(latitude) * 111km/deg

Correct

:woozy_face:

The points are artificially on the same latitude: I have (say) 10 locations in Some City. I want to know the offset, in km, of each location from the node [place=city][name=Some City], for X and Y separately.

Perfect, thank you.

Could someone mathematical check my work?

I’ve tried the formula and got unexpected results.

Ref point lat/lon 52.0, 0.0
POI 53.0, 1.0
Y-delta (deg) 1
Y-delta (km) 1*111=111km
X-delta (deg) 1
X-delta (km) 1 * cos(52) * 111 = -18.092

Maybe I simply need to multiply by -1? But looks like there’s something else going on?

Thanks.

I didn’t check the formulas for correctness but you probably have a misinterpretation between degrees and radiant.

Mixing degree and radiant does not make sense but gives the number you where getting:
1° * cos(52 rad) * 111km/° = -18,09...km

Setting the caluculator to using degrees instead of radiants gives this:
1° * cos(52°) * 111km/° = 68,33...km

That shoul do the trick.

Did that help?

1 Like

Yes, this does the trick.

I’m using LibreOffice Calc, and it seems the default is radians. (Tested in Excel, same.)

The fix is to use the RADIANS() function to convert the degrees to radians before COS() processes it:

Maths: 1° * cos(52°) * 111km/° = 68.33...km
Functions: 1 * COS(RADIANS(52)) * 111 = 68.33