0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

東西南北の緯度経度から任意の数に分割する

Last updated at Posted at 2020-10-28
# 縦横何分割するか
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)
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?