Rectangle Rotation in Python/Pygame
        Posted  
        
            by 
                mramazingguy
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by mramazingguy
        
        
        
        Published on 2012-01-20T21:20:46Z
        Indexed on 
            2012/07/09
            21:15 UTC
        
        
        Read the original article
        Hit count: 297
        
Hey I'm trying to rotate a rectangle around its center and when I try to rotate the rectangle, it moves up and to the left at the same time. Does anyone have any ideas on how to fix this?
def rotatePoint(self, angle, point, origin):
    sinT = sin(radians(angle))
    cosT = cos(radians(angle))
    return (origin[0] + (cosT * (point[0] - origin[0]) - sinT * (point[1] - origin[1])),
                  origin[1] + (sinT * (point[0] - origin[0]) + cosT * (point[1] - origin[1])))
def rotateRect(self, degrees):
    center = (self.collideRect.centerx, self.collideRect.centery)
    self.collideRect.topleft = self.rotatePoint(degrees, self.collideRect.topleft, center)
    self.collideRect.topright = self.rotatePoint(degrees, self.collideRect.topright, center)
    self.collideRect.bottomleft = self.rotatePoint(degrees, self.collideRect.bottomleft, center)
    self.collideRect.bottomright = self.rotatePoint(degrees, self.collideRect.bottomright, center)
© Stack Overflow or respective owner