Skip to content

Instantly share code, notes, and snippets.

@straydogstudio
Last active September 11, 2018 21:18
Show Gist options
  • Select an option

  • Save straydogstudio/4992733 to your computer and use it in GitHub Desktop.

Select an option

Save straydogstudio/4992733 to your computer and use it in GitHub Desktop.

Revisions

  1. straydogstudio revised this gist May 30, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions circle_path
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    def self.circle_path(center, radius, complete_path = false)
    # For increased accuracy, if your data is in a localized area, add the elevation in meters to r_e below:
    r_e = 6378137.0
    @@d2r ||= Math::PI/180
    @@multipliers ||= begin
  2. straydogstudio revised this gist Feb 20, 2013. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions circle_path
    Original file line number Diff line number Diff line change
    @@ -4,8 +4,12 @@ def self.circle_path(center, radius, complete_path = false)
    @@multipliers ||= begin
    segments = 16
    dRad = 2*Math::PI/segments
    segments += 1 if complete_path
    segments.times.map { |i| rads = dRad*i; [Math.sin(rads),Math.cos(rads)] }
    (segments + (complete_path ? 1 : 0)).times.map do |i|
    rads = dRad*i
    y = Math.sin(rads)
    x = Math.cos(rads)
    [y.abs < 0.01 ? 0.0 : y, x.abs < 0.01 ? 0.0 : x]
    end
    end
    centerLat = center.first
    centerLng = center.last
  3. straydogstudio created this gist Feb 20, 2013.
    15 changes: 15 additions & 0 deletions circle_path
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    def self.circle_path(center, radius, complete_path = false)
    r_e = 6378137.0
    @@d2r ||= Math::PI/180
    @@multipliers ||= begin
    segments = 16
    dRad = 2*Math::PI/segments
    segments += 1 if complete_path
    segments.times.map { |i| rads = dRad*i; [Math.sin(rads),Math.cos(rads)] }
    end
    centerLat = center.first
    centerLng = center.last
    dLat = radius/(r_e*@@d2r)
    dLng = radius/(r_e*Math.cos(@@d2r*centerLat)*@@d2r)
    @@multipliers.map {|m| [centerLat + m[0]*dLat, centerLng + m[1]*dLng]}
    end