Is it possible to write a function in python that could rotate any 2d structure with the arguments being only the coordinates (x,y) of the points in the structure? Additional arguments would be included for axis, speed and direction.
To my understanding it would only be possible by calculating point distance from symmetrical points and the axis and therefore it would always vary and is thus impossible except for 2d structures made up of standard shapes (triangles, rectangles, squares etc)
Good examples would be appreciated.
I have written such a function to use in pygame before. It is kinda self-explanatory but feel free to ask the parts that require clarification. Here is my code:
import math def rotatePolygon(polygon,theta): """Rotates the given polygon which consists of corners represented as (x,y), around the ORIGIN, clock-wise, theta degrees""" theta = math.radians(theta) rotatedPolygon =  for corner in polygon : rotatedPolygon.append(( corner*math.cos(theta)-corner*math.sin(theta) , corner*math.sin(theta)+corner*math.cos(theta)) ) return rotatedPolygon my_polygon = [(0,0),(1,0),(0,1)] print rotatePolygon(my_polygon,90)
[(0.0, 0.0), (6.123233995736766e-17, 1.0), (-1.0, 6.123233995736766e-17)]
Which is nearly
I also have a function that rotates the given point(x,y) around another one. I share it in case you find it useful (And you can combine these two functions to rotate the polygon around another point rather than the origin):
def rotatePoint(centerPoint,point,angle): """Rotates a point around another centerPoint. Angle is in degrees. Rotation is counter-clockwise""" angle = math.radians(angle) temp_point = point-centerPoint , point-centerPoint temp_point = ( temp_point*math.cos(angle)-temp_point*math.sin(angle) , temp_point*math.sin(angle)+temp_point*math.cos(angle)) temp_point = temp_point+centerPoint , temp_point+centerPoint return temp_point print rotatePoint((1,1),(2,2),45)
This will print
(1.0, 2.414213562373095),which is equal to
(Note that this one is counter-clockwise)