我目前正在编写一个算法,该算法沿不同多边形的边界和由 shapely 制作的线串进行迭代。当我使用使用缓冲区制作的圆形时,这很好用,但是当我制作方形时,我得到的点太少了。
这张图基本上展示了我所拥有的和我想要的:
我想我以前在这里见过类似的东西,但我再也找不到了。
from shapely.geometry import Point, LineString, Polygon
from shapely import affinity
def my_shape(position, scale):
x, y = position[0], position[1]
angle = - position[2]
width = 30 * scale
length = 50 * scale
x_min, x_max = x - width / 2, x + width / 2
y_min, y_max = y - length / 2, y + length / 2
left_behind, right_behind = (x_min, y_min), (x_max, y_min)
left_front, right_front = (x_min, y_max), (x_max, y_max)
coordinates = [right_front, right_behind, left_behind, left_front]
my_polygon = Polygon(coordinates)
my_polygon_rot = affinity.rotate(my_polygon, angle, 'center')
return my_polygon_rot