Rotate 2d Polygon Without Changing Its Position
I've got this code: class Vector2D(object): def __init__(self, x=0.0, y=0.0): self.x, self.y = x, y def rotate(self, angle): angle = math.radians(angle)
Solution 1:
You're rotating around 0/0
, not around its center. Try moving the polygon before rotating, such that its center is 0/0
. Then rotate it, and finally move it back.
For instance, if you only need movement of vertices/polygons for this particular case, you could probably simply adjust rotate
to be:
defrotate(self, angle):
center = self.center()
for point inself.points:
point.x -= center.x
point.y -= center.y
point.rotate(angle)
point.x += center.x
point.y += center.y
Post a Comment for "Rotate 2d Polygon Without Changing Its Position"