[Bug] Loxodrome cosLat

In java file Loxodrome, there is a mathematical bug in handling movement along circle of latitude.

There should be a division by cosine of latitude instead of the multiplication. This is probably caused by missing parentheses and isn’t an issue with deeper understanding of loxodrome. After all, this branch dealing with a circle of latitude is the simpler case of a loxodrome.

The problem is relatively simple to understand. Even if there was no flattening of Earth, the cosLat (cosine of latitude) would still be there in the formulae. cosLat at the equator is 1. cosLat at poles is zero. cosLat helps answer the question of how many meters is a degree of longitude at a specific latitude. Infinitely near the North Pole, a degree of longitude is infinitely close to zero meters. Invertly, a meter along circle of latitude is close to infinity when infinitely near the North Pole.

The function promises to find a position along a loxodrome. It needs to return the longitude of the found position. The current implementation would seem to aim to add a longitude offset to the longitude of the original position. The parameter to the method is the distance in meters. In other words, the question is how many degrees/radians of longitude does the number of meters represent. As I said above, one meter along circle of latitude should go towards infinite degrees when cosLat goes to zero - the result should go to infinity, which it cannot do if multiplied by a value between -1…1 instead of dividing by a value near positive zero.

Have someone verify the mathematical formulae from source material.

1 Like

Hi @merola90

Thank you for finding this potential issue. Unfortunately, I don’t have any reference to verify the equations.

Maybe @greyskyy can have a look on it and say if there is an error in the equation.

Regards,
Bryan

I confirm the problem and the analysis. I will fix it.
Thanks @merola90 for the report, please note that the forge issues page is better suited for reporting issues.

Hi @merola90,
Thanks a lot for the report, I have just validated your account on our GitLab instance. Sorry for the delay.
Have a nice day,
Sébastien

Sorry for the delay in my reply,

Thanks for the catch, yes that’s a bug. Missed the parenthesis and corresponding test cases in the original implementation. Thanks @luc for fixing.

–joe