5 Basic 2D Transformations
T. Raghuveera
Objectives:
- To get introduced to the fundamental transformations Translation, Rotation, Scaling
- To understand the use of Homogeneous coordinates that make transformations simpler.
Discussion:
Any changes done to the properties of objects are called transformations. Transformations can be classified as ‘Geometric’, and ‘Attribute’. Geometric Transformations involve changes to the structural properties of objects, while attribute transformations involve changes to color, style and so on. For Ex: consider a line, whose geometric properties are position, size, shape, and orientation while its attributes arecolor, style (dashed, dot-dash patterns etc.).
Basic Transformations are classified as
- Translation(change is position)
- Rotation(change in orientation)
- Scaling(change in size)
There are other transformations which are less often performed, and they are classified as below. Many complex transformations can be broken into a series of simple or basic transformations.
Other Transformations
- Reflection
- Shearing
- Transformations Between Coordinate Systems
The other transformations are such that they can be represented assome combination of basic transformations.Let’s start our discussion with the first basic transformation, the Translation.
Translation (change in position):
As shown in the diagram above, Translation involves change in position of an object. Assume a point initially positioned at P(x,y), It is moved to a new position P’(x’,y’). To reach point P’ from point P, the amount of horizontal distance travelled along x-axis would be (x’-x) and the amount of vertical distance travelled along y-axis would be (y’-y). These two distances can be called as translational distances Tx and Tyrespectively along X-axis and Y-axis. Now we can represent the transformation, Translation in simple equations as
x’=x+Tx
y’=y+Ty
For convenience of implementation in a program, these are converted to matrix equivalent representations as below.
The notation for Translation can be given as
P’=P+T
where P’ represents the final position of the point P and T is the translation matrix.
Rotation (change in orientation):
Let’s understand how Rotation transformation is performed. Rotation is a transformation that is performed with respect to a pivot point by some angle.After rotation, the object is placed at a new position. A standard rotation is generally performed with respect to origin. We can choose any random point in space as pivot point and perform rotation.
As shown, Let P(x,y) be the point to be rotated about origin (pivot point), by an angleq (rotation angle), so that the point P, after rotation is at P’ (x’,y’) position. Let r be the radius vector.Here the direction from origin along P is identified as position vector of point P. Let q be the angle between position vectors of the points P and P’. Let Øbe the angle made by position vector of point P with X-axis. So the angle made by position vector point P’ with X-axis will be (Ø + q). Our aim is compute the coordinates of P’ in terms of other parameters P, r, Ø, q.
Scaling (change in size):
Consider a rectangular object (The filled blue square as shown in the middle in the above figure), which is to be scaled.Increase in size is considered as ‘upscaling’ while decrease in size is considered as ‘down scaling’. The farthest object is the up scaled object and the object close to origin is the down scaled version of the original object. If you observe scaling closely, it involves two transformations (change in size and change in position), as evident from the figure above, the up scaled object has moved to a new position away from the origin while the down scaled object has moved close to origin. Scaling is simply multiplying the object with values one along X-axis and one along Y-axis, i.e.,
x’=x.Sx
y’=y.Sy
whereSx, Sy are scaling factors along x and y axes respectively.
Sx= Sy = 1 (No Scaling)
Sx= Sy (Uniform Scaling)
Sx≠Sy (Non-Uniform Scaling)
Sx ,Sy> 1 (Up scaling)
Sx ,Sy< 1 (Down scaling)
Thus scaling transformation can be represented in matrix form as
The notation representation for scaling transformation is given by
P=S(Sx,Sy).P
Imp. Note:Scaling for point is meaningless (since it is dimensionless quantity), for lines,scaling is less relevant, because, it is one dimensional (length) and so scaling may be understood as increase or decrease inlength.Scaling is relevant for 2D and higher dimension objects.
Scaling can also be understood as holding the object and stretching or squeezing it along x-direction and y-direction by the scaling factors Sx,S yrespectively. Scaling involves not only change in size but also change in position. Standard scaling is performed with respect to origin and the above equations are valid only in this case. If scaling is to be performed with respect to another fixed position, then the equations would be different. Also observe, for a rectangular object if scaling is to be performed with respect to its left corner vertex, then the objects size changes, the positions of other vertices would also change except the left corner vertex. Similarly if scaling has to be performed with respect to say midpoint, then the object expands or contracts with respect to its mid-point.
Now putting all the three transformations together we have
When transformations are performed, with respect to points other than origin, the equations would be different than what we have already derived, and they will assume a form as below i.e., for rotation, and scaling an additional 2×1 matrix whose elements (shown as ? in the matrices below) will be derived later.
Let the additional matrix for rotation, scaling transformations performed with respect to any other point in space be denoted as Mr and Ms respectively.So we can rewrite the notations for the three basic transformations as shown below, intentionally, the notation for translation is altered to include a 2×2 identity matrix multiplying P.
P’=I.P+T
P’=R(q).P+Mr
P’=S(Sx,Sy).P+Ms
Intentionally, the notation for translation is altered to include a 2×2 Identity matrix multiplying P, such that all the three transformations have one common form, i.e.,each transformation involves a matrix multiplication and a matrix addition.
Homogeneous coordinates:
When a series of transformations are to be performed (ex:animation) say T, R,S,T in succession on an object, We have to give the initial coordinates for T, perform a multiplication and an addition, store the result and pass it to R and repeat the process. So there are 8 matrix operations and 3 intermediate storages.This is simplified by Homogeneous coordinatesand Homogeneous transformation matrices.
A Homogeneous coordinate system is an imaginary 3 dimensional coordinate system, with the three coordinates as (Xh, Yh, h), where h is called the homogeneous coordinate and h can take any numerical value.
To convert between Cartesian and Homogeneous coordinates, the relation is given
by
(X, Y) ↔ (Xh, Yh, h)
When h=1, X=Xhand Y=Yh and the relation becomes (X, Y) ↔ (X, Y, 1)
That is when h=1, the Cartesian coordinates in 2D can be represented as homogeneous coordinates with an additional 1 for the homogeneous coordinates.
Our aim is to simplify transformations, by representing data in homogeneous coordinates, performall computations, and while plotting the results are converted back to the Cartesian domain. But by choosing ‘h’ as 1, the conversion from homogeneous to Cartesian is as simple as discarding the third coordinate 1.
Advantages of Homogeneous representation:
- A series of transformations can be represented as matrix multiplications.
- Given the initial coordinates, the final coordinates can be computed easily by using composite matrix.
- No. of matrix operations are reduced.
- Storage of intermediate results is not required.
Let’s have a closer look at the advantages mentioned above. The first one, says that, when many transformations are to be performed in succession, we can simply multiply them in that order. This matrix obtained by multiplying many matrices is called a ‘composite matrix’.Now get the initial coordinates, multiply with composite matrix, and get final coordinates in just one multiplication step. Thus the other advantages mentioned become obvious.
Summary:
- Learnt how basic 2D transformations viz., Translation, Rotation, Scaling are performed
- Also understood how homogeneous coordinates help reduce no. of matrix operations.
you can view video on Basic 2D Transformations |