Module: GpxDoctor::DistanceCalculator

Defined in:
lib/gpx_doctor/distance_calculator.rb

Constant Summary collapse

METERS_PER_DEGREE_LAT =

Approximate degrees-to-meters conversion factors. 1 degree latitude ≈ 111_320 m 1 degree longitude ≈ 111_320 m * cos(latitude)

111_320.0

Class Method Summary collapse

Class Method Details

.bearing(a, b) ⇒ Object

Returns geographic bearing in degrees (0 = North, 90 = East, 180 = South, 270 = West) between two waypoints.



20
21
22
23
24
25
# File 'lib/gpx_doctor/distance_calculator.rb', line 20

def bearing(a, b)
  dlat_m, dlon_m = components(a, b)
  angle_rad = Math.atan2(dlon_m, dlat_m)
  degrees = angle_rad * 180.0 / Math::PI
  degrees % 360
end

.distance(a, b) ⇒ Object

Returns the flat-earth Pythagorean distance in meters between two waypoints.



13
14
15
16
# File 'lib/gpx_doctor/distance_calculator.rb', line 13

def distance(a, b)
  dlat_m, dlon_m = components(a, b)
  Math.sqrt(dlat_m**2 + dlon_m**2)
end