views:

482

answers:

1

Hi

I have two given lat and lon points. For example, lets assume I have two positions (point_1 and point_2) at coordinates (lat1, lon1) and (lat2, lon2). I would like to calculate a third point, that is on the same latitude as that of point_2, but x km to the east or west of point_2. So the third point will have the same latitude as point_2, but a different longitude depending on distance x (in kilometers), in other words point_3 will be (lat2, lon?). I am writing this in IDL, but any other language or formulas would be very welcome.

Thanks

+1  A: 

You don't use point 1 anywhere, do you? Let's say our point is P = (lat, lon)

The first rule of problems like this: draw a picture! From a cross-section of the earth, you can see that the radius of the circle centered on the earth's axis, going through your two points, is R*cos(lat). (R is the earth's radius. I hope you don't need to consider the earth an ellipsoid here.) The length x therefore takes up an angle (in degrees) of 360*x/(2*pi*R*cos(lat)). The new point you want is then:

P' = ( lat, lon +- 180*x/(2Rcos(lat)) )

I'm assuming you're using -180 to 0 for west longitude, so you have +/- for east/west. You'll have to check if you need to wrap around. Pseudo-code:

if (lon < -180)
   lon += 360
else if (long > 180)
   lon -= 360

Just for fun: if you do care about the earth being ellipsoidal, the radius of the circle is (instead of R*cos(lat)):

1/sqrt(tan^2 lat / Rp^2 + 1 / Re^2)

where Rp is the polar radius and Re is the equatorial radius. If Rp = Re, this reduces to the original formula, since 1 + tan^2 lat = sec^2 lat

Jefromi