module GeoCalc::Rhumb

Public Class Methods

rhumb_bearing_to(base_point, point) click to toggle source

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

# File lib/geo_calc/calc/rhumb.rb, line 55
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

  dphi = Math.log(Math.tan(lat2/2+Math::PI/4) / Math.tan(lat1/2+Math::PI/4))
  if dlon.abs > Math::PI
    dlon = dlon>0 ? -(2*Math::PI-dlon) : (2*Math::PI+dlon);
  end

  brng = Math.atan2(dlon, dphi);

  (brng.to_deg+360) % 360
end
rhumb_destination_point(base_point, brng, dist) click to toggle source

Returns the destination point from this point having travelled the given distance (in km) on the given bearing along a rhumb line

@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]

# File lib/geo_calc/calc/rhumb.rb, line 89
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

  lat2 = lat1 + d*Math.cos(brng);
  dlat = lat2 - lat1;
  dphi = Math.log(Math.tan(lat2/2+Math::PI/4) / Math.tan(lat1/2+Math::PI/4))

  q = begin
    dlat / dphi
  rescue 
    Math.cos(lat1) # E-W line gives dPhi=0
  end

  dlon = d * Math.sin(brng) / q
  # check for some daft bugger going past the pole

  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

  [lat2.to_deg, lon2.to_deg]
  # GeoPoint.new
end
rhumb_distance_to(base_point, point) click to toggle source

Returns the distance from this point to the supplied point, in km, travelling along a rhumb line

@param [GeoPoint] Start point with (latitude, longitude) @param [GeoPoint] Destination point (latitude, longitude) @return [Numeric] Distance in km between start and destination point

# File lib/geo_calc/calc/rhumb.rb, line 19
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
  dlon = (point.lon - base_point.lon).abs.to_rad

  dphi = Math.log(Math.tan(lat2/2 + Math::PI/4) / Math.tan(lat1/2 + Math::PI/4))

  q = begin
    dlat / dphi
  rescue 
    Math.cos(lat1) # E-W line gives dPhi=0
  end
  
  # if dlon over 180° take shorter rhumb across 180° meridian:
  dlon = 2*Math::PI - dlon if (dlon > Math::PI)

  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

Public Instance Methods

rhumb_bearing_to(point) click to toggle source

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

# File lib/geo_calc/calc/rhumb.rb, line 47
def rhumb_bearing_to point
  GeoCalc::Rhumb.rhumb_bearing_to self, point
end
rhumb_destination_point(brng, dist) click to toggle source

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]

# File lib/geo_calc/calc/rhumb.rb, line 77
def rhumb_destination_point brng, dist
  GeoCalc::Rhumb.rhumb_destination_point self, brng, dist
end
rhumb_distance_to(point) click to toggle source

Returns the distance from this point to the supplied point, in km, travelling along a rhumb line

see(#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

# File lib/geo_calc/calc/rhumb.rb, line 9
def rhumb_distance_to point
  GeoCalc::Rhumb.rhumb_distance_to self, point
end