Transformaions are a fundamental part of computer graphics.

A point is represented by (x,y). And for each transformation i will write a function that will take in the edges, the origin(if needed) and the transform factors and will return the new transformed edges.

Here, i am demonstrating the 4 main types of transformations that one can perform in 2 dimensions:

1. Translations

2. Scaling

3. Rotation

4. Shearing

#### Translations

void translation( int figure[], int edges, int dx, int dy ) { for(int i=0; i < edges; i++) { figure[2*i] += dx; figure[2*i+1] += dy; } } |

**Click here to see the example usage**.

#### Scaling

void scale( int figure[], int edges, int dx, int dy, int cx, int cy ) { for(int i=0; i < edges; i++) { figure[2*i] = (figure[2*i] - cx) * dx + cx; figure[2*i+1] = (figure[2*i+1] - cy) * dy + cy; } } |

**Click here to see the example usage**.

#### Rotation

void rotate( int figure[], int edges, double angle, int cx, int cy ) { double x, y; angle = -1 * (angle*3.14/180); double cos_a = cos(angle); double sin_a = sin(angle); for(int i=0; i < edges; i++) { x = figure[2*i] - cx; y = figure[2*i+1] - cy; figure[2*i] = floor( (x * cos_a) - (y * sin_a) + cx + 0.5 ); figure[2*i+1] = floor( (x * sin_a)+(y * cos_a) + cy + 0.5 ); } } |

**Click here to see the example usage**.

### Shearing

Check back later.

nice tutoral…..