mrJean1 / PyGeodesy

Pure Python geodesy tools
https://mrjean1.github.io/PyGeodesy/
297 stars 58 forks source link

Along-track distance #7

Closed naktinis closed 7 years ago

naktinis commented 7 years ago

It would be convenient to have a method for computing along-track distance: "distance from the start point to the closest point on the path (to the end point) to the third point". The formula (as provided here) is:

dAt = acos(cos(d13 / R) / cos(dXt / R)) * R

Where dXt is cross-track distance and d13 is the distance from start to the point of interest.

It is also possible to modify it to support negative values, which makes sense in certain cases.

I would be happy to add this method if you're considering accepting pull requests.

naktinis commented 7 years ago

I would suggest adding the following test:

s = LatLon(53.3206, -1.7297)
e = LatLon(53.1887, 0.1334)
p1 = LatLon(53.36366, -1.83883)
p2 = LatLon(53.35423, -1.60881)
d1 = p1.alongTrackDistanceTo(s, e)  # -7702.7
d2 = p2.alongTrackDistanceTo(s, e)  # 7587.6

I would expect d1 to be negative as p1 projects onto the great circle defined by s->e to the opposite side than d2.

image

mrJean1 commented 7 years ago

Thank you! Tried that, but d1 is 7702.7, positive and not negative.

naktinis commented 7 years ago

Yes, it currently is. I think the sign can be determined by looking at the difference between bearings of s->e and s->p. I.e. checking if cos(bearing_s_to_e - bearing_s_to_p) > 0.

mrJean1 commented 7 years ago

That works. New version PyGeodesy-17.4.27 with your tests and an other one from Aviation Formula.

mrJean1 commented 7 years ago

An other open issue. There is also a crossTrackDistanceTo method for the sphericalNvector LatLon class and an alongTrackDistanceTo method is also available since PyGeodesy-17.5.11.

mrJean1 commented 7 years ago

Done.