A transformation is a function that maps every position (x, y) into a new position (x', y'). Instead of applying the transformation function to every point in every line that makes up the object, we simply apply the function to the object vertices and then draw new lines between the resulting new endpoints.
Basic Transformations:
1)Translation
2)Scaling
3)Rotation
1)Translation:
A translation is applied to an object by repositioning it along a straight-line path from one coordinate location to another. Translation refers to the shifting (moving) of a point to some other place, whose distance with regard to the present point is known. Translation can be defined as “the process of repositioning an object along a straight line path from one co-ordinate location to new co-ordinate location.” A translation moves an object to a different position on the screen. You can translate a point in 2D by adding translation coordinate (tx, ty) to the original coordinate (X, Y) to get the new coordinate (X', Y')
From the above Fig. you can write that:
X' = X + tx
Y' = Y + ty
The pair (tx, ty) is called the translation vector or shift vector. The above
equations can also be represented using the column vectors.
P = [X] [Y] p'
= [X] [Y] T = [tx] [ty]
We can write it as,
P' = P + T
Rotation
Rotation as the name suggests is to rotate a point about an axis. The axis can be any of the co-ordinates or simply any other specified line also. In rotation, we rotate the object at particular angle θ (theta) from its origin. From the following figure, we can see that the point P(X, Y) is located at angle φ from the horizontal X coordinate with distance r from the origin. Let us, suppose you want to rotate it at the angle θ. After rotating it to a new location, you will get a new point P' (X', Y').
Using standard trigonometric the original coordinate of point P(X, Y) can be
represented as:
X = r cos ф (1)
Y = r sin ф (2)
Same way we can represent the point P' (X', Y') as:
x′ = r cos (ф + θ) = r cos ф cos θ − r sin ф sin θ (3)
y′ = r sin (ф + θ) = r cos ф sin θ + r sin ф cos θ (4)
Substituting equation (1) and (2) in (3) and (4) respectively, we will get
x′ = x cos θ − y sin θ
y′ = x sin θ + y cos θ
Representing the above equation in matrix form,
The rotation angle can be positive and negative.
Scaling:
Scaling means to change the size of object. This change can either be positive or negative. To change the size of an object, scaling transformation is used. In the scaling process, you either expand or compress the dimensions of the object. Scaling can be achieved by multiplying the original co-ordinates of the object with the scaling factor to get the desired result. Let us assume that the original co-ordinates are (X, Y), the scaling factors are (SX, SY), and the produced co-ordinates are (X', Y'). This can be mathematically represented as shown below:
X' = X .SX and Y' = Y .SY
The scaling factor SX, SY scales the object in X and Y direction respectively.
The above equations can also be represented in matrix form as below:
Where, S is the scaling matrix.
If we provide values less than 1 to the scaling factor S, then we can reduce the size of the object. If we provide values greater than 1, then we can increase the size of the object.