2D Transformation PDF

Document Details

SpiritedMoldavite3541

Uploaded by SpiritedMoldavite3541

Bachelor of Computer Application

Tags

2D transformation computer graphics geometry mathematics

Summary

This document covers 2D transformations in computer graphics, including translation, rotation, and scaling. It provides equations and examples for these transformations. The document also touches upon homogenous coordinates.

Full Transcript

Unit 3 2D Transformation Introduction Transformations play an important role in computer graphics to reposition the graphics on the screen and change their size or orientation. 2D transformation means a change in either the position or orientati...

Unit 3 2D Transformation Introduction Transformations play an important role in computer graphics to reposition the graphics on the screen and change their size or orientation. 2D transformation means a change in either the position or orientation or size or shape of a graphics objects like line, circle, arc, ellipse, rectangle, polygon, polylines etc. Any manipulation done on an object is called a transformation. I.e. moving an object from one location to another location at a certain angle, resizing the object (maximizing or minimizing). It is utilized to modify the position, orientation or size of an object within a 2D space. There are two essential aspects of transformation: 1. Each transformation is a single entity. Denoted by a unique name or symbol. 2. It is possible to combine 2 transformations, after connecting a single transformation is obtained. There are 2 complimentary points to view for describing object transformation: 1. Geometric transformation: The object itself is transformed relative to the coordinate system or background. 2. Coordinate transformation: the object is held stationary while the coordinate system is transformed relative to the object. Transformation Techniques: The different transformation techniques are: 1. Translation 2. Rotation 3. Scaling 4. Reflection 5. Shear Homogenous Coordinates To perform a sequence of transformation such as translation followed by rotation and scaling, we need to follow a sequential process −  Translate the coordinates,  Rotate the translated coordinates, and then  Scale the rotated coordinates to complete the composite transformation. In a homogeneous co-ordinate system, we replace 2x2 dimensional matrix of coordinates (X, Y) by a 3×3 dimensional matrix of coordinates (X,Y,W). To convert a 2×2 matrix to 3×3 matrix, we have to add an extra dummy coordinate W. The relationship between these forms is given as: xh = x + w yh = y + w Translation: Translation is a process of changing or moving the position of an object in a straight line path from one coordinate location to another location in a two dimensional plane. Consider a point with coordinate P (x, y), we have to reposition this point P’(x’, y’). In order to do that, we need to know the distance with respect to x and y. Applying 2D translation, we get: x’ = x + tx y’ = y + ty Where x, y -> Original position x’, y’ -> New position tx, ty -> Translation distance also called as translation vector or shift vector. tx defines the distance the X coordinate has to be moved. ty defines the distance the Y coordinate has to be moved. This can also be written as: P’ = P + T The equations can be expressed using column vectors for efficient representation and computation. ***************************************************************************** Numerical Question: 1. Translate a polygon with coordinates A (2, 5), B(7, 10), C(10, 2) by 3 units in x axis and 4 units in y axis. Solution: Given A (2, 5) B (7, 10) C (10, 2) 3 units in x 4 units in y First plot the polygon for A, B and C 2. Given a circle C with radius 10 and center of coordinates (1, 4). Apply translation with distance 5 towards x-axis and 1 towards y-axis. Obtain the new coordinates of C without changing its radius. 3. Given a square with coordinate point A(0,3), B(3,3), C(3, 0), D(0,0). Apply translation with distance 1 towards x-axis and 1 towards y-axis. Obtain the new coordinate of the square. Scaling Scaling is a process of modifying or altering the size of objects. 2D Scaling in Computer Graphics involves resizing objects or coordinate systems in a 2D plane. It allows us to change the size of each point in the object or coordinate system by applying scaling factors in the x and y directions. 1. Scaling may be used to increase or reduce the size of object. 2. Scaling subjects the coordinate points of the original object to change. 3. Scaling factor determines whether the object size is to be increased or reduced. 4. If scaling factor > 1, then the object size is increased. 5. If scaling factor < 1, then the object size is reduced. Consider a point object O has to be scaled in a 2D plane. Let- Initial coordinates of the object O = (Xold, Yold) Scaling factor for X-axis = Sx Scaling factor for Y-axis = Sy New coordinates of the object O after scaling = (Xnew, Ynew) This scaling is achieved by using the following scaling equations- Xnew = Xold x Sx Ynew = Yold x Sy Or it can be written as P’ = P. S In Matrix form, the above scaling equations may be represented as- Numerical problems 1. Given a square object with coordinate points A(0, 3), B(3, 3), C(3, 0), D(0, 0). Apply the scaling parameter 2 towards X axis and 3 towards Y axis and obtain the new coordinates of the object. Given- Old corner coordinates of the square = A (0, 3), B (3, 3), C (3, 0), D (0, 0) Scaling factor along X axis = 2 Scaling factor along Y axis = 3 For Coordinates A(0, 3) Let the new coordinates of corner A after scaling = (Xnew, Ynew). Applying the scaling equations, we have- Xnew = Xold x Sx = 0 x 2 = 0 Ynew = Yold x Sy = 3 x 3 = 9 Thus, New coordinates of corner A after scaling = (0, 9). For Coordinates B(3, 3) Let the new coordinates of corner B after scaling = (Xnew, Ynew). Applying the scaling equations, we have- Xnew = Xold x Sx = 3 x 2 = 6 Ynew = Yold x Sy = 3 x 3 = 9 Thus, New coordinates of corner B after scaling = (6, 9). For Coordinates C(3, 0) Let the new coordinates of corner C after scaling = (Xnew, Ynew). Applying the scaling equations, we have- Xnew = Xold x Sx = 3 x 2 = 6 Ynew = Yold x Sy = 0 x 3 = 0 Thus, New coordinates of corner C after scaling = (6, 0). For Coordinates D(0, 0) Let the new coordinates of corner D after scaling = (Xnew, Ynew). Applying the scaling equations, we have- Xnew = Xold x Sx = 0 x 2 = 0 Ynew = Yold x Sy = 0 x 3 = 0 Thus, New coordinates of corner D after scaling = (0, 0). The New coordinates of the square after scaling = A (0, 9), B(6, 9), C(6, 0), D(0, 0). 2. Magnify a triangle placed ar A(0,0), B(1,1) and C(5,2) to twice its size. Rotation: 2D Rotation is a process of rotating an object with respect to an angle in a two dimensional plane. It enables us to rotate graphical elements around a specified point or axis by a certain angle. To perform a 2D rotation, we need to consider two key components: the rotation angle and the rotation center. The rotation angle, denoted as θ (in radians), represents the amount of rotation to be applied. The rotation center, represented as (cx, cy), defines the point around which the rotation will occur. Consider a point object O has to be rotated from one angle to another in a 2D plane. Let- Initial coordinates of the object O = (Xold, Yold) Initial angle of the object O with respect to origin = Φ Rotation angle = θ New coordinates of the object O after rotation = (Xnew, Ynew) We know that cos Φ = base/ Hypotenuse = x/r  x = r cos Φ sin Φ = Perpendicular / Hypotenuse = y/r  y = r sin Φ Now if we rotate the angle at θ degree cos (Φ + θ) = x’/r  x’ = r cos (Φ + θ) = r [cos Φ cos θ - sin Φ sin θ] = r cos Φ cos θ – r sin Φ sin θ sin (Φ + θ) = y’/r  y’ = r sin (Φ + θ) = r cosΦsin θ + r cosθ sinΦ  x’ = x cosθ - y sinθ [replacing r cosΦ with x and r sinΦ with y)  y’ = x sinθ + y cosθ In Matrix form, the above rotation equations may be represented as Numerical problems: 1. Given a line segment with starting point as (0, 0) and ending point as (4, 4). Apply 30 degree rotation anticlockwise direction on the line segment and find out the new coordinates of the line. Given- Old ending coordinates of the line = (Xold, Yold) = (4, 4) Rotation angle = θ = 30 o Let new ending coordinates of the line after rotation = (Xnew, Ynew). Applying the rotation equations, we have- Xnew = Xold x cosθ – Yold x sinθ = 4cos θ – 4sin θ = 4 x cos30o – 4 x sin30o = 4 x (√3 / 2) – 4 x (1 / 2) = 2√3 – 2 = 2(√3 – 1) {taking 2 as a common value) = 2(1.73 – 1) = 1.46 Ynew = Xold x sinθ + Yold x cosθ = 4 x sin30o + 4 x cos30o = 4 x (1 / 2) + 4 x (√3 / 2) = 2 + 2√3 = 2(1 + √3) {taking 2 as a common value) = 2(1 + 1.73) = 5.46 Thus, New ending coordinates of the line after rotation = (1.46, 5.46). Alternatively, In matrix form, the new ending coordinates of the line after rotation may be obtained as- Thus, New ending coordinates of the line after rotation = (1.46, 5.46). Shearing Shearing in 2D graphics refers to the distortion of the shape of an object by shifting some of its points in a particular direction. 2D Shearing is an ideal technique to change the shape of an existing object in a two dimensional plane. Shearing can be performed in two ways: 1. Shearing in X axis 2. Shearing in Y axis Consider a point object P has to be sheared in a 2D plane. Let- Initial coordinates of the object P = (x, y) Shearing parameter towards X direction = Shx Shearing parameter towards Y direction = Shy New coordinates of the object O after shearing = (x’, y’) Shearing in X Axis- Shearing in X axis is achieved by using the following shearing equations- X’ = x + Shx x y Y’ = y In Matrix form, the above shearing equations may be represented as- Shearing in Y Axis- Shearing in Y axis is achieved by using the following shearing equations- X’ = x Y’ = y + Shy x x In Matrix form, the above shearing equations may be represented as- ************************************************************************* Numerical Problems 1. Given A(2,2) B (1,1) C(3, 1). Apply shear parameter 1 on X axis and 1 on Y axis and find out the new coordinates of the object. Solution: Given, A (2,2) B (1,1) C (3, 1) Shx = 1 Shy = 1 Shearing in x-axis: A’: x' = 2+1x2 = 4 y’ = 2 B’: x’ = 1+1 x 1 = 2 y’ = 1 C’ x' = 3+1x1 = 4 y’ = 1 Shearing in y-axis: A’: x' = 2 y’ = 2+1x2 = 4 B’: x’ = 1 y’ = 1+1 x 1 = 2 C’ x' = 3 y’ = 1+1x3 = 4 ********************************************************** Difference between the rotation about the origin and the rotation about a local point Rotation about the origin: 1. Rotation about the Origin is a transformation that rotates or turns an object (e.g., a triangle) about the origin point (x, y) -> (0, 0). 2. When you rotate an object about the origin, every point on the shape rotates by a given angle around the origin and the shapes overall position changes relative to the coordinate plane. 3. You apply a rotation matrix to each point relative to the origin. The general 2D rotation matric for an angle θ is cos θ -sin θ sin θ cos θ When we multiply this matrix by the coordinate of each point (x, y), the entire object rotates about the origin. Rotation about a local point: 1. Rotation about a local point: an object is rotated around a specific point in space, which may be a point on or near the object. 2. When rotating around a local point, the object moves in a circular path around the specific point and its position relative to the global coordinate system changes differently compared to origin- based rotation. 3. This rotation is more complex because we must first translate the object so that the local point coincides with the origin, apply the rotation, and then translate the object back to its original position. 4. Rotation about a local point uses an arbitrary point.

Use Quizgecko on...
Browser
Browser