rspatial / geosphere

R geosphere package
GNU General Public License v3.0
34 stars 7 forks source link

Fixing out of domaine acos() in alongTrackDistance() #8

Open clementviolet opened 2 years ago

clementviolet commented 2 years ago

Hi !

In some rare case, like those reported by #3, https://github.com/rspatial/geosphere/blob/0a775039177646d093edc23c709267ffc7094d76/R/alongTrack.R#L28 The angle in the acos(cos(dp) / cos(xtr)) function can be slightly lower than -1 or higher than +1 due to due to the rounding and machine precision. I added this quick (and maybe a bit dirty) fix to ensure that the angle stays within the domain of the arc-cosine function.