Created
July 11, 2013 23:57
-
-
Save FernandoEscher/5980331 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def point_at_distance(center, distance, bearing=180) | |
pi = Math::PI | |
r_e = 6378137.0 #meters | |
d = distance/r_e | |
lat1 = (pi/180) * center.latitude | |
lng1 = (pi/180) * center.longitude | |
tc = (pi/180) * bearing | |
y = Math.asin(Math.sin(lat1)*Math.cos(d)+Math.cos(lat1)*Math.sin(d)*Math.cos(tc)) | |
dlng = Math.atan2( | |
Math.sin(tc)*Math.sin(d)*Math.cos(lat1), | |
Math.cos(d) - Math.sin(lat1)*Math.sin(y) | |
) | |
x = ((lng1-dlng+pi) % (2*pi)) - pi | |
lat = y * (180/pi) | |
lng = x * (180/pi) | |
center.factory.point(lat,lng) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment