-
Notifications
You must be signed in to change notification settings - Fork 994
Description
https://github.com/Turfjs/turf/blob/master/packages/turf-nearest-point-on-line/index.ts
This code is wrong. It is an approximation.
You calculate the azimuth (bearing/direction) between p1 and p2, and from that azimuth, you try to make a perpendicular great circle by changing that azimuth by +180 (or -180, whatever). The problem with this is that, as you move along the path from p1 to p2, your azimuth constantly changes, assuming you are taking the shortest great-circle distance (ie: Haversine/Vincenty). Unless you use a line that assumes the azimuth does not change (ie: occasionally used for moving by sea), your azimuth only applies for p1. p2 has a different azimuth, and so does every single point along that great-circle.
It is a decent approximation of an answer for short distances, but know that this calculation will be way* off if distance(p1, p2) is either long, or if you're close to true north/south pole.
If you do have the proper code for this, I would welcome you let me know.
Thanks
-Phil