2D geometric transformations 3

Translation moves object from current position to another. Translation is defined by vector T = (X´-X, Y´-Y), where (X, Y) are coordinates of current position of the object and (X´, Y´) are coordinates of position after translating object.

Tranlation matrix may looks like this one:

Transformation which moves object around strict point along round trajectory is called Rotation. It is determined by angle of rotation and the mid-point of rotation.
Rotating point P[x, y] around the start-point of coordinates system O=[0, 0] by angle Alfa, we get new point P´ on coordinates [x´,y´]

x´= x*cos(alfa) - y*sin(alfa)
y´= x*sin(alfa) + y*cos(alfa)

Rotation matrix may looks like this one:

Putting the translation and rotation transformations together, we should for example rotate object around any point (I chose left down corner point of object).


Applet Angle is counted from positive X axis counter-clockwise in degrees. Applet internally works with radians. Rotation matrix shows values for left down corner of object. For transforming object, you must drag mouse. Angle for rotation is calculated from current mouse position in coordinates system, while dragging.

Source code