Sha256: 9345fecf0083d9385b716fd228c0219b5f9306f5621870aced1f60b89cf1c756
Contents?: true
Size: 1 KB
Versions: 6
Compression:
Stored size: 1 KB
Contents
module GeoCalc module Midpoint def midpoint_to point GeoCalc::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) # # @param [GeoPoint] base_point: Starting point (latitude, longitude) # @param [GeoPoint] point: Destination point (latitude, longitude) # @return [Array] 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) [lat3.to_deg, lon3.to_deg] # GeoPoint.new end end end
Version data entries
6 entries across 6 versions & 1 rubygems