- 1. Unit 3: Overview Of Transformation Mr. C. P. Divate Department Of Computer Engineering
- 2. Contents
- 3. Two Dimensional 2D Transformations What is transformations? a) The geometrical changes of an object from it’s current state to another modified state is known as transformation. b) “Transformations are the operations applied to existing geometrical data of an object to change its position, orientation, or size are called geometric transformations”.
- 4. Two Dimensional 2D Transformations Why the transformations are needed? • To manipulate the initially created object and to display the modified object without having to redraw it. • To Change the shape of object. • To Study the object surface details. • To Study the future and past changes in objects. • To modify old images. • To get mirror image / Reflections of object. • To change the color of objects. etc.
- 5. Two Dimensional 2D Transformations a) Translation- It is a process of Moving / shifting the position of an object from one location to another in a straight-line path. b) Rotation- It is a process rotating an object either • Around itself. • In clockwise or anti clockwise direction about any point on screen. c) Scaling- It is a process enlarging / Compressing an object size. d) Reflection- It is the process which gives mirror image of an object. e) Shearing- It is the process where object get distorted in different shape. f) Morphing- It is the process where object gets transit from between two shapes. g) Coloring- It is process where object gets colored. Types of Transformations?
- 6. Two Dimensional 2D Transformations Process of Transformation: It is a single step process in computer graphics where original object image is given as input to transformation process software and returns output as Transformed object image. Positional Vector: It is a representation of an original object image in computers memory. Usually represented in Matrix format (data structure). Process of Transformations • Translation • Rotation • Scaling • Reflection • Shearing • Morphing • Coloring Original object image Transformed image Positional Vector Transformed Vector Geometric Operation / (Multiplication) [T]
- 7. Two Dimensional 2D Transformations Geometric Operation: • All Transformations can be performed with Mathematical Techniques only. • In Computer Graphics transformations are performed with Matrix Calculations only. • Especially it uses Matrix Multiplication Operation to perform above transformations. • It has transformation matrix [ T ] of size 3 x 3 for each type of Transformation. • Translation • Rotation • Scaling • Reflection • Shearing • Morphing • Coloring Original object image Transformed image Positional Vector Transformed Vector Geometric Operation / (Multiplication) [T] Process of Transformations
- 8. Two Dimensional 2D Transformations Transformed Vector: It is a representation of an Transformed object image in computers memory. Usually represented in Matrix format (data structure). It has same matrix size as that of Positional Vector. • Translation • Rotation • Scaling • Reflection • Shearing • Morphing • Coloring Original object image Transformed image Positional Vector Transformed Vector Geometric Operation / (Multiplication) [T] Process of Transformations
- 9. Two Dimensional 2D Transformations Representation of Original Object / Positional Vector in Brain
- 10. Two Dimensional 2D Transformations Representation of Original Object / Positional Vector in Brain
- 11. Two Dimensional 2D Transformations Representation of Original Object / Positional Vector in Brain
- 12. Two Dimensional 2D Transformations Representation of Original Object / Positional Vector in Brain
- 13. Two Dimensional 2D Transformations Representation of Original Object / Positional Vector Why do we use matrix to represent Positional Vector? • More convenient organization of data. • More efficient processing • Enable the combination of various concatenations Example 1: Consider a single point object P then, the Positional Vector in matrix form is, as follows, P = 𝑥 𝑦 OR P = 𝒙 𝒚 P(x,y) Column Matrix Form Row Matrix Form Note: In this Presentation we use Row Matrix Form to show all Transformations
- 14. Two Dimensional 2D Transformations Representation of Original Object / Positional Vector Example 2: Consider a line object P1P2 then, the Positional Vector P in matrix form is, as follows, P = 𝒙𝟏 𝒚𝟏 OR P = 𝒙𝟏 𝒙𝟐 𝒚𝟏 𝒚𝟐 Column Matrix Form Row Matrix Form 𝒙𝟐 𝒚𝟐 Example 3: Consider a Triangle object ΔP1P2P3 then, the Positional Vector P in matrix form is, as follows, P = 𝒙𝟏 𝒚𝟏 𝒙𝟐 𝒚𝟐 𝒙𝟑 𝒚𝟑 OR P = 𝒙𝟏 𝒙𝟐 𝒙𝟑 𝒚𝟏 𝒚𝟐 𝒚𝟑 P1(x1,y1) P2(x2,y2) P3(x3,y3)
- 15. Two Dimensional 2D Transformations Homogeneous co-ordinate system Positional Vector Example 2: Consider a line object P1P2 P = 𝒙𝟏 𝒙𝟐 𝒚𝟏 𝒚𝟐 𝒛𝟏 𝒛𝟐 Example 3: Consider a Triangle object ΔP1P2P3 P = 𝒙𝟏 𝒙𝟐 𝒙𝟑 𝒚𝟏 𝒚𝟐 𝒚𝟑 • In 3D system there are three coordinates ( x, y, z ) to represent each pixel P. • When we perform 2D transformation it is must that all points of the objects lies in single plane i.e. z = 1. • When all pixels of the objects lies in same 2D plane e.g. z =1 the these pixels are known to be in homogeneous co-ordinate system. 𝒛𝟏 𝒛𝟐 𝒛𝟑 When Object pixels are in 3D Space When Object pixels are in Homogeneous Coordinate system z=1 plane P = 𝒙𝟏 𝒙𝟐 𝒚𝟏 𝒚𝟐 𝟏 𝟏 P = 𝒙𝟏 𝒙𝟐 𝒙𝟑 𝒚𝟏 𝒚𝟐 𝒚𝟑 𝟏 𝟏 𝟏 Note: In this Presentation we use Homogeneous PV to show all Transformations
- 16. Two Dimensional 2D Transformations Transformation Matrix / Geometric Operator [ T ] • In Computer Graphics it uses matrix multiplications to Perform any Transformations on set of points represented in positional vector [ P ]. • The Transformation matrix [ T ] is used to performed the desired Transformation. • It is assumed that two matrices are known i.e. [ P ] and [ T ] and these are the input for all transformations. • The Transformation Matrix [ T ] is of 3 X 3 size i.e. 3 rows and 3 col. • Following is the Transformation Matrix [ T ]. [ T ] = 𝒂 𝒅 𝒈 𝒃 𝒆 𝒉 𝒄 𝒇 𝒊 • The desired Transformation is obtained with multiplication of [ P ] and [ T ] matrices. i.e. [ P ] x [ T ] = [ R ]
- 17. Two Dimensional 2D Transformations Transformation Matrix / Geometric Operator [ T ] • The desired Transformation is obtained with multiplication of [ P ] and [ T ] matrices. i.e. [ P ] x [ T ] = [ R ] [ R ] = [ P ] . [ T ] = 𝒙𝟏 𝒙𝟐 𝒙𝟑 𝒚𝟏 𝒚𝟐 𝒚𝟑 𝟏 𝟏 𝟏 X 𝒂 𝒅 𝒈 𝒃 𝒆 𝒉 𝒄 𝒇 𝒊 R1 x 3 3 x C2 • The Size of Resultant Matrix [ R ] is R1 x C2
- 18. Two Dimensional 2D Transformations Transformation by Unit Matrix • If the Transformation Matrix [ T ] is Unit Matrix as follows. • The desired Transformation is obtained with multiplication of [ P ] and [ T ] matrices. i.e. [ P ] x [ T ] = [ R ] • Here Transformed Object is same as that of Original Object hence no transformation has done. • So Object has not transformed and remain as it is at original positions. • The Size of Resultant Matrix [ R ] is R1 x C2. [ T ] = 𝟏 𝟎 𝟎 𝟎 𝟏 𝟎 𝟎 𝟎 𝟏 𝟏 𝟏 𝟏 [ R ] = [ P ] . [ T ] = 𝒙𝟏 𝒙𝟐 𝒙𝟑 𝒚𝟏 𝒚𝟐 𝒚𝟑 X 𝟏 𝟎 𝟎 𝟎 𝟏 𝟎 𝟎 𝟎 𝟏 R1 x 3 3 x C2 = 𝒙𝟏 𝒙𝟐 𝒙𝟑 𝒚𝟏 𝒚𝟐 𝒚𝟑 𝟏 𝟏 𝟏 R1 x C2
- 19. Two Dimensional 2D Transformations 2D Scaling in Computer Graphics • In scaling, we can expend or compress the size of any object. • We can apply scaling on the object by multiplying the original coordinates with scaling factors Sx and Sy. • The term scaling factor is used to define whether the size of an object is increased or decreased. • We can represent the scaling factor by ‘Sx’ for the x-axis and ‘Sy’ for the y-axis. • The Scaling Transformation is obtained with multiplication of [ P ] and [ T ] matrices. i.e. [ P ] x [ T ] = [ R ]. • The Size of Resultant Matrix [ R ] is R1 x C2 𝟏 𝟏 𝟏 [ R ] = [ P ] . [ T ] = 𝒙𝟏 𝒙𝟐 𝒙𝟑 𝒚𝟏 𝒚𝟐 𝒚𝟑 X 𝑺𝒙 𝟎 𝟎 𝟎 𝑺𝒚 𝟎 𝟎 𝟎 𝟏 R1 x 3 3 x C2 = 𝑺𝒙 . 𝒙𝟏 𝑺𝒙 . 𝒙𝟐 𝑺𝒙 . 𝒙𝟑 𝑺𝒚 . 𝒚𝟏 𝑺𝒚 . 𝒚𝟐 𝑺𝒚 . 𝒚𝟑 𝟏 𝟏 𝟏 R1 x C2
- 20. Two Dimensional 2D Transformations 2D Scaling in Computer Graphics 𝟏 𝟏 𝟏 𝟏 [ R ] = [ P ] . [ T ] = 𝟏 𝟒 𝟒 𝟏 𝟒 𝟒 𝟏 𝟏 X 𝟑 𝟎 𝟎 𝟎 𝟒 𝟎 𝟎 𝟎 𝟏 R1 x 3 3 x C2 = 𝟑 𝟏𝟐 𝟏𝟐 𝟑 𝟏𝟔 𝟏𝟔 𝟒 𝟒 𝟏 𝟏 𝟏 𝟏 R1 x C2 • Example: A Square object with the coordinate points D (1, 4), C (4, 4), B (4, 1), A (1,1). • Apply the scaling factor 3 on the X-axis and 4 on the Y- axis. • Find out the new coordinates of the square?
- 21. Two Dimensional 2D Transformations 2D Scaling in Computer Graphics - Enlargement 𝟏 𝟏 𝟏 𝟏 [ R ] = [ P ] . [ T ] = 𝟏 𝟒 𝟒 𝟏 𝟒 𝟒 𝟏 𝟏 X 𝟑 𝟎 𝟎 𝟎 𝟒 𝟎 𝟎 𝟎 𝟏 R1 x 3 3 x C2 = 𝟑 𝟏𝟐 𝟏𝟐 𝟑 𝟏𝟔 𝟏𝟔 𝟒 𝟒 𝟏 𝟏 𝟏 𝟏 R1 x C2
- 22. Two Dimensional 2D Transformations 2D Scaling in Computer Graphics compression 𝟏 𝟏 𝟏 𝟏 [ R ] = [ P ] . [ T ] = 𝟏 𝟒 𝟒 𝟏 𝟒 𝟒 𝟏 𝟏 X 𝟏 𝟎 𝟎 𝟎 𝟎. 𝟐𝟓 𝟎 𝟎 𝟎 𝟏 4 x 3 3 x C2 = 𝟏 𝟒 𝟒 𝟏 𝟏 𝟏 𝟎. 𝟐𝟓 𝟎. 𝟐𝟓 𝟏 𝟏 𝟏 𝟏 R1 x C2 • Example: A Square object with the coordinate points D (1, 4), C (4, 4), B (4, 1), A (1,1). • Apply the scaling factor 1 on the X-axis and 0.25 on the Y- axis. • Find out the new coordinates of the square?
- 23. Two Dimensional 2D Transformations 2D Scaling in Computer Graphics - Compression 𝟏 𝟏 𝟏 𝟏 [ R ] = [ P ] . [ T ] = 𝟏 𝟒 𝟒 𝟏 𝟒 𝟒 𝟏 𝟏 X 𝟏 𝟎 𝟎 𝟎 𝟎. 𝟐𝟓 𝟎 𝟎 𝟎 𝟏 4 x 3 3 x C2 = 𝟏 𝟒 𝟒 𝟏 𝟏 𝟏 𝟎. 𝟐𝟓 𝟎. 𝟐𝟓 𝟏 𝟏 𝟏 𝟏 R1 x C2
- 24. Two Dimensional 2D Transformations 2D Scaling Rules in Computer Graphics T= identity matrix: a=e=i=1, b=c=d==f=g=h=0 Results for all x’ = x, y’ = y. Scaling Rules by parameters a and e : b=c=d==f=g=h=0 => x' = a.x, y' = e.y; This is scaling by a in x, d in y. • If, a = e > 1, we have enlargement (scale up) & uniform scaling. • If, a ≠ e > 1, we have enlargement (scale up) & non-uniform scaling. • If, 0 < a = e < 1, we have compression (scale down) & uniform scaling. • If, 0 < a ≠ e < 1, we have compression (scale down) & non-uniform scaling. Uniform Scaling by parameter i: a = e = 1 and b=c=d==f=g=h=0 • If, i > 1, we have compression (scale down) & uniform scaling. • If, i < 1, we have enlargement (scale up) & uniform scaling. • If, i = 1, we have [ T ] as Unit Matrix hence results for all x’ = x, y’ = y. [ T ] = 𝒂 𝒅 𝒈 𝒃 𝒆 𝒉 𝒄 𝒇 𝒊
- 25. Two Dimensional 2D Transformations 2D Scaling in Computer Graphics compression 𝟏 𝟏 𝟏 𝟏 [ R ] = [ P ] . [ T ] = 𝟏 𝟒 𝟒 𝟏 𝟒 𝟒 𝟏 𝟏 X 𝟏 𝟎 𝟎 𝟎 𝟏 𝟎 𝟎 𝟎 𝟐 4 x 3 3 x 3 = 𝟏 𝟒 𝟒 𝟏 𝟒 𝟒 𝟏 𝟏 𝟐 𝟐 𝟐 𝟐 4 x 3 • Example: A Square object with the coordinate points D (1, 4), C (4, 4), B (4, 1), A (1,1). Apply the scaling factor 2 on both axis. Find out the new coordinates of the square? Some Observations and Imaginations are,
- 26. Two Dimensional 2D Transformations 2D Scaling in Computer Graphics compression • Here Original object Matrix [ P ] is in One Homogeneous Co-ordinate Plane (z=1) plane. • And The Resultant object Matrix [ R ] which is of same size, lies in another Homogeneous Co-ordinate Plane (z=2) plane. • It is needed to bring Resultant object of [ R ] in the same plane of [ P ] i.e. z = 1 • Divide each row of [ R ] by third column element [ R ] = 𝟎. 𝟓 𝟐 𝟐 𝟎. 𝟓 𝟐 𝟐 𝟎. 𝟓 𝟎. 𝟓 𝟏 𝟏 𝟏 𝟏 𝟏 𝟒 𝟒 𝟏 𝟒 𝟒 𝟏 𝟏 𝟐 𝟐 𝟐 𝟐 [ R ] =
- 27. Two Dimensional 2D Transformations 2D Scaling in Computer Graphics compression [ R ] = 𝟎. 𝟓 𝟐 𝟐 𝟎. 𝟓 𝟐 𝟐 𝟎. 𝟓 𝟎. 𝟓 𝟏 𝟏 𝟏 𝟏
- 28. Two Dimensional 2D Transformations 2D Scaling in Computer Graphics compression 𝟏 𝟏 𝟏 𝟏 [ R ] = [ P ] . [ T ] = 𝟏 𝟒 𝟒 𝟏 𝟒 𝟒 𝟏 𝟏 X 𝟏 𝟎 𝟎 𝟎 𝟏 𝟎 𝟎 𝟎 𝟎. 𝟓 4 x 3 3 x 3 = 𝟏 𝟒 𝟒 𝟏 𝟒 𝟒 𝟏 𝟏 𝟎. 𝟓 𝟎. 𝟓 𝟎. 𝟓 𝟎. 𝟓 4 x 3 • Example: A Square object with the coordinate points D (1, 4), C (4, 4), B (4, 1), A (1,1). Apply the scaling factor 0.5 on both axis. Find out the new coordinates of the square? Some Observations and Imaginations are,
- 29. Two Dimensional 2D Transformations 2D Scaling in Computer Graphics compression • Here Original object Matrix [ P ] is in One Homogeneous Co-ordinate Plane (z=1) plane. • And The Resultant object Matrix [ R ] which is of same size, lies in another Homogeneous Co-ordinate Plane (z=0.5) plane. • It is needed to bring Resultant object of [ R ] in the same plane of [ P ] i.e. z = 1 • Divide each row of [ R ] by third column element [ R ] = 𝟐 𝟖 𝟖 𝟐 𝟖 𝟖 𝟐 𝟐 𝟏 𝟏 𝟏 𝟏 [ R ] = 𝟏 𝟒 𝟒 𝟏 𝟒 𝟒 𝟏 𝟏 𝟎. 𝟓 𝟎. 𝟓 𝟎. 𝟓 𝟎. 𝟓
- 30. Two Dimensional 2D Transformations 2D Scaling in Computer Graphics compression [ R ] = 𝟐 𝟖 𝟖 𝟐 𝟖 𝟖 𝟐 𝟐 𝟏 𝟏 𝟏 𝟏
- 31. Two Dimensional 2D Transformations 2D Reflection in Computer Graphics • It is a transformation which produces a mirror image of an object. • The mirror image can be either about x-axis or y-axis. • The object is rotated by180°. • Types of Reflection: a) Reflection about the x-axis (𝒓𝒙 = 1, 𝒓𝒚 = -1) b) Reflection about the y-axis (𝒓𝒙 = -1, 𝒓𝒚 = 1) c) Reflection about an axis perpendicular to xy plane and passing through the origin. (𝒓𝒙 = -1, 𝒓𝒚 = -1) d) Reflection about line y=x • Here 𝒓𝒚 , 𝒓𝒙 can be either -1 for reflection. • The Reflection Transformation is obtained with multiplication of [ P ] and [ T ] matrices. i.e. [ P ] x [ T ] = [ R ]. • The Size of Resultant Matrix [ R ] is R1 x C2. 𝟏 𝟏 𝟏 [ R ] = [ P ] . [ T ] = 𝒙𝟏 𝒙𝟐 𝒙𝟑 𝒚𝟏 𝒚𝟐 𝒚𝟑 X 𝒓𝒙 𝟎 𝟎 𝟎 𝒓𝒚 𝟎 𝟎 𝟎 𝟏 R1 x 3 3 x 3 = 𝒓𝒙. 𝒙𝟏 𝒓𝒙. 𝒙𝟐 𝒓𝒙. 𝒙𝟑 𝒓𝒚. 𝒚𝟏 𝒓𝒚. 𝒚𝟐 𝒓𝒚. 𝒚𝟑 𝟏 𝟏 𝟏 R1 x 3
- 32. Two Dimensional 2D Transformations 2D Reflection in Computer Graphics • 1. Reflection about x-axis: The object can be reflected about x-axis with the help of the following matrix • In this transformation value of x will remain same whereas the value of y will become negative. • The Reflection Transformation is obtained with multiplication of [ P ] and [ T ] matrices. i.e. [ P ] x [ T ] = [ R ]. • The Size of Resultant Matrix [ R ] is R1 x C2. 𝟏 𝟏 𝟏 [ R ] = [ P ] . [ T ] = 𝒙𝟏 𝒙𝟐 𝒙𝟑 𝒚𝟏 𝒚𝟐 𝒚𝟑 X 𝟏 𝟎 𝟎 𝟎 −𝟏 𝟎 𝟎 𝟎 𝟏 R1 x 3 3 x 3 = 𝒙𝟏 𝒙𝟐 𝒙𝟑 −𝒚𝟏 −𝒚𝟐 −𝒚𝟑 𝟏 𝟏 𝟏 R1 x C2 [ T ] = • Following figures shows the reflection of the object axis. • The object will lie another side of the x-axis
- 33. Two Dimensional 2D Transformations 2D Reflection in Computer Graphics • 2. Reflection about y-axis: The object can be reflected about y-axis with the help of following transformation matrix • In this transformation value of y will remain same whereas the value of x will become negative. • The Reflection Transformation is obtained with multiplication of [ P ] and [ T ] matrices. i.e. [ P ] x [ T ] = [ R ]. • The Size of Resultant Matrix [ R ] is R1 x C2. 𝟏 𝟏 𝟏 [ R ] = [ P ] . [ T ] = 𝒙𝟏 𝒙𝟐 𝒙𝟑 𝒚𝟏 𝒚𝟐 𝒚𝟑 X −𝟏 𝟎 𝟎 𝟎 𝟏 𝟎 𝟎 𝟎 𝟏 R1 x 3 3 x 3 = −𝒙𝟏 −𝒙𝟐 −𝒙𝟑 𝒚𝟏 𝒚𝟐 𝒚𝟑 𝟏 𝟏 𝟏 R1 x C2 • The following figure shows the reflection about the y-axis [ T ] =
- 34. Two Dimensional 2D Transformations 2D Reflection in Computer Graphics • 3. Reflection about an axis perpendicular to xy plane and passing through origin: • In this value of x and y both will be reversed. This is also called as half revolution about the origin. • The Reflection Transformation is obtained with multiplication of [ P ] and [ T ] matrices. i.e. [ P ] x [ T ] = [ R ]. • The Size of Resultant Matrix [ R ] is R1 x C2. 𝟏 𝟏 𝟏 [ R ] = [ P ] . [ T ] = 𝒙𝟏 𝒙𝟐 𝒙𝟑 𝒚𝟏 𝒚𝟐 𝒚𝟑 X −𝟏 𝟎 𝟎 𝟎 −𝟏 𝟎 𝟎 𝟎 𝟏 R1 x 3 3 x 3 = −𝒙𝟏 −𝒙𝟐 −𝒙𝟑 −𝒚𝟏 −𝒚𝟐 −𝒚𝟑 𝟏 𝟏 𝟏 R1 x C2 • The following figure shows the reflection about an axis perpendicular to xy plane [ T ] =
- 35. Two Dimensional 2D Transformations 2D Reflection in Computer Graphics • 3. Reflection about an axis perpendicular to xy plane and passing through origin: • In this value of x and y both will be reversed. This is also called as half revolution about the origin. • The Reflection Transformation is obtained with multiplication of [ P ] and [ T ] matrices. i.e. [ P ] x [ T ] = [ R ]. • The Size of Resultant Matrix [ R ] is R1 x C2. 𝟏 𝟏 𝟏 [ R ] = [ P ] . [ T ] = 𝒙𝟏 𝒙𝟐 𝒙𝟑 𝒚𝟏 𝒚𝟐 𝒚𝟑 X −𝟏 𝟎 𝟎 𝟎 −𝟏 𝟎 𝟎 𝟎 𝟏 R1 x 3 3 x 3 = −𝒙𝟏 −𝒙𝟐 −𝒙𝟑 −𝒚𝟏 −𝒚𝟐 −𝒚𝟑 𝟏 𝟏 𝟏 R1 x C2 • The following figure shows the reflection about an axis perpendicular to xy plane [ T ] =
- 36. Two Dimensional 2D Transformations 2D Reflection in Computer Graphics • 4. Reflection about line y=x: The object may be reflected about line y = x with the help of following transformation matrix • In this value of x and y both will be exchanged. This is also called as reflection about y=x line. • The Reflection Transformation is obtained with multiplication of [ P ] and [ T ] matrices. i.e. [ P ] x [ T ] = [ R ]. • The Size of Resultant Matrix [ R ] is R1 x C2. 𝟏 𝟏 𝟏 [ R ] = [ P ] . [ T ] = 𝒙𝟏 𝒙𝟐 𝒙𝟑 𝒚𝟏 𝒚𝟐 𝒚𝟑 X 𝟎 𝟏 𝟎 𝟏 𝟎 𝟎 𝟎 𝟎 𝟏 = 𝒚𝟏 𝒚𝟐 𝒚𝟑 𝒙𝟏 𝒙𝟐 𝒙𝟑 𝟏 𝟏 𝟏 R1 x C2 • The following figure shows the reflection about an x=y line [ T ] =
- 37. Two Dimensional 2D Transformations 2D Reflection in Computer Graphics Problem-01: Given a triangle with coordinate points A(3, 4), B(6, 4), C(5, 6). Apply the reflection on the X axis and obtain the new coordinates of the object. 𝟏 𝟏 𝟏 [ R ] = [ P ] . [ T ] = 𝟑 𝟔 𝟓 𝟒 𝟒 𝟔 X 𝟏 𝟎 𝟎 𝟎 −𝟏 𝟎 𝟎 𝟎 𝟏 R1 x 3 3 x 3 = 𝟑 𝟔 𝟓 −𝟒 −𝟒 −𝟔 𝟏 𝟏 𝟏 R1 x C2 Problem-02: Given a triangle with coordinate points A(3, 4), B(6, 4), C(5, 6). Apply the reflection on the X=Y Line to obtain the new coordinates of the object. 𝟏 𝟏 𝟏 [ R ] = [ P ] . [ T ] = 𝟑 𝟔 𝟓 𝟒 𝟒 𝟔 X 𝟎 𝟏 𝟎 𝟏 𝟎 𝟎 𝟎 𝟎 𝟏 R1 x 3 3 x 3 = 𝟒 𝟒 𝟔 𝟑 𝟔 𝟓 𝟏 𝟏 𝟏 R1 x C2 Problem-03: Given a triangle with coordinate points A(3, 4), B(6, 4), C(5, 6). Apply the reflection on the Y axis to obtain the new coordinates of the object.
- 38. Two Dimensional 2D Transformations 2D Translation in Computer Graphics • We can move any object from one to another place without changing the shape of the object. • Translation of a Point: If we want to translate a point from P (x0, y0) to Q (x1, y1), then we have to add Translation coordinates (Tx, Ty) with original coordinates. • The Translation Transformation is obtained with multiplication of [ P ] and [ T ] matrices. i.e. [ P ] x [ T ] = [ R ]. • The Size of Resultant Matrix [ R ] is R1 x C2. 𝟏 𝟏 𝟏 [ R ] = [ P ] . [ T ] = 𝒙𝟏 𝒙𝟐 𝒙𝟑 𝒚𝟏 𝒚𝟐 𝒚𝟑 X 𝟏 𝟎 𝑻𝒙 𝟎 𝟏 𝑻𝒚 𝟎 𝟎 𝟏 = 𝒙𝟏 + 𝑻𝒙 𝒙𝟐 + 𝑻𝒙 𝒙𝟑 + 𝑻𝒙 𝒚𝟏 + 𝑻𝒚 𝒚𝟐 + 𝑻𝒚 𝒚𝟑 + 𝑻𝒚 R1 x C2 • The following figure shows the translation from P to Q Pixel. 𝟏 𝟏 𝟏
- 39. Two Dimensional 2D Transformations 2D Rotation in Computer Graphics • 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 θ. • The Rotation Transformation is obtained with multiplication of [ P ] and [ T ] matrices. i.e. [ P ] x [ T ] = [ R ]. • The Size of Resultant Matrix [ R ] is R1 x C2. • After rotating it to a new location, you will get a new point P’ (X′,Y′).
- 40. Two Dimensional 2D Transformations 2D Anticlockwise Rotation in Computer Graphics • Using standard trigonometric the original coordinate of point P(X,Y) can be represented as − • X=rcosϕ......(1) • Y=rsinϕ......(2) • Same way we can represent the point P’ X′,Y′ as − • x′=rcos(ϕ+θ)=r cosϕcosθ−r sinϕsinθ.......(3) • y′=rsin(ϕ+θ)=r cosϕsinθ+r sinϕcosθ.......(4) • Substituting equation 1 & 2 in 3 & 4 respectively, we will get • x′ = xcosθ − ysinθ • y′ = xsinθ + ycosθ • Representing the above equation in matrix [ R ] =[ X Y ] x cos(θ) sin(θ) −sin(θ) cos(θ) 0 0 1 𝒄𝒐𝒔(θ) 𝒔𝒊𝒏(θ) −𝒔𝒊𝒏(θ) 𝟎 𝒄𝒐𝒔(θ) 𝟎 For Anti-clockwise Rotation [ T ]=
- 41. Two Dimensional 2D Transformations 2D Clockwise Rotation in Computer Graphics For clockwise Rotation • Consider Previous equations, • x′ = xcosθ − ysinθ .......(5) • y′ = xsinθ + ycosθ .......(6) • Substituting equation -θ in 5 & 6, we will get • x′ = xcos(-θ) − y sin(-θ) .......(5) • y′ = xsin(-θ) + ycos(-θ) .......(6) • Becomes, • x′ = xcosθ − ( - ysinθ) • y′ = -xsinθ + ycosθ • Results • x′ = xcosθ + ysinθ .......(7) • y′ = -xsinθ + ycosθ .......(8) • Representing the above equation in matrix form, [ R ] =[ X Y ] x cos(θ) −sin(θ) sin(θ) cos(θ) 0 0 1 𝒄𝒐𝒔(θ) −𝒔𝒊𝒏(θ) 𝒔𝒊𝒏(θ) 𝟎 𝒄𝒐𝒔(θ) 𝟎 For clockwise Rotation [ T ]=
- 42. Two Dimensional 2D Transformations 2D Shearing in Computer Graphics • A transformation that slants the shape of an object is called the shear transformation. • There are two shear transformations • X-Shear • Y-Shear. • X-Y Shear. • One shifts X coordinates values and other shifts Y coordinate values. • However in both the cases only one coordinate changes its coordinates and other preserves its values. • Shearing is also termed as Skewing.
- 43. Two Dimensional 2D Transformations 2D Shearing in Computer Graphics X-Shear: • The X-Shear preserves the Y coordinate and changes are made to X coordinates, which causes the vertical lines to tilt right or left as shown in below figure. The transformation matrix for X-Shear can be represented as − 𝟏 𝟏 𝟏 𝟏 𝑺𝒉𝒙 𝟎 𝟎 𝟏 𝟎 For X-Shear [ T ]=
- 44. Two Dimensional 2D Transformations 2D Shearing in Computer Graphics Y-Shear: • The Y-Shear preserves the X coordinates and changes the Y coordinates which causes the horizontal lines to transform into lines which slopes up or down as shown in the following figure. The transformation matrix for Y-Shear can be represented as − 𝟏 𝟏 𝟏 𝟏 𝟎 𝑺𝒉𝒚 𝟎 𝟏 𝟎 For Y-Shear [ T ]=
- 45. Two Dimensional 2D Transformations 2D Shearing in Computer Graphics X-Y-Shear: • The XY-Shear changes the X and Y coordinates which causes the horizontal and vertical lines to transform into lines which slopes up and down as shown in the following figure. The transformation matrix for Y-Shear can be represented as − 𝟏 𝟏 𝟏 𝟏 𝑺𝒉𝒙 𝑺𝒉𝒚 𝟎 𝟏 𝟎 For Y-Shear [ T ]=
- 46. Two Dimensional 2D Transformations Composite / Concatenation / Combined Transformation • If a transformation of the plane T1 is followed by a second plane transformation T2, then the result itself may be represented by a single transformation T which is the composition of T1 and T2 taken in that order. • This is written as T = [ T1 ] ∙ [ T2 ]. • Composite transformation can be achieved by concatenation of transformation matrices to obtain a combined transformation matrix. • A combined matrix − [ T ] = [ T1 ] [ T2 ] [ T3 ] [ T4 ] …. [ Tn ] • Where [Ti] is any combination of- Translation, Scaling, Shearing, Rotation, Reflection • The change in the order of transformation would lead to different results, as in general matrix multiplication is not cumulative, that is [A] . [B] ≠ [B] . [A] and the order of multiplication. • The basic purpose of composing transformations is to gain efficiency by applying a single composed transformation to a point, rather than applying a series of transformation, one after another.