Transformation (Translation, Rotation and Scaling) of a two dimensional objects in C/C++
1. Translation
A translation is applied to an object by repositioning it along a straight-line path from one coordinate location to another. We translate a two-dimensional point by adding translation distances, tx and ty, to the original coordinate position (x,y) to move the point to a new position (x’, y’)
x’ = x + tx,         y’ = y + ty
The translation distance pair (tx, ty) is called a translation vector or shift vector. In matrix form, the translation of a two-dimensional object can be written as

2. Rotation

A two-dimensional rotation is applied to an object by repositioning it along a circular path in the xy plane. To generate a rotation, we specify a rotation angle ? and the position (xr, yr) of the pivot point about which the object is to be rotated. In general Pivot – Point rotation, there are 3 steps to rotate an object about pivot point,
1. Translate the object so that the pivot-point position is moved to the coordinate origin.
2. Rotate the object about the coordinate origin.
3. Translate the object so that the pivot point is returned to its original position.

The composite transformation matrix for this process is

3. Scaling
A scaling transformation alters the size of an object. This operation can be carried out for polygons by multiplying the coordinate values (x, y) of each vertex by scaling factors sx and sy to produce the transformed coordinates (x’, y’). In General Fixed – Point Scaling, there are 3 steps to scale an object about the fixed point,

1. Translate object so that the fixed point coincides with the coordinate origin.
2. Scale the object with respect to the coordinate origin.
3. Use the inverse translation of step 1 to return object to its original position.

The composite transformation matrix for this process is

Source code

Output (Modified)

Related Article

destination source:https://www.programming-techniques.com/?p=121

```