lib/geo_calc/calc/rhumb.rb in geo_calc-0.7.1 vs lib/geo_calc/calc/rhumb.rb in geo_calc-0.7.3

- old
+ new

@@ -1,18 +1,23 @@ -module GeoCalc::Calc +module GeoCalc module Rhumb + # Returns the distance from this point to the supplied point, in km, travelling along a rhumb line + # + # see(http:#williams.best.vwh.net/avform.htm#Rhumb) + # + # @param [GeoPoint] Destination point latitude and longitude of + # @return [Numeric] Distance in km between start and destination point def rhumb_distance_to point GeoCalc::Calc::Rhumb.rhumb_distance_to self, point end # Returns the distance from this point to the supplied point, in km, travelling along a rhumb line - # - # see http:#williams.best.vwh.net/avform.htm#Rhumb - # - # - GeoPoint point: Latitude/longitude of destination point - # Returns Numeric: Distance in km between this point and destination point - + # + # @param [GeoPoint] Start point with (latitude, longitude) + # @param [GeoPoint] Destination point (latitude, longitude) + # @return [Numeric] Distance in km between start and destination point + # def self.rhumb_distance_to base_point, point lat1 = base_point.lat.to_rad lat2 = point.lat.to_rad dlat = (point.lat - base_point.lat).to_rad @@ -32,18 +37,23 @@ dist = Math.sqrt(dlat*dlat + q*q*dlon*dlon) * base_point.earth_radius_km; dist.round(4) # 4 sig figures reflects typical 0.3% accuracy of spherical model end + # Returns the bearing from this point to the supplied point along a rhumb line, in degrees + # + # @param [GeoPoint] Destination point (latitude, longitude) + # @return [Numeric] Bearing in degrees from North + # def rhumb_bearing_to point GeoCalc::Calc::Rhumb.rhumb_bearing_to self, point end # Returns the bearing from this point to the supplied point along a rhumb line, in degrees # - # - GeoPoint point: Latitude/longitude of destination point - # Returns Numeric: Bearing in degrees from North - + # @param [GeoPoint] Destination point (latitude, longitude) + # @return [Numeric] Bearing in degrees from North + # def self.rhumb_bearing_to base_point, point lat1 = base_point.lat.to_rad lat2 = point.lat.to_rad dlon = (point.lon - base_point.lon).to_rad @@ -56,20 +66,28 @@ brng = Math.atan2(dlon, dphi); (brng.to_deg+360) % 360 end + # Returns the destination point from this point having travelled the given distance (in km) on the + # given bearing along a rhumb line + # + # @param [Number] brng: Bearing in degrees from North + # @param [Number] dist: Distance in km + # @returns [Array] Destination point as an array [lat, long] def rhumb_destination_point brng, dist GeoCalc::Calc::Rhumb.rhumb_destination_point self, brng, dist end + # Returns the destination point from this point having travelled the given distance (in km) on the # given bearing along a rhumb line - # - # @param {Number} brng: Bearing in degrees from North - # @param {Number} dist: Distance in km - # @returns {LatLon} Destination point - + # + # @param [GeoPoint] Starting point (latitude, longitude) + # @param [Number] brng: Bearing in degrees from North + # @param [Number] dist: Distance in km + # @returns [Array] Destination point as an array [lat, long] + # def self.rhumb_destination_point base_point, brng, dist d = dist / base_point.earth_radius_km # d = angular distance covered on earth's surface lat1 = base_point.lat.to_rad lon1 = base_point.lon.to_rad brng = brng.to_rad @@ -90,9 +108,10 @@ if lat2.abs > Math::PI/2 lat2 = lat2>0 ? Math::PI-lat2 : -(Math::PI-lat2) end lon2 = (lon1+dlon+3*Math::PI) % (2*Math::PI) - Math::PI - GeoPoint.new lat2.to_deg, lon2.to_deg + [lat2.to_deg, lon2.to_deg] + # GeoPoint.new end end end \ No newline at end of file