Skip to content

Instantly share code, notes, and snippets.

@FernandoEscher
Forked from straydogstudio/circle_path
Created June 16, 2013 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FernandoEscher/5793278 to your computer and use it in GitHub Desktop.
Save FernandoEscher/5793278 to your computer and use it in GitHub Desktop.
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
segments = 16
dRad = 2*Math::PI/segments
(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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment