开发者

C# - Find coordinates to extend line by certain amount of kilometers

开发者 https://www.devze.com 2023-03-02 05:27 出处:网络
I need to calculate the coordinates of a point that extends an existing line by a certain amount of kilometers.

I need to calculate the coordinates of a point that extends an existing line by a certain amount of kilometers.

Given Input: (1) beginning and ending coordinates of an existing line (in degrees). (2) length (km) of how far the new line sho开发者_高级运维uld extend past the "ending" coordinate given above.

Output: Latitude and longitude (in degrees) of point that extends the line

I currently have a method that calculates the bearing between 2 sets of coordinates if that helps. I also have a method that finds a point on a line, but it's a point between the 2 sets of given coordinates, not extending the existing line. I cannot seem to figure out how to alter that for my needs.

Also, I'm using WGS-84, so (from my understanding) the curvature of the earth does not need to be taken into account.

Any help would be appreciated, thank you!

Edit:

Well the problem I saw was that the distance was in kilometers while the coordinates were GPS degrees. But I just ended up using vectors to solve it:

C = B - k(A - B), where k = proportion of distance to place C

Note: k=1.5 in my case because I wanted the new point to be one half the distance outside of the original line. 0 would be at point A and 1 at point B I believe.

I've plotted it in Google Earth and it seems to work.


You want to look into the equation of a straight line. With the magnitude and start point you can easily calculate the end point for a given length.

Y = mx + b

Here is a quick tutorial:

http://www.mathsisfun.com/equation_of_line.html

You could also google for collinear points which is actually what you are looking for.


The Earth's curvature does need to be taken into account. You also need to decide whether you are working with greater circles (shortest distance) or rhumb lines. If it is the former then you need to calculate the end bearing and then extend from this bearing. The following link contains the formulas you need.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号