Computer Graphics Lecture 2 Transformations 021009 Lecture 4
- Slides: 55
Computer Graphics Lecture 2 Transformations 02/10/09 Lecture 4 1
Transformations. What is a transformation? • P =T(P) What does it do? Transform the coordinates / normal vectors of objects Why use them? • Modelling -Moving the objects to the desired location in the environment -Multiple instances of a prototype shape -Kinematics of linkages/skeletons – character animation • Viewing – Virtual camera: parallel and perspective projections 7/10/2008 Lecture 4 2
Types of Transformations – Geometric Transformations • Translation • Rotation • scaling • Linear (preserves parallel lines) • Non-uniform scales, shears or skews – Projection (preserves lines) • Perspective projection • Parallel projection – Non-linear (lines become curves) • Twists, bends, warps, morphs, 7/10/2008 Lecture 4 3
Geometric Transformation – Once the models are prepared, we need to place them in the environment – Objects are defined in their own local coordinate system – We need to translate, rotate and scale them to put them into the world coordinate system 9/10/2020 Lecture 1 4
2 D Translations. P’ P 7/10/2008 Lecture 4 5
2 D Scaling from the origin. P’ P 7/10/2008 Lecture 4 6
2 D Rotation about the origin. y P’(x’, y’) P(x, y) r r x 7/10/2008 Lecture 4 7
2 D Rotation about the origin. y P’(x’, y’) P(x, y) r y r x x 7/10/2008 Lecture 4 8
2 D Rotation about the origin. y P’(x’, y’) P(x, y) r y r x x 7/10/2008 Lecture 4 9
2 D Rotation about the origin. Substituting for r : Gives us : 7/10/2008 Lecture 4 10
2 D Rotation about the origin. Rewriting in matrix form gives us : 7/10/2008 Lecture 4 11
Transformations. • Translation. – P =T + P • Scale – P =S P • Rotation – P =R P • We would like all transformations to be multiplications so we can concatenate them • express points in homogenous coordinates. 02/10/09 Lecture 4 12
Homogeneous coordinates • Add an extra coordinate, W, to a point. – P(x, y, W). • Two sets of homogeneous coordinates represent the same point if they are a multiple of each other. – (2, 5, 3) and (4, 10, 6) represent the same point. • If W 0 , divide by it to get Cartesian coordinates of point (x/W, y/W, 1). • If W=0, point is said to be at infinity. 02/10/09 Lecture 4 13
Translations in homogenised coordinates • Transformation matrices for 2 D translation are now 3 x 3. 02/10/09 Lecture 4 14
Concatenation. • When we perform 2 translations on the same point 02/10/09 Lecture 4 15
Concatenation. Matrix product is variously referred to as compounding, concatenation, or composition 02/10/09 Lecture 4 16
Concatenation. Matrix product is variously referred to as compounding, concatenation, or composition. 02/10/09 Lecture 4 17
Properties of translations. Note : 3. translation matrices are commutative. 02/10/09 Lecture 4 18
Homogeneous form of scale. Recall the (x, y) form of Scale : In homogeneous coordinates : 02/10/09 Lecture 4 19
Concatenation of scales. 02/10/09 Lecture 4 20
Homogeneous form of rotation. 02/10/09 Lecture 4 21
Orthogonality of rotation matrices. 02/10/09 Lecture 4 22
Other properties of rotation. 02/10/09 Lecture 4 23
How are transforms combined? Scale then Translate (1, 1) (2, 2) Scale(2, 2) Translate(3, 1) (5, 3) (3, 1) (0, 0) Use matrix multiplication: p' = T ( S p ) = TS p TS = 1 0 3 0 1 1 0 0 1 2 0 0 0 1 = 2 0 3 0 2 1 0 0 1 Caution: matrix multiplication is NOT commutative! 02/10/09 Lecture 4 24
Non-commutative Composition Scale then Translate: p' = T ( S p ) = TS p (1, 1) (2, 2) Scale(2, 2) Translate(3, 1) (5, 3) (3, 1) (0, 0) Translate then Scale: p' = S ( T p ) = ST p (8, 4) (1, 1) Translate(3, 1) (4, 2) (3, 1) Scale(2, 2) (6, 2) (0, 0) 02/10/09 Lecture 4 25
Non-commutative Composition Scale then Translate: p' = T ( S p ) = TS p TS = 1 0 3 0 1 1 0 0 1 2 0 0 0 1 = 2 0 3 0 2 1 0 0 1 Translate then Scale: p' = S ( T p ) = ST p ST = 02/10/09 2 0 0 0 1 1 0 3 0 1 1 0 0 1 Lecture 4 = 2 0 6 0 2 2 0 0 1 26
How are transforms combined? Rotate then Translate (1, 1) Rotate 45 deg (0, sqrt(2)) (3, sqrt(2)) Translate(3, 0) (0, 0) (3, 0) Translate then Rotate (1, 1) (0, 0) Translate(3, 0) Rotate 45 deg (0, 0) (3/sqrt(2), 3/sqrt(2)) (3, 0) Caution: matrix multiplication is NOT commutative! 02/10/09 Lecture 4 27
Non-commutative Composition Rotate then Translate: p' = T ( R p ) = TR p TR = 1 0 3 0 1 1 0 0 1 0 -1 0 0 0 0 1 0 -1 3 0 0 1 0 -1 0 0 0 0 1 1 0 3 0 1 1 0 -1 -1 1 0 3 0 0 1 = Translate then Rotate: p' = R ( T p ) = RT p RT = 02/10/09 0 0 1 Lecture 4 = 28
Types of transformations. • Rotation and translation – Angles and distances are preserved – Unit cube is always unit cube – Rigid-Body transformations. • Rotation, translation and scale. – Angles & distances not preserved. – But parallel lines are. 02/10/09 Lecture 4 29
Transformations of coordinate systems. • Have been discussing transformations as transforming points. • Always need to think the transformation in the world coordinate system • Sometimes this might not be so convenient – i. e. rotating objects at its location 02/10/09 Lecture 4 30
Transformations of coordinate systems - Example • Concatenate local transformation matrices from left to right • Can obtain the local – world transformation matrix • p’, p’’’ are the world coordinates of p after each transformation 02/10/09 Lecture 4 31
Transformations of coordinate systems - example • is the world coordinate of point p after n transformations 02/10/09 Lecture 4 32
Quiz • I sat in the car, and realized the side mirror is 0. 4 m on my right and 0. 3 m in my front • I started my car and drove 5 m forward, turned 30 degrees to right, moved 5 m forward again, and turned 45 degrees to the right, and stopped • What is the position of the side mirror now, relative to where I was sitting in the beginning? 02/10/09 Lecture 4 33
Solution • The side mirror position is locally (0, 4, 0. 3) • The matrix of first driving forward 5 m is 02/10/09 Lecture 4 34
Solution • The matrix to turn to the right 30 and 45 degrees (rotating -30 and -45 degrees around the origin) are 02/10/09 Lecture 4 35
Solution The local-to-global transformation matrix at the last configuration of the car is The final position of the side mirror can be computed by TR 1 TR 2 p which is around (2. 89331, 9. 0214) 02/10/09 Lecture 4 36
This is convenient for character animation / robotics • In robotics / animation, we often want to know what is the current 3 D location of the end effectors (like the hand) • Can concatenate matrices from the origin of the body towards the end effecter 02/10/09 Lecture 4 37
Transformations of coordinate systems. 02/10/09 Lecture 4 38
3 D Transformations. • Use homogeneous coordinates, just as in 2 D case. • Transformations are now 4 x 4 matrices. • We will use a right-handed (world) coordinate system - ( z out of page ). y x z (out of page) 02/10/09 Lecture 4 39
Translation in 3 D. Simple extension to the 3 D case: 02/10/09 Lecture 4 40
Scale in 3 D. Simple extension to the 3 D case: 02/10/09 Lecture 4 41
Rotation in 3 D • Need to specify which axis the rotation is about. • z-axis rotation is the same as the 2 D case. 02/10/09 Lecture 4 42
Rotating About the x-axis Rx( ) 02/10/09 Lecture 4 43
Rotating About the y-axis Ry( ) 02/10/09 Lecture 4 44
Rotation About the z-axis Rz( ) 02/10/09 Lecture 4 45
Rotation about an arbitrary axis y Rotate(k, θ) θ • About (ux, uy, uz), a unit vector on an arbitrary axis u z x uxux(1 -c)+c uzux(1 -c)-uzs uxuz(1 -c)+uys 0 x' y' uyux(1 -c)+uzs uzux(1 -c)+c uyuz(1 -c)-uxs 0 = uzux(1 -c)-uys uyuz(1 -c)+uxs uzuz(1 -c)+c 0 z' 0 0 0 1 1 x y z 1 where c = cos θ & s = sin θ 02/10/09 Lecture 4 46
Rotation • Not commutative if the axis of rotation are not parallel 02/10/09
Shearing 02/10/09 Lecture 4 48
Calculating the world coordinates of all vertices • For each object, there is a local-to-global transformation matrix • So we apply the transformations to all the vertices of each object • We now know the world coordinates of all the points in the scene 02/10/09 Lecture 4 49
Normal Vectors • We also need to know the direction of the normal vectors in the world coordinate system • This is going to be used at the shading operation • We only want to rotate the normal vector • Do not want to translate it 02/10/09 Lecture 4 50
Normal Vectors - (2) • We need to set elements of the translation part to zero 02/10/09 Lecture 4 51
Viewing • Now we have the world coordinates of all the vertices • Now we want to convert the scene so that it appears in front of the camera 02/10/09 Lecture 4 52
View Transformation We want to know the positions in the camera coordinate system We can compute the camera-to-world transformation matrix using the orientation and translation of the camera from the origin of the world coordinate system Mc→w 02/10/09 Lecture 4 53
View Transformation We want to know the positions in the camera coordinate system vw = Mc→w vc Point in the camera coordinate Camera-to-world Point in the world coordinate transformation vc = M -1 c→w vw = Mw→c vw 02/10/09 Lecture 4 54
Summary. • Transformations: translation, rotation and scaling • Using homogeneous transformation, 2 D (3 D) transformations can be represented by multiplication of a 3 x 3 (4 x 4) matrix • Multiplication from left-to-right can be considered as the transformation of the coordinate system • Need to multiply the camera matrix from the left at the end • Reading: Foley et al. Chapter 5, Appendix 2 sections A 1 to A 5 for revision and further background (Chapter 5) 02/10/09 Lecture 4 55
- Computer graphics
- Dot matrix display ppt
- 01:640:244 lecture notes - lecture 15: plat, idah, farad
- Angel
- Define viewing in computer graphics
- Plasma panel in computer graphics
- In two dimensional viewing we have?
- Shear transformation in computer graphics
- Glsl asin
- Define scan conversion in computer graphics
- Rigid body definition
- What are two different region filling algorithms
- Dda algorithm advantages and disadvantages
- Polygon filling algorithm
- Random vs raster scan
- Computer graphics
- Lines in computer graphics
- Cs 418
- Cs 418 interactive computer graphics
- Introduction to hidden surface removal
- Achromatic light in computer graphics
- Interactive input methods
- Uniform scaling in computer graphics
- Uniform scaling in computer graphics
- Orthogonal projection in computer graphics
- Logical input devices in computer graphics
- Sierpinski gasket in computer graphics
- Points and lines in computer graphics ppt
- Ellipse drawing algorithm in computer graphics ppt
- Dda in computer graphics
- In two dimensional viewing system have
- Keyframe system in computer graphics
- Solid examples
- Scan conversion in computer graphics
- 8 connected boundary fill algorithm
- Boundary representation in computer graphics
- Thick primitives in computer graphics
- Interaction in computer graphics
- Computer graphics
- Computer graphics pipeline
- Scan conversion of ellipse in computer graphics
- Srgp in computer graphics
- Types of transformation in computer graphics
- Gupta-sproull algorithm
- Uniform scaling in computer graphics
- Computer
- Input of graphical data in computer graphics
- Active edge table in computer graphics
- Warping in computer graphics
- Warping in computer graphics
- Frame yv
- Edge table in computer graphics
- Filled vs unfilled polygon in computer graphics
- How to draw a line in computer graphics
- Bundled attributes in computer graphics ppt
- Objectives of computer graphics