gpx 0.9.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,60 +0,0 @@
1
- #--
2
- # Copyright (c) 2006 Doug Fales
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
23
- module GPX
24
- # Basically the same as a point, the TrackPoint class is supposed to
25
- # represent the points that are children of Segment elements. So, the only
26
- # real difference is that TrackPoints hold a reference to their parent
27
- # Segments.
28
- class TrackPoint < Point
29
- RADIUS = 6371; # earth's mean radius in km
30
-
31
- attr_accessor :segment
32
-
33
-
34
- def initialize(opts = {})
35
- super(opts)
36
- @segment = opts[:segment]
37
- end
38
-
39
- # Units are in km
40
- def haversine_distance_from(p2)
41
- d_lat = p2.latr - latr;
42
- d_lon = p2.lonr - lonr;
43
- 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);
44
- c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
45
- d = RADIUS * c;
46
- return d;
47
- end
48
-
49
- # Units are in km
50
- def pythagorean_distance_from(p2)
51
- Math.sqrt((p2.latr - latr)**2 + (p2.lonr - lonr)**2)
52
- end
53
-
54
- # Units are in km
55
- def law_of_cosines_distance_from(p2)
56
- (Math.acos(Math.sin(latr)*Math.sin(p2.latr) + Math.cos(latr)*Math.cos(p2.latr)*Math.cos(p2.lonr-lonr)) * RADIUS)
57
- end
58
-
59
- end
60
- end