Class: GPX::TrackPoint
Overview
Basically the same as a point, the TrackPoint class is supposed to represent the points that are children of Segment elements. So, the only real difference is that TrackPoints hold a reference to their parent Segments.
Constant Summary collapse
- RADIUS =
earth’s mean radius in km
6371
Constants inherited from Point
Instance Attribute Summary collapse
-
#segment ⇒ Object
Returns the value of attribute segment.
Attributes inherited from Point
#elevation, #extensions, #gpx_file, #lat, #lon, #speed, #time
Instance Method Summary collapse
-
#haversine_distance_from(p2) ⇒ Object
Units are in km.
-
#initialize(opts = {}) ⇒ TrackPoint
constructor
A new instance of TrackPoint.
-
#law_of_cosines_distance_from(p2) ⇒ Object
Units are in km.
Methods inherited from Point
#lat_lon, #latr, #lon_lat, #lonr
Methods inherited from Base
#instantiate_with_text_elements
Constructor Details
#initialize(opts = {}) ⇒ TrackPoint
Returns a new instance of TrackPoint.
11 12 13 14 |
# File 'lib/gpx/track_point.rb', line 11 def initialize(opts = {}) super(opts) @segment = opts[:segment] end |
Instance Attribute Details
#segment ⇒ Object
Returns the value of attribute segment.
9 10 11 |
# File 'lib/gpx/track_point.rb', line 9 def segment @segment end |
Instance Method Details
#haversine_distance_from(p2) ⇒ Object
Units are in km
17 18 19 20 21 22 23 |
# File 'lib/gpx/track_point.rb', line 17 def haversine_distance_from(p2) d_lat = p2.latr - latr d_lon = p2.lonr - lonr a = Math.sin(d_lat / 2) * Math.sin(d_lat / 2) + Math.cos(latr) * Math.cos(p2.latr) * Math.sin(d_lon / 2) * Math.sin(d_lon / 2) c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)) RADIUS * c end |
#law_of_cosines_distance_from(p2) ⇒ Object
Units are in km
26 27 28 |
# File 'lib/gpx/track_point.rb', line 26 def law_of_cosines_distance_from(p2) Math.acos(Math.sin(latr) * Math.sin(p2.latr) + Math.cos(latr) * Math.cos(p2.latr) * Math.cos(p2.lonr - lonr)) * RADIUS end |