# 縦横何分割するか
DEVIDE_COUNT = 7
# 配列の中央値
cneter_index = (DEVIDE_COUNT / 2) + (DEVIDE_COUNT % 2)
# 東西南北
origin_n = 0
origin_s = 50
origin_w = 100
origin_e = 200
north_south_unit = (origin_s - origin_n).fdiv(DEVIDE_COUNT)
west_east_unit = (origin_e - origin_w).fdiv(DEVIDE_COUNT)
# 北から南、西から東へ分割していく distance_rankは中心から遠いほど大きくなる
Mesh = Struct.new(:nl, :sl, :el, :wl, :distance_rank)
results = []
(1..DEVIDE_COUNT).each do |ns_count|
(1..DEVIDE_COUNT).each do |ew_count|
results << Mesh.new(
origin_n + (north_south_unit * (ns_count -1)),
origin_n + (north_south_unit * ns_count),
origin_w + (west_east_unit * (ew_count -1)),
origin_w + (west_east_unit * ew_count),
(cneter_index - ns_count).abs + (cneter_index - ew_count).abs
)
end
end
pp results.sort_by(&:distance_rank)
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme