I'm currently writing an algorithm that iterates along the boundary of different polygons and linestrings made with shapely. This works fine when I use circular shapes made using buffer, but when I make square shapes I get too few points to work with.
This picture shows basically what I have and what I want:
I think I have seen something like this here before, but I have not been able to find it again.
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