Calculate point between two coordinates based on percentage

I am looking for a function that returns a point (lat, long) between two points (where I also indicate their lat, long), and this point is based on a percentage of the distance.

So, I specify Lat1, Lon1, Lat2, Lon2 and% of the function, and it returns a point, for example, 20% distant from the first point to the second.

+5
source share
2 answers

Assuming the coordinate is a decimal number. You can use this equation.

function midpoint(lat1, long1, lat2, long2, per) { return [lat1 + (lat2 - lat1) * per, long1 + (long2 - long1) * per]; } 

Returns the new desired coordinate [lat, long] depending on the percentage (for example, for = 0.2 for 20%).

+10
source

Here is a link that will help a lot (check below)

http://www.movable-type.co.uk/scripts/latlong.html

Midpoint

An intermediate point of any fraction along the path of a large circle between two points can also be calculated.

Formula

 a = sin((1−f)⋅δ) / sin δ b = sin(f⋅δ) / sin δ x = a ⋅ cos φ1cos λ1 + b ⋅ cos φ2cos λ2 y = a ⋅ cos φ1sin λ1 + b ⋅ cos φ2sin λ2 z = a ⋅ sin φ1 + b ⋅ sin φ2 φi = atan2(z, √x² + y²) λi = atan2(y, x) 

where f is the fraction along the large circle (f = 0 is point 1, f = 1 is point 2), δ is the distance of angular d / R between two points.

+1
source

Source: https://habr.com/ru/post/1236763/


All Articles