6

This is similar to this question, but kind of the opposite.

I have two geographic points (latitude, longitude) A and B. Let's say they're 40 nautical miles apart. I'd like to calculate the coordinates of the point 10 nautical miles from point A, on the line between A and B. I'm sure this is very basic math, but it's been YEARS since I've had to do this kind of math (some other kinds I use daily), so I'm stuck. Any pointers would be greatly appreciated. My code for this project is in Python, but math isn't language-specific, so I'm not really concerned about that -- I just want to know the formula.

Community
  • 1
  • 1
RustyAtMath
  • 63
  • 1
  • 3
  • Presumably by "line between A and B" you mean the line on the sphere, and not the straight line in 3D space (which cuts through the sphere)? The latter is probably easier to code, and may be close enough for your purposes? – ShreevatsaR Aug 05 '10 at 04:29
  • Yes, the line on the sphere is what I mean. The straight line is surely easier to calculate; I'm not entirely sure if it's close enough or not (I don't know how much difference it will make at the relatively short distances I'm working with). – RustyAtMath Aug 05 '10 at 04:46

4 Answers4

8

You have two position vectors with (latitude, longitude). From those you can calculate your bearing from point A to point B (if you don't already know it). With a bearing and a distance you can calculate your new latitude and longitude.

All the math you need to know is referenced here: http://www.movable-type.co.uk/scripts/latlong.html. I deal with this stuff so infrequently it's nice to have that link saved somewhere (read: printed).

Anthony
  • 2,256
  • 2
  • 20
  • 36
4

So, it's something like:

 x B (x2,y2)
  \
   \
    \
     \
      x C (x3, y3)
       \
        \
         \
          X A (x1,y1)

The way I'd do this is first find the angle of that line:

angle_A_B = arctan((y2-y1)-(x2-x1))

then given the distance between A and C is known (lets call it distance_A_C):

sin(angle_A_B) = delta_x_A_C / distance_A_C
delta_x_A_C = distance_A_C * sin(angle_A_B)

therefore:

x3 = x1+delta_x_A_C

same for the value of y3:

delta_y_A_C = distance_A_C * cos(angle_A_B)

therefore:

y3 = y1+delta_y_A_C

I may have gotten the signs mixed so if it doesn't work change the + to -.

slebetman
  • 109,858
  • 19
  • 140
  • 171
  • This doesn't work on a sphere, which is the question here. It's finding the "straight line", not the great-circle line. – ShreevatsaR Aug 05 '10 at 06:15
  • Ah, OK. Didn't realise it is literally for the Earth's surface. – slebetman Aug 05 '10 at 06:36
  • Even if this solution was not 100% accurate with the original question it has been very helpful for me. [JS implementation of this algorithm](https://gist.github.com/1965850) – fguillen Mar 03 '12 at 12:23
0

I believe the Haversine Formula could be applied here. If it would help I've implemented it in C#, Java and Javascript?

Matthew Sposato
  • 1,635
  • 1
  • 11
  • 13
0

You can use my simple package to help you: Link: https://www.npmjs.com/package/haversine-calculator

const haversineCalculator = require('haversine-calculator')

const start = {
  latitude: -23.754842,
  longitude: -46.676781
}

const end = {
  latitude: -23.549588,
  longitude: -46.693210
}

console.log(haversineCalculator(start, end))
console.log(haversineCalculator(start, end, {unit: 'meter'}))
console.log(haversineCalculator(start, end, {unit: 'mile'}))
console.log(haversineCalculator(start, end, {threshold: 1}))
console.log(haversineCalculator(start, end, {threshold: 1, unit: 'meter'}))
console.log(haversineCalculator(start, end, {threshold: 1, unit: 'mile'}))
Undo
  • 25,519
  • 37
  • 106
  • 129