Module: Calculations
- Defined in:
- lib/klimt/util/calculations.rb
Constant Summary collapse
- RADIUS =
Haversine formula for spherical distance See: rosettacode.org/wiki/Haversine_formula#Ruby
6371
Class Method Summary collapse
- .deg2rad(lat, long) ⇒ Object
-
.spherical_distance(start_latlng, end_latlng) ⇒ Object
rough radius of the Earth, in kilometers.
Class Method Details
.deg2rad(lat, long) ⇒ Object
14 15 16 |
# File 'lib/klimt/util/calculations.rb', line 14 def self.deg2rad(lat, long) [lat * PI / 180, long * PI / 180] end |
.spherical_distance(start_latlng, end_latlng) ⇒ Object
rough radius of the Earth, in kilometers
8 9 10 11 12 |
# File 'lib/klimt/util/calculations.rb', line 8 def self.spherical_distance(start_latlng, end_latlng) lat1, long1 = deg2rad(*start_latlng) lat2, long2 = deg2rad(*end_latlng) 2 * RADIUS * asin(sqrt(sin((lat2 - lat1) / 2)**2 + cos(lat1) * cos(lat2) * sin((long2 - long1) / 2)**2)) end |