![]() |
VOOZH | about |
We can use a 2 × 2 matrix to change or transform, a 2D vector. This kind of operation, which takes in a 2-vector and produces another 2-vector by a simple matrix multiplication, is a linear transformation.
By this simple formula, we can achieve a variety of useful transformations, depending on what we put in the entries of the matrix. For our purposes, consider moving along the x-axis a horizontal move and along the y-axis, a vertical move.
A scaling transformation alters size of an object. In the scaling process, we either compress or expand the dimension of the object. Scaling operation can be achieved by multiplying each vertex coordinate (x, y) of the polygon by scaling factor sx and sy to produce the transformed coordinates as (x', y'). So, x' = x * sx and y' = y * sy. The scaling factor sx, sy scales the object in X and Y direction respectively. So, the above equation can be represented in matrix form: Or P' = S . P Scaling process: 👁 Image
Note: If the scaling factor S is less than 1, then we reduce the size of the object. If the scaling factor S is greater than 1, then we increase size of the object. Algorithm:
1. Make a 2x2 scaling matrix S as: Sx 0 0 Sy 2. For each point of the polygon. (i) Make a 2x1 matrix P, where P[0][0] equals to x coordinate of the point and P[1][0] equals to y coordinate of the point. (ii) Multiply scaling matrix S with point matrix P to get the new coordinate. 3. Draw the polygon using new coordinates.
Below is C implementation:
Output:
For Shearing
Output:
Code For Rotation
Output:
Translation