Sha256: 0d9c8b80f0d4a558136cb2839e159ee680c4534e212e732dbda220d94ad14fa7

Contents?: true

Size: 772 Bytes

Versions: 3

Compression:

Stored size: 772 Bytes

Contents

class GeoDistance
  class NVector < DistanceFormula
    def self.distance *args
      from, to, units = get_points(args)
      lat1, lon1, lat2, lon2 = [from.lat, from.lng, to.lat, to.lng]
      
      sin_x1 = Math.sin(lon1)
      cos_x1 = Math.cos(lon1)

      sin_y1 = Math.sin(lat1)
      cos_y1 = Math.cos(lat1)

      sin_x2 = Math.sin(lon2)
      cos_x2 = Math.cos(lon2)

      sin_y2 = Math.sin(lat2)
      cos_y2 = Math.cos(lat2)

      cross_prod =  (cos_y1*cos_x1 * cos_y2*cos_x2) + (cos_y1*sin_x1 * cos_y2*sin_x2) + (sin_y1 * sin_y2)
        
      c = Math.acos(cross_prod)
      
      # puts "c: #{c}"
      # radians_per_degree                          
      c = (c * 0.0201324).to_deg      
      
      units ? c.radians_to(units) : c
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
geo-distance-0.2.2 lib/geo-distance/formula/n_vector.rb
geo-distance-0.2.1 lib/geo-distance/formula/n_vector.rb
geo-distance-0.2.0 lib/geo-distance/formula/n_vector.rb