Module: GeoCalc::Bearing
- Defined in:
- lib/geo_calc/calc/bearing.rb
Class Method Summary collapse
-
.bearing_to(base_point, point) ⇒ Numeric
Returns the (initial) bearing from this point to the supplied point, in degrees see(#williams.best.vwh.net/avform.htm#Crs).
-
.final_bearing_to(base_point, point) ⇒ Numeric
Returns final bearing arriving at supplied destination point from this point; the final bearing will differ from the initial bearing by varying degrees according to distance and latitude.
Instance Method Summary collapse
Class Method Details
.bearing_to(base_point, point) ⇒ Numeric
Returns the (initial) bearing from this point to the supplied point, in degrees see(#williams.best.vwh.net/avform.htm#Crs)
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/geo_calc/calc/bearing.rb', line 15 def self.bearing_to base_point, point lat1 = base_point.lat.to_rad lat2 = point.lat.to_rad dlon = (point.lon - base_point.lon).to_rad y = Math.sin(dlon) * Math.cos(lat2) x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dlon) bearing = Math.atan2(y, x) (bearing.to_deg + 360) % 360 end |
.final_bearing_to(base_point, point) ⇒ Numeric
Returns final bearing arriving at supplied destination point from this point; the final bearing will differ from the initial bearing by varying degrees according to distance and latitude
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/geo_calc/calc/bearing.rb', line 38 def self.final_bearing_to base_point, point # get initial bearing from supplied point back to this point... lat1 = point.lat.to_rad lat2 = base_point.lat.to_rad dlon = (base_point.lon - point.lon).to_rad y = Math.sin(dlon) * Math.cos(lat2) x = Math.cos(lat1)*Math.sin(lat2) - Math.sin(lat1)*Math.cos(lat2)*Math.cos(dlon) bearing = Math.atan2(y, x) # ... & reverse it by adding 180° (bearing.to_deg+180) % 360 end |
Instance Method Details
#bearing_to(point) ⇒ Object
4 5 6 |
# File 'lib/geo_calc/calc/bearing.rb', line 4 def bearing_to point GeoCalc::Bearing.bearing_to self, point end |
#final_bearing_to(point) ⇒ Object
27 28 29 |
# File 'lib/geo_calc/calc/bearing.rb', line 27 def final_bearing_to point GeoCalc::Bearing.final_bearing_to self, point end |