Похожие чаты

Any way to make it more performant? def get_points_between_2_points(

point_1: tuple[int, int], point_2: tuple[int, int]
) -> np.ndarray:
"""Return an array of coordinates of points that lie on the line between
two given points.
"""

x1, y1 = np.array(point_1).astype(int)
x2, y2 = np.array(point_2).astype(int)

# Calculate the slope of the line
if x1 == x2:
# Handle the special case where the line is vertical
x_coords: np.ndarray = np.full(abs(y2 - y1) + 1, x1)
y_coords: np.ndarray = np.arange(min(y1, y2), max(y1, y2) + 1)
else:
slope: float = (y2 - y1) / (x2 - x1)
intercept: float = y1 - slope * x1

# Calculate the coordinates of the points on the line
x_coords: np.ndarray = np.arange(min(x1, x2), max(x1, x2) + 1)
y_coords: np.ndarray = np.around(slope * x_coords + intercept).astype(
int
)

# Combine the x and y coordinates into a single array
points: np.ndarray = np.column_stack((x_coords, y_coords))

# Remove duplicate points
points: np.ndarray = np.unique(points, axis=0)

# Sort the points by distance from the first input point
distances: np.ndarray = np.linalg.norm(points - point_1, axis=1)
sorted_indices: np.ndarray = np.argsort(distances)
points: np.ndarray = points[sorted_indices]

return points.astype(int)

2 ответов

8 просмотров

To post more than a few lines of code, use a pastebin like: * dpaste.org * linkode.org * bin.kv2.dev * hastebin.com If you are stuck in a terminal, you can use ix.io or paste.rs to paste from the CLI: <command to print output> |& curl -F 'f:1=<-' ix.io <command to print output> |& curl --data-binary @- https://paste.rs

Tushar- Автор вопроса

Похожие вопросы

Обсуждают сегодня

generic procedure function test<T>(param: T); type case T of longint: NewT = word; longword: NewT = byte; end; var v1: NewT; Как это можно сделать? Чтобы у меня...
notme
21
Интересно, нет ли какого-то способа получить из dll не адрес самой метки, а адрес со смещением?
The Bird of Hermes
54
Делал задачу вот такую https://stepik.org/lesson/4985/step/9?unit=1083 получилось такое https://play.haskell.org/saved/ipKrepqe оно работает, тестов много не писал, но работае...
Fedor
22
Whoa, did you guys see this FUNToken Seed Grant announcement? 💸
Noah Noure
37
hello guys, I have a laptop, if you connect wired headphones, the sound will come from the headphones and the built-in speakers AT THE SAME TIME. How can I make the sound com...
El Pepe
21
Всем привет, все время юзал бандлы, но появилась задача по базовому образу и команда werf build не пушит образ werf build --config='./root/werf.yaml' --repo ${CI_REGISTRY_IMAG...
Илья Корж
4
hello, does someone have a good cheat sheet (max 2 sides of A4 paper sheet) for C only? I need it to cover most useful function for math, dynamic memory, strings, files (I/O),...
狐 - えんきどぅ
19
А можно как-нибудь включить default'ные настройки ядра?
Ari
26
There is a week left before the distribution of ANVL, gentlemen, why is there almost no news about this event on the Internet? Who is so bad at marketing a project ?
GDC
9
День GPO прям сегодня. Можно как-то через GPO запретить пользователю сохранять на рабочий стол файлы *.exe? Запретить запускать могу. А вот сохранять... На файловом сервер мог...
Dmitriy
16
Карта сайта