Sha256: 15d6d99811ef1dd3f8c5c3eefde3b8eb66aea0f1d577a09d4ef9952aa1d8472a
Contents?: true
Size: 947 Bytes
Versions: 4
Compression:
Stored size: 947 Bytes
Contents
module GeoCalc::Calc module Midpoint def midpoint_to point GeoCalc::Calc::Midpoint.midpoint_to self, point end # Returns the midpoint between this point and the supplied point. # see http:#mathforum.org/library/drmath/view/51822.html for derivation # # - GeoPoint point: Latitude/longitude of destination point # Returns GeoPoint: Midpoint between this point and the supplied point def self.midpoint_to base_point, point lat1 = base_point.lat.to_rad lon1 = base_point.lon.to_rad; lat2 = point.lat.to_rad dlon = (point.lon - base_point.lon).to_rad bx = Math.cos(lat2) * Math.cos(dlon) by = Math.cos(lat2) * Math.sin(dlon) lat3 = Math.atan2(Math.sin(lat1)+Math.sin(lat2), Math.sqrt( (Math.cos(lat1)+bx)*(Math.cos(lat1)+bx) + by*by) ) lon3 = lon1 + Math.atan2(by, Math.cos(lat1) + bx) GeoPoint.new lat3.to_deg, lon3.to_deg end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
geo_calc-0.7.1 | lib/geo_calc/calc/midpoint.rb |
geo_calc-0.6.1 | lib/geo_calc/calc/midpoint.rb |
geo_calc-0.6.0.1 | lib/geo_calc/calc/midpoint.rb |
geo_calc-0.6.0 | lib/geo_calc/calc/midpoint.rb |