geodesics calculates the geodesic distance between 2 points with latitude and longitude on ellipsoid Earth using Lambert's formula.
- It is extensible using strategy pattern. By default:
- Use haversine formula for central angle calculation.
- Use Lambert's formula for geodesic calculation.
- The error rate is less than 1%. Passed a test set of 500,000 geodesics for the WGS84 ellipsoid.
gem install geodesics
require 'geodesics'
latitude1 = 22.633333
longitude1 = 120.266670
latitude2 = 25.105497
longitude2 = 121.597366
Geodesics.distance(latitude1, longitude1, latitude2, longitude2)
# => 306035.64651391446
- Distance unit is meter.
Geodesics#distance
is an alias ofGeodesics#distance_degree
Geodesics.distance_radian(latitude1, longitude1, latitude2, longitude2)
class MyStrategy
def distance(point1, point2)
# you implementation here
end
end
g = Geodesics.new(strategy: MyStrategy.new)
g.distance(latitude1, longitude1, latitude2, longitude2)
g.distance_radian(latitude1, longitude1, latitude2, longitude2)