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

translation
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
Rotation
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
Scaling
Source code

Output (Modified)

Output

SHARE Transformation (Translation, Rotation and Scaling) of a two dimensional objects in C/C++

You may also like...

7 Responses

  1. Hello Bibek, you're codin skills are top notch, you are truly passionate about programming, and I admire that of you.

    I was hoping if you can do a C version of this program, cause in class I have to present this topics but the annoying teacher that I have wants it to be compiled on C, so I was wondering if you wouldn't mind doing a C version of this same program.

    Again, thank you so much for providing this tutorials 🙂

  2. What is the matrix for 3D Rotation with Pivot point and 3D Scaling with Pivot point?

  3. well thanks for sharing the program is running successfully.
    Nice share bro.

  4. Anonymous says:

    can this run on ubantu?

  5. No you can't. This program runs only on Windows platform.

  6. Please can you explain why we taken Xf(1-Sx) and Yf(1-Sy) in composite transformation matrix? what does that calculations means?

Leave a Reply

Your email address will not be published. Required fields are marked *

Share