geohash-java icon indicating copy to clipboard operation
geohash-java copied to clipboard

VincentyGeodesy.distanceInMeters can result in NaN for valid input coordinates

Open satorg opened this issue 3 years ago • 2 comments

Sometimes VincentyGeodesy.distanceInMeters produces NaN for pretty valid input points. There are examples (not a complete list!) of arguments for distanceInMeters below that result it to generate NaN:

foo=(0.0,0.0), bar=(0.0,-180.0)
foo=(1.0,180.0), bar=(0.0,1.0)
foo=(0.0,0.0), bar=(0.0,180.0)
foo=(-1.0,1.0), bar=(0.0,-180.0)
foo=(-1.0,-103.0), bar=(0.0,78.0)
foo=(-1.0,-106.0), bar=(0.0,75.0)
foo=(-1.0,-142.0), bar=(0.0,39.0)
foo=(-1.0,-155.0), bar=(0.0,26.0)
foo=(-1.0,-161.0), bar=(0.0,18.0)
foo=(-1.0,-164.0), bar=(0.0,17.0)
foo=(-1.0,-176.0), bar=(1.0,4.0)
foo=(-1.0,-178.0), bar=(0.0,1.0)
foo=(-1.0,-179.0), bar=(0.0,0.0)
foo=(-1.0,-30.0), bar=(0.0,149.0)
foo=(-1.0,-33.0), bar=(0.0,148.0)
foo=(-1.0,-50.0), bar=(1.0,130.0)
foo=(-1.0,-74.0), bar=(0.0,105.0)
foo=(-1.0,-79.0), bar=(1.0,101.0)
foo=(-1.0,-93.0), bar=(0.0,86.0)
foo=(-1.0,0.0), bar=(0.0,-179.0)
foo=(-1.0,0.0), bar=(0.0,179.0)
foo=(-1.0,1.0), bar=(0.0,-178.0)
foo=(-1.0,1.0), bar=(1.0,-179.0)
foo=(-1.0,110.0), bar=(0.0,-69.0)
foo=(-1.0,144.0), bar=(0.0,-35.0)
foo=(-1.0,158.0), bar=(1.0,-22.0)
foo=(-1.0,167.0), bar=(1.0,-13.0)
foo=(-1.0,174.0), bar=(0.0,-5.0)
foo=(-1.0,176.0), bar=(0.0,-3.0)
foo=(-1.0,179.0), bar=(0.0,0.0)
foo=(-1.0,33.0), bar=(0.0,-148.0)
foo=(-1.0,46.0), bar=(0.0,-135.0)
foo=(-1.0,47.0), bar=(0.0,-134.0)
foo=(-1.0,5.0), bar=(1.0,-175.0)

The list above is generated with help of ScalaCheck.

Version: 1.4.0

satorg avatar Mar 02 '21 07:03 satorg

This probably happens because "Between two nearly antipodal points, the iterative formula may fail to converge". Perhaps in such cases, half the circumference of earth should be used.

mrjonjonjon avatar Jul 04 '22 17:07 mrjonjonjon

@mrjonjonjon yes, looks like so... But seems there's no clear and ready-to-use solution yet.

satorg avatar Jul 11 '22 21:07 satorg