Geometry: find point a specific distance between two points
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.
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).
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 -
.
I believe the Haversine Formula could be applied here. If it would help I've implemented it in C#, Java and Javascript?
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'}))
精彩评论