Sei sulla pagina 1di 7

2 D TRANSFORMATIONS

2D Transformations are editing operations like change in position, shape, size, orientation etc. of an object with respect to some point or its frame of reference. They are named so as the transformations take place in the same plane. Transformations can be broadly classified into the following: Geometry transformations: Changing the position, shape, size, etc. of the object with respect to a frame of reference. Coordinates transformations: Changing the frame of reference itself. TYPES OF 2D TRANSFORMATIONS: 1) Translation: It refers to the transfer of a point from one position to another along a straight-line path in the same frame of reference. We translate a 2D point by addi ng translation distances, tx and ty, to the original coordinate position. Transforming P(x,y) to P(x,y):

1) 2)

From the above diagram we get the coordinates of the new point P(x,y) as:

x = x + tx y = y + ty
Matrix representation of the above equations is as follows:

We convert the above matrix representation to Homogeneous Coordinate System so that later on, n processes or transformations can be combined into a single Composite transformation using only Multiplication as the operation. Hence, instead of calculating the matrix separately for each transformation for n processes, we can find out the final matrix by just one calculation, once we derive the composite matrix for the processes combined together. Homogeneous Coordinate System: A point P(x,y) in Cartesian Coordinate System can be represented in Homogeneous System as: P(x/h, y/h, h) where, h is known as the Homogeneous Factor.

For eg: (2,3) in Cartesian System can be written as (2,3,1) or (4,6,2) or (6,9,3) in Homogeneous System. Hence, the translation matrix using the Homogeneous Coordinates System can be written as follows:

Above is the matrix representation that will be used for all the calculations later on as it makes composite transformation simpler. 2) Scaling: It 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 the Scaling Factors, sx and sy, to produce the transformed coordinates (x,y) for each vertex. Hence, all the vertices are repositioned.

In the above Figure, the scaling factors are as follows: sx = 2, sy = 2

If the 2 scaling factors are equal, then it is called Uniform scaling. If the 2 are different then it is called Differential scaling (For eg: sx = 2, sx = 3). Hence, the scaling equations for each transformed vertex are: x = sx * x y = sy * y The above can be represented in the matrix form as follows:

As stated before, for composite transformations, we need to convert the above form to the Homogeneous Coordinates System. Hence the above can be written as:

In case the 2 operations of translation and scaling are performed together, the result of the below matrix multiplication will give us the composite matrix:

3) Rotation: It is applied to an object by repositioning it along a circular path in the xy-plane about the rotation point or the pivot point. Considering rotation of a point about the origin we have,

In the above figure a point P(x,y), at an angle , distant r from the origi n, has been rotated about the origin by angle in counter clockwise direction, hence giving the new point, P(x,y). For counter clockwise rotation, is considered to be positive and negative for clockwise rotation. For calculation for the coordinates of the new point P, from the figure we have the following: x = r cos( + ) = r cos cos - r sin sin (Using cos (a+b) = cos a.cos b sin a.sin b) y = r sin( + ) = r cos sin + r sin cos (Using sin (a+b) = sin a.cos b + cos a.sin b) From figure, x = r cos and y = r sin . Hence, we get the equations for rotation of a point about the origin as, x = x cos y sin y = x sin + y cos Converting the above to matrix multiplication form, we get,

Expressing the above in Homogeneous coordinate system, we get,

The above matrix is with respect to the origin. For any other point as reference, we need to apply a combination of the above 3 transformations to find out the actual result by using Composite matrix. Consider the following transformation:

We can perform the above transformation in 3 steps: 1. Shift the pivot of rotation to coincide with the origin using Translation.

2. Rotate the triangle about the origin as the pivot of rotation.

3. Inverse Translation to the previous points.

So we can combine the 3 steps into one by writing the composite matrix as a result of the following matrix multiplication,

Questions: Q1. Rotate a square with coordinates, (1,1), (2,1), (2,2), (2,1) by 45 in counter clockwise direction with respect to, (a) Origin (b) Center of the square, taking points as (1,1), (3,1), (3,3), (3,1) Ans. (a) Origin. Using the following,

Since rotation is counter clockwise, is taken to be positive. Also, cos 45 = sin 45 = 1/2. Hence we get,

Solving the above, we get,

Points : (0, 2), (1/2,3/2), (-1/2,3/2), (0,22). (b) For the coordinates, (1,1), (3,1), (3,3), (3,1), the center of the square comes out to be (2,2). Applying Translation (of center point (2,2) to origin; tx=-2,ty=-2), Rotation (=45) and then inverse translation (of center point of square back to (2,2); tx=2,ty=2), we get,

The new coordinates can be calculated as,

Solving the above we get the new points of the square as, Points : (2, 2-2), (2+2,2), (2-2,2), (2,2+2). Q2. A point (3,4) is rotated by 90 in clockwise direction and translated by 5 units along the X direction. Find the final coordinates. Ans. Here there are just 2 steps: 1. 2. Rotation of point by 90 in clockwise direction ( = -90). Translation by 5 units along X-direction (tx = 5, ty = 0). So we can find the final coordinates as follows:

(Using cos(-) = cos , sin(-) = -sin , cos 90 = 0, sin 90 = 1) Solving the above, we get the new coordinates as (9,-3). Q3. Scale the triangle with coordinates, (1,1), (5,1) and (3,5) along the X axis, such that the point (1,1) will not get disturbed and sx = 2 and sy = 3. Ans. During scaling, the coordinates of all the points of the object change as a result of resizing. So, in order to keep the vertex (1,1) of the triangle constant, that vertex needs to be shifted to the origin, as origin never changes its position. Hence, the steps to be performed here are: 1. 2. 3. Translate (1,1) to origin (tx=-1, ty=-1) Scale the triangle (sx=2, sy=3). Inverse translation to bring the left most vertex back to (1,1). (tx=1, ty=1). The above steps can be performed mathematically as follows:

Solving the above expression, we get the new coordinates of the triangle as

(1,1), (9,1), (5,13).

Potrebbero piacerti anche