Divide into arbitrary numbers from the latitude and longitude of north, south, east and west

#How many vertical and horizontal divisions
DEVIDE_COUNT = 7 

#Median of array
cneter_index = (DEVIDE_COUNT / 2) + (DEVIDE_COUNT % 2)

#East, West, South and North
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)

#Dividing from north to south and west to east distance_rank increases as the distance from the center increases
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)

Recommended Posts

Divide into arbitrary numbers from the latitude and longitude of north, south, east and west
Divide the List into arbitrary numbers
ArrayList and the role of the interface seen from List
Java language from the perspective of Kotlin and C #