Created
March 2, 2018 11:30
-
-
Save fujimura/bc238dd5d6a75aac31051d36d04a737a 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
require 'json' | |
def get_lonlat_in_spiral(i) | |
v = Complex.polar i, i/4.9 * Math::PI/2 | |
angle = v.angle | |
magnitude = v.magnitude | |
[magnitude * Math.cos(angle), magnitude * Math.sin(angle)] | |
end | |
r = 10.upto(30).map { |i| get_lonlat_in_spiral(i) } | |
coords = r.map {|x, y| [139.6 + y * 0.01, 35.7 + x * 0.01] } | |
puts JSON.generate( | |
type: "MultiPolygon", | |
coordinates: [coords.map {|y, x| [y.floor(5), x.floor(5)] }.map { |y, x| | |
[ | |
[y, x], | |
[y, x + 0.01], | |
[y - 0.01, x + 0.01], | |
[y - 0.01, x], | |
[y, x] | |
] | |
}] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment