Фух, наконец-то доделал всю логику, благодарю за подсказку, вот готовый код:
from haversine import haversine
from re import match
from pprint import pprint
def num_decimal_places(number):
return len(
(str(number) if '.' in str(number) \
else str(number) + '.').rstrip('0').split('.')[-1]
)
def go_to_metr(x, y, name_coordinate):
required_dist = 1
l = 0
r = min(180, 90-y)
while r-l > 1e-10:
m=(r+l)/2
dist = (
(haversine((x,y),(x,y+m))/1000)
) if name_coordinate == "y" else (
(haversine((x,y),(x+m,y))/1000)
)
if dist > required_dist:
r = m
else:
l = m
step = float(int(l))
numb_digit = 1
for _ in range(
num_decimal_places(y if name_coordinate == "y" else x)
):
numb_digit *= 10
step = step/numb_digit
finally_coordinate = x+step if name_coordinate == "x" else y+step
return finally_coordinate
def go_to_radius(init_x, init_y, radius):
array_coord_x = []
array_coord_y = []
for coordinate in ["x", "y"]:
local_coord = init_x if coordinate == "x" else init_y
init_coord = init_y if coordinate == "x" else init_x
array_coord = array_coord_x if coordinate == "x" else array_coord_y
for _ in range(radius):
local_coord = go_to_metr(
local_coord if coordinate == "x" else init_coord,
init_coord if coordinate == "x" else local_coord, coordinate)
array_coord.append(
(
(local_coord, init_coord)
) if coordinate == "x" else (
(init_coord, local_coord)
)
)
array_coord_all = []
for numb, _ in enumerate(range(len(array_coord_x))):
array_coord_all.append((array_coord_x[numb][0], array_coord_y[numb][1]))
return {
"coords_x": array_coord_x, "coords_y": array_coord_y,
"coords_all": array_coord_all
}
pprint(go_to_radius(55.880707, 37.55513, 5))
Вывод:
{'coords_all': [(55.880715, 37.55529),
(55.880723, 37.55545),
(55.880731000000004, 37.55561),
(55.88073100000001, 37.55577),
(55.88073100000009, 37.555930000000004)],
'coords_x': [(55.880715, 37.55513),
(55.880723, 37.55513),
(55.880731000000004, 37.55513),
(55.88073100000001, 37.55513),
(55.88073100000009, 37.55513)],
'coords_y': [(55.880707, 37.55529),
(55.880707, 37.55545),
(55.880707, 37.55561),
(55.880707, 37.55577),
(55.880707, 37.555930000000004)]}