## 2D Transformations

### Translation

This transformation moves points of an object to a new specified position. Translation is defined by a vector of the shift p = (X1-X2, Y1-Y2), where (X1, Y1) are coordinates of the object in its first position and (X2, Y2) are its coordinates in the second position.

Translation matrix is  :

```      |  1  0  0 |
A = |  0  1  0 |
| tx ty  0 |
```

\$\$\$APPLET

Applet Translation with transformation matrix

### Rotation

Rotation can be described as circular motion about some axis, in this case the axis is one of the object's local axes. Transformation of an object around a static point on a circular trajectory is called rotation. It is defined by a rotation angle and rotation centre.

\$\$\$APPLET

Applet Rotation around angle  (in radian) with transformation matrix

After a rotation of point P[x, y] around the centre of co-ordinates system O=[0, 0] by angle alfa we will get a new point P' with coordinates

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

Matrix transformation for rotation is

```     | cos(alfa) sin(alfa) 0 |
Ao = |-sin(alfa) cos(alfa) 0 |
|    0          0     1 |
```

### Scaling

A change of scale also causes a change of object's size in the directions of the coordinates axes. If the coefficient of proportion of the new length to the old one is higher than 1 in a direction of one of the axes then the object will be prolonged, if the coefficient is lower than 1, then the object will be shortened.

The formule for the change of scale for the point P [x, y] is

x' = Sx * x
y' = Sy * y

The scaling equations are represented in matrix form as

```      | Sx  0  0 |
As = |  0 Sy  0 |
|  0  0  1 |
```

\$\$\$APPLET

Applet Scaling

### Symetry

Symetry can be a special case of scale change, where coefficients Sx and Sy get values 1 or -1.

 Sx Sy symetry along the x axis 1 -1 symetry along the y axis -1 1 symetry along the center -1 -1

\$\$\$APPLET

Applet Symetry along the y axis

### Shear transformations

Two-dimensional sheare transformations are of two kinds: a shear along the x axis and a shear along the y axis.

A transformations matrix on the form

```        |  1 Sy  0 |
Asxy = | Sx  1  0 |
|  0  0  1 |
```

\$\$\$APPLET

Applet Shear transformations.
If you want along the x axis select a point on x axis,
if along the y axis select a point on y axis.

### Composition of 2D transformations

When composing transformations, it is important not to change the right order of transformations. A transformations originated by composing of other ones, can be expressed by one matrix by gradual multiplication of matrix representing original partial transformations.

Copyright (c) 1999-2019 Juraj Štugel. www.netgraphics.sk