Skip to content
Snippets Groups Projects
Commit 1bc72c15 authored by Hoa Ben The Nguyen's avatar Hoa Ben The Nguyen
Browse files

fix: calculation

parent 19c84eaf
No related branches found
No related tags found
No related merge requests found
...@@ -30,31 +30,36 @@ def calculate_corners(lat, lng, area_offset): ...@@ -30,31 +30,36 @@ def calculate_corners(lat, lng, area_offset):
(60.7966, 10.7405)]''' (60.7966, 10.7405)]'''
# separate the zones into smaller area, into a grid # separate the zones into smaller area, into a grid
def define_gridareas(lat, lng, area_offset, grid_size, dimension, subId, groupId): def define_gridareas(lat, lng, area_offset, grid_size):
a = dimension + subId + groupId # soon to be implemented #a = dimension + subId + groupId soon to be implemented
print(a) #print(a)
grided_area = [] # container for an area turned into a grid of areas grided_area = [] # container for an area turned into a grid of areas
# find the main area's corner positions # find the main area's corner positions
main_area = calculate_corners(lat, lng, area_offset) main_area = calculate_corners(lat, lng, area_offset)
# find the main area's range size # find the main area's range size
area_size = (main_area[0][0] - main_area[2][0], main_area[0][1] - main_area[2][1]) area_size = (main_area[2][0] - main_area[0][0], main_area[0][1] - main_area[2][1])
# find each subareas vector to it's center # find each subareas vector to it's center
dist_to_subcenter = (area_size[0]/(grid_size*2), area_size[1]/(grid_size*2)) dist_to_subcenter = (area_size[0]/(grid_size*2), area_size[1]/(grid_size*2))
print(dist_to_subcenter)
# find subareas size relative to main area # find subareas size relative to main area
subarea_offset = area_offset/grid_size subarea_offset = area_offset/grid_size
print(main_area)
# find the center coordinates of each area in grid to find the corner areas # find the center coordinates of each area in grid to find the corner areas
for y in range(grid_size-1): for y in (range(grid_size)):
relative_size_lng = y / grid_size relative_size_lng = y / grid_size
for x in range(grid_size-1): for x in (range(grid_size)):
relative_size_lat = x / grid_size relative_size_lat = x / grid_size
lat_pos = main_area[0][0] + relative_size_lat * area_size[0] - dist_to_subcenter[0] lat_pos = main_area[3][0] + relative_size_lat * area_size[0] + dist_to_subcenter[0]
lng_pos = main_area[0][1] + relative_size_lng * area_size[1] - dist_to_subcenter[1] lng_pos = main_area[3][1] + relative_size_lng * area_size[1] + dist_to_subcenter[1]
# id of each subarea
sub_id = x % grid_size + grid_size*y
# use the center of sub areas to find the corner of each subarea # use the center of sub areas to find the corner of each subarea
grided_area.append(calculate_corners(lat_pos, lng_pos,subarea_offset)) corners = calculate_corners(lat_pos, lng_pos, subarea_offset)
grided_area.append((sub_id, corners))
return grided_area return grided_area
#print(calculate_corners(60,10,1500)) print(define_gridareas(60,10,1500,4))
#print(define_gridareas(60,10,1500,4)) \ No newline at end of file
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment