Q:

python rotating a point counterclockwise by an angle

I have this method that rotates a point counter clockwise.
def rotate(self, rad):
    self.x = math.cos(rad)*self.x - math.sin(rad)*self.y
    self.y = math.sin(rad)*self.x + math.cos(rad)*self.y

but when i pass it a point to rotate, only the x coordinate is rotated correctly. For example I tried to rotate the point (0,25) by π/3 . I should be getting (-22,13) since i am rounding the answers. Instead I am getting (-22,-6).

A:

The Problem here is that you save the new value for self.x and use that same value as input for the calculation of self.y
Try this:
def rotate(self, rad):
    x = math.cos(rad)*self.x - math.sin(rad)*self.y
    self.y = math.sin(rad)*self.x + math.cos(rad)*self.y
    self.x = x

