I'm trying to rotate a polygon around its center. To make things easy, I positioned it in the origin of the canvas so that I don't have to translate it back and forth. This is the rotation function I came up with:
"""
rotates robot's vertices around its center point
"""
# configure angle parameters
angle = np.deg2rad(phi)
rotated_vertices = []
for vertex in vertices:
# translate points to the origin
x_new = vertex[0]
y_new = vertex[1]
x_new = x_new*np.cos(angle) - y_new*np.sin(angle)
y_new = x_new*np.sin(angle) + y_new*np.cos(angle)
rotated_vertices.append([x_new, y_new])
return rotated_vertices
This applies a simple rotation to each vertex (x, y) in a set of vertices that make up the polygon. As I start to increase the angle of rotation, the shape begin to get distorted until it ends up being a line. I have the samples below:
Rotations angle = 0
Rotation angle = 50
Rotation angle = 70

Thank you in advance. I'm not sure what I'm doing wrong
Well, you update the xnew first then use the rotated xnew to compute ynew, and that's where it goes wrong.
Instead, do something like
Also, a few points here: you are already using numpy, so why don't you just define a rotation matrix and and use numpy's matmul? That would usually avoid time waste on such error:
Also, for any abstraction of the geometric operation, I would suggest shapely. For your problem here, with
shapelyyou only need a few lines to utilize its affine transformation