vincenty 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.txt +8 -0
- data/lib/vincenty.rb +8 -8
- data/test/ts_vincenty.rb +30 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d378b30cc2863c4fbdb032cf44473d75c2a5e479eb226e3e24d956a0c9a77e66
|
4
|
+
data.tar.gz: b3b552e6a59501707b76c848aa7e1fae795a2430d91d1f180c177b16a23bc604
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 201e6694807048f2029f6b8779f70c9a068aace73ff8495fb29ee6cfda76de7e941bed8ca1e861e970d4e5c8ce67818554f4254ea5a4bb3aff86d2867afa86e0
|
7
|
+
data.tar.gz: f0770e50a4225648bd054bbfeb4bab51024452536456bb9b69c6244b516514be0c93ee9d80cb4960997464c036c073208413ceac0e1d8f4e9930942274121d9a
|
data/History.txt
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
robertburrowes Thu Oct 14 15:09:23 2021 +1300
|
2
|
+
bumped version
|
3
|
+
robertburrowes Thu Oct 14 15:06:18 2021 +1300
|
4
|
+
Bump version.
|
5
|
+
robertburrowes Thu Oct 14 14:43:00 2021 +1300
|
6
|
+
Bearing 0 and 180 edgecase for spherical test method resulted in negative sqrt
|
7
|
+
robertburrowes Sun Oct 10 12:09:10 2021 +1300
|
8
|
+
#{PROJECT} release 1.0.10
|
1
9
|
robertburrowes Sun Oct 10 12:07:45 2021 +1300
|
2
10
|
Inc version
|
3
11
|
robertburrowes Sun Oct 10 12:05:54 2021 +1300
|
data/lib/vincenty.rb
CHANGED
@@ -12,7 +12,7 @@ require_relative 'coordinate.rb'
|
|
12
12
|
# Modified to incorporate corrections to formulae as found in script on http://www.movable-type.co.uk/scripts/LatLongVincenty.html
|
13
13
|
# Added my Modification of the distanceAndAngle formulae to correct the compass bearing.
|
14
14
|
class Vincenty < Coordinate
|
15
|
-
VERSION = '1.0.
|
15
|
+
VERSION = '1.0.11'
|
16
16
|
|
17
17
|
# @return [String] constant VERSION
|
18
18
|
def version
|
@@ -30,13 +30,11 @@ class Vincenty < Coordinate
|
|
30
30
|
# @param [Coordinate] p2 is target coordinate that we want the bearing to.
|
31
31
|
# @return [TrackAndDistance] with the compass bearing and distance in meters to P2
|
32
32
|
def sphericalDistanceAndAngle( p2, equatorial_radius = WGS84_ER, inverse_flattening = WGS84_IF )
|
33
|
-
|
34
|
-
|
35
|
-
end
|
33
|
+
# No calculations necessary, if these are the same point.
|
34
|
+
return TrackAndDistance.new(0, 0, true) if @latitude == p2.latitude && @longitude == p2.longitude
|
36
35
|
|
37
36
|
a = equatorial_radius # equatorial radius in meters (+/-2 m)
|
38
|
-
|
39
|
-
b = a - a / f # WGS84 = 6356752.314245179 polar radius in meters
|
37
|
+
b = a - a / inverse_flattening # WGS84 = 6356752.314245179 polar radius in meters
|
40
38
|
r = (a + b) / 2 # average diametre as a rough estimate for our tests.
|
41
39
|
|
42
40
|
sin_lat1 = Math.sin(@latitude.to_rad)
|
@@ -45,9 +43,11 @@ class Vincenty < Coordinate
|
|
45
43
|
atan1_2 = Math.atan(1) * 2
|
46
44
|
t1 = cos_lat1 * Math.cos(p2.latitude.to_rad) * Math.cos(@longitude.to_rad - p2.longitude.to_rad) + sin_lat1 * sin_lat2
|
47
45
|
angular_distance = Math.atan(-t1 / Math.sqrt(-t1 * t1 + 1)) + atan1_2 # central angle in radians so we can calculate the arc length.
|
48
|
-
|
49
46
|
t2 = (sin_lat2 - sin_lat1 * Math.cos(angular_distance)) / (cos_lat1 * Math.sin(angular_distance))
|
50
|
-
|
47
|
+
|
48
|
+
bearing = if @longitude == p2.longitude
|
49
|
+
@latitude > p2.latitude ? Math::PI : 0
|
50
|
+
elsif Math.sin(p2.longitude.to_rad - @longitude.to_rad) < 0
|
51
51
|
2 * Math::PI - (Math.atan(-t2 / Math.sqrt(-t2 * t2 + 1)) + atan1_2) # Compass Bearing in radians (clockwise)
|
52
52
|
else
|
53
53
|
Math.atan(-t2 / Math.sqrt(-t2 * t2 + 1)) + atan1_2 # Compass Bearing in radians (clockwise)
|
data/test/ts_vincenty.rb
CHANGED
@@ -90,6 +90,36 @@ class TestVincenty < Test::Unit::TestCase
|
|
90
90
|
assert_equal(0, vtrack_and_bearing.distance.round(4))
|
91
91
|
end
|
92
92
|
|
93
|
+
# Edge case, when points are close, and 180 degrees
|
94
|
+
def test_vincenty_angle_when_180
|
95
|
+
start_track = Vincenty.new(-36.98684848301985, 174.4873448681314)
|
96
|
+
end_track = Vincenty.new(-36.989952870042174, 174.4873448681314)
|
97
|
+
|
98
|
+
vtrack_and_bearing = start_track.distanceAndAngle( end_track )
|
99
|
+
assert_equal(180.0, vtrack_and_bearing.bearing.to_deg.round(4))
|
100
|
+
|
101
|
+
vtrack_and_bearing = end_track.distanceAndAngle( start_track )
|
102
|
+
assert_equal(0.0, vtrack_and_bearing.bearing.to_deg.round(4))
|
103
|
+
end
|
104
|
+
|
105
|
+
# Edge case, when points are close, and 180 degrees
|
106
|
+
def test_spherical_angle_when_180
|
107
|
+
start_track = Vincenty.new(-36.98684848301985, 174.4873448681314)
|
108
|
+
end_track = Vincenty.new(-36.989952870042174, 174.4873448681314)
|
109
|
+
|
110
|
+
vtrack_and_bearing = start_track.sphericalDistanceAndAngle( end_track )
|
111
|
+
assert_equal(180.0, vtrack_and_bearing.bearing.to_deg.round(4))
|
112
|
+
end
|
113
|
+
|
114
|
+
#Edgecase when points are close and 0 degress
|
115
|
+
def test_spherical_angle_when_0
|
116
|
+
start_track = Vincenty.new(-36.98684848301985, 174.4873448681314)
|
117
|
+
end_track = Vincenty.new(-36.989952870042174, 174.4873448681314)
|
118
|
+
|
119
|
+
vtrack_and_bearing = end_track.sphericalDistanceAndAngle( start_track )
|
120
|
+
assert_equal(0.0, vtrack_and_bearing.bearing.to_deg.round(4))
|
121
|
+
end
|
122
|
+
|
93
123
|
# Run the Australian Geoscience site example.
|
94
124
|
def test_geoscience_au
|
95
125
|
flindersPeak = Vincenty.new("-37 57'3.72030″", "144 25'29.52440″" )
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vincenty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Burrowes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hoe-yard
|