Turfjs / turf

A modular geospatial engine written in JavaScript and TypeScript
https://turfjs.org/
MIT License
9.19k stars 934 forks source link

nearestPointOnLine broken on vertical line segments #1514

Open msbarry opened 5 years ago

msbarry commented 5 years ago

nearestPointOnLine exhibits strange behavior when the line is near-vertical.

For example in this jsfiddle the line goes from [-40,50] to [-40,60], the point is [-40.01,56] and turf returns the nearest point as [-40,~55.3]: https://jsfiddle.net/hdumty60/

I tried playing with the code a bit and the issue went away if I changed nearest-point-on-line to use rhumb destination, not sure if that is an ideal solution though.

rowanwins commented 5 years ago

Hi @msbarry

Thanks for the report. Yeah we've experienced similar with the along module, particularly when traversing large distances. In the v7 branch I've switched to using rhumb-destination for the along module.

This page contains some of the information behind the idea of rhumb calculations. I can't claim to be a maths & geomatics nerd but i think rhumb calculations are a better fit for these modules.

Cheers Rowan