2

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

Jim Lewis
  • 43,505
  • 7
  • 82
  • 96
  • This problem is solvable with some trigonometrics and basic maths. Sure you can't figure out? – svens Oct 06 '09 at 15:42
  • It is not clear to me what point one has to do with it...? As per your question, you are just looking for a position x ml west or east of point 2. Is that correct....? – KristoferA Oct 06 '09 at 15:46
  • Is the coordinate in degrees:minutes:seconds or decimal degrees? – James Goodwin Oct 06 '09 at 15:47
  • 1
    This gentleman has provided all you need as C# code in his blog: http://bryan.reynoldslive.com/post/Latitude2c-Longitude2c-Bearing2c-Cardinal-Direction2c-Distance2c-and-C.aspx – KristoferA Oct 06 '09 at 15:48
  • solutions for this problem are also available here: https://stackoverflow.com/questions/7222382/get-lat-long-given-current-point-distance-and-bearing – Yonoss Aug 22 '22 at 23:22

2 Answers2

2

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

Cascabel
  • 479,068
  • 72
  • 370
  • 318
0
import math

R = 6378.1 #Radius of the Earth
brng = 1.57 #Bearing is 90 degrees converted to radians.
d = 15 #Distance in km

#lat2  52.20444 - the lat result I'm hoping for
#lon2  0.36056 - the long result I'm hoping for.

lat1 = math.radians(52.20472) #Current lat point converted to radians
lon1 = math.radians(0.14056) #Current long point converted to radians

lat2 = math.asin( math.sin(lat1)*math.cos(d/R) +
     math.cos(lat1)*math.sin(d/R)*math.cos(brng))

lon2 = lon1 + math.atan2(math.sin(brng)*math.sin(d/R)*math.cos(lat1),
             math.cos(d/R)-math.sin(lat1)*math.sin(lat2))

lat2 = math.degrees(lat2)
lon2 = math.degrees(lon2)

print(lat2)
print(lon2)
MRDJR97
  • 818
  • 2
  • 10
  • 27