Computer Graphics Lecture 4 Geometry Transformations Computer Graphics

  • Slides: 36
Download presentation
Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics Some Basics • Basic geometric types. – Scalars s – Vectors v

Computer Graphics Some Basics • Basic geometric types. – Scalars s – Vectors v – Points p = p + s * v • Transformations – Types of transformation: rotation, translation, scale. – Matrix representation – Order • Geometric modelling – Hierarchical modelling – Polyhedral shapes. 7/10/2008 Lecture 4 2

Computer Graphics Transformations. What is a transformation? • P =T(P) Why use them? •

Computer Graphics Transformations. What is a transformation? • P =T(P) Why use them? • Modelling - Create objects in natural/convenient coordinates - Multiple instances of a prototype shape - Kinematics of linkages/skeletons - robot animation • Viewing – Windows and device independence – Virtual camera: parallel and perspective projections 7/10/2008 Lecture 4 3

Computer Graphics Types of Transformations Continuous (preserves neighbourhoods) One to one, invertible Classify by

Computer Graphics Types of Transformations Continuous (preserves neighbourhoods) One to one, invertible Classify by invariants or symmetries Isometry (distance preserved) – Reflections (interchanges left-handed and righthanded) – Rigid body motion: Rotations + Translations Similarity (preserves angles) – Uniform scale Affine (preserves parallel lines) – Non-uniform scales, shears or skews Collineation (lines remain lines) – Perspective Non-linear (lines become curves) – Twists, bends, warps, morphs, . . . 7/10/2008 Lecture 4 4

Computer Graphics 2 D Translations. P’ P 7/10/2008 Lecture 4 5

Computer Graphics 2 D Translations. P’ P 7/10/2008 Lecture 4 5

Computer Graphics 2 D Scaling from the origin. P’ P 7/10/2008 Lecture 4 6

Computer Graphics 2 D Scaling from the origin. P’ P 7/10/2008 Lecture 4 6

Computer Graphics 2 D Rotation about the origin. y P’(x’, y’) P(x, y) r

Computer Graphics 2 D Rotation about the origin. y P’(x’, y’) P(x, y) r r x 7/10/2008 Lecture 4 7

Computer Graphics 2 D Rotation about the origin. y P’(x’, y’) P(x, y) r

Computer Graphics 2 D Rotation about the origin. y P’(x’, y’) P(x, y) r y r x x 7/10/2008 Lecture 4 8

Computer Graphics 2 D Rotation about the origin. y P’(x’, y’) P(x, y) r

Computer Graphics 2 D Rotation about the origin. y P’(x’, y’) P(x, y) r y r x x 7/10/2008 Lecture 4 9

Computer Graphics 2 D Rotation about the origin. Substituting for r : Gives us

Computer Graphics 2 D Rotation about the origin. Substituting for r : Gives us : 7/10/2008 Lecture 4 10

Computer Graphics 2 D Rotation about the origin. Rewriting in matrix form gives us

Computer Graphics 2 D Rotation about the origin. Rewriting in matrix form gives us : 7/10/2008 Lecture 4 11

Computer Graphics Transformations. • Translation. – P =T + P • Scale – P

Computer Graphics 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. 7/10/2008 Lecture 4 12

Computer Graphics Homogeneous coordinates • Add an extra coordinate, W, to a point. –

Computer Graphics 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. • At least one component must be non-zero (0, 0, 0) is not defined. • 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. 7/10/2008 Lecture 4 13

Computer Graphics Homogeneous coordinates • If we represent (x, y, W) in 3 -space,

Computer Graphics Homogeneous coordinates • If we represent (x, y, W) in 3 -space, all triples representing the same point describe a line passing through the origin. • If we homogenize the point, we get a point of form (x, y, 1) – homogenised points form a plane at W=1. W P W=1 plane X Y 7/10/2008 Lecture 4 14

Computer Graphics Translations in homogenised coordinates • Transformation matrices for 2 D translation are

Computer Graphics Translations in homogenised coordinates • Transformation matrices for 2 D translation are now 3 x 3. 7/10/2008 Lecture 4 15

Computer Graphics Concatenation. • We perform 2 translations on the same point: 7/10/2008 Lecture

Computer Graphics Concatenation. • We perform 2 translations on the same point: 7/10/2008 Lecture 4 16

Computer Graphics Concatenation. Matrix product is variously referred to as compounding, concatenation, or composition

Computer Graphics Concatenation. Matrix product is variously referred to as compounding, concatenation, or composition 7/10/2008 Lecture 4 17

Computer Graphics Concatenation. Matrix product is variously referred to as compounding, concatenation, or composition.

Computer Graphics Concatenation. Matrix product is variously referred to as compounding, concatenation, or composition. This single matrix is called the Coordinate Transformation Matrix or CTM. 7/10/2008 Lecture 4 18

Computer Graphics Properties of translations. Note : 3. translation matrices are commutative. 7/10/2008 Lecture

Computer Graphics Properties of translations. Note : 3. translation matrices are commutative. 7/10/2008 Lecture 4 19

Computer Graphics Homogeneous form of scale. Recall the (x, y) form of Scale :

Computer Graphics Homogeneous form of scale. Recall the (x, y) form of Scale : In homogeneous coordinates : 7/10/2008 Lecture 4 20

Computer Graphics Concatenation of scales. 7/10/2008 Lecture 4 21

Computer Graphics Concatenation of scales. 7/10/2008 Lecture 4 21

Computer Graphics Homogeneous form of rotation. 7/10/2008 Lecture 4 22

Computer Graphics Homogeneous form of rotation. 7/10/2008 Lecture 4 22

Computer Graphics Orthogonality of rotation matrices. 7/10/2008 Lecture 4 23

Computer Graphics Orthogonality of rotation matrices. 7/10/2008 Lecture 4 23

Computer Graphics Other properties of rotation. 7/10/2008 Lecture 4 24

Computer Graphics Other properties of rotation. 7/10/2008 Lecture 4 24

Computer Graphics Types of transformations. • Rotation and translation – Angles and distances are

Computer Graphics 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. – Affine transformations. 7/10/2008 Lecture 4 25

Computer Graphics 3 D Transformations. • Use homogeneous coordinates, just as in 2 D

Computer Graphics 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 Note: Convenient to think of display as Being left-handed !! ( z into the screen ) z (out of page) 7/10/2008 Lecture 4 26

Computer Graphics Translation in 3 D. Simple extension to the 3 D case: 7/10/2008

Computer Graphics Translation in 3 D. Simple extension to the 3 D case: 7/10/2008 Lecture 4 27

Computer Graphics Scale in 3 D. Simple extension to the 3 D case: 7/10/2008

Computer Graphics Scale in 3 D. Simple extension to the 3 D case: 7/10/2008 Lecture 4 28

Computer Graphics Rotation in 3 D • Need to specify which axis the rotation

Computer Graphics Rotation in 3 D • Need to specify which axis the rotation is about. • z-axis rotation is the same as the 2 D case. 7/10/2008 Lecture 4 29

Computer Graphics Rotation in 3 D • For rotation about the x and y

Computer Graphics Rotation in 3 D • For rotation about the x and y axes: 7/10/2008 Lecture 4 30

Computer Graphics Rotation about an arbitrary axis? • • Hard! But we know how

Computer Graphics Rotation about an arbitrary axis? • • Hard! But we know how to rotate about the major axes. So turn required rotation into one about major axis. We need to translate arbitrary axis a to pass through origin, rotate to align with major axis, perform rotation, and rotate and translate back to original position. • Say Mz is the compound transformation to translate and rotate a to align with z-axis, then Mz-1 is the reverse transformation required to restore a to its original position. • Ignore translation for present, a passes through origin…. . 7/10/2008 Lecture 4 31

Computer Graphics How do we define M? M transforms a into a vector along

Computer Graphics How do we define M? M transforms a into a vector along the z-axis, ie. Ma = k Construct the rotation matrix R(a) as follows: Ra (a) = M-1 Rz(a)M A suitable M-1 can be found with a little effort, ie. M-1 k = a First define axis direction a as a unit vector as: a = (a 1, a 2, a 3) = Rz(- )Rx(- )k = (sin , sin cos , cos ) Thus: 7/10/2008 and: Lecture 4 32

Computer Graphics Rotation about arbitrary axis So: M-1 = Rz(- )Rx(- ) and therefore:

Computer Graphics Rotation about arbitrary axis So: M-1 = Rz(- )Rx(- ) and therefore: M = Rx( )Rz( ) And the full expression for a rotation about an arbitrary axis is: Ra(a) = T-1 Rz(- )Rx(- )Rz(a)Rx( )Rz( )T Example: consider axis through origin, Thus = 45 o and = 0 o and Ra(a) = Rx(-45 o)Rz(a)Rx(45 o) 7/10/2008 Lecture 4 33

Computer Graphics Transformations of coordinate systems. • Have been discussing transformations as transforming points.

Computer Graphics Transformations of coordinate systems. • Have been discussing transformations as transforming points. • Useful to think of them as a change in coordinate system. • Model objects in a local coordinate system, and transform into the world system. • Unrealistic to think all objects are defined in the same coordinate system. 7/10/2008 Lecture 4 34

Computer Graphics Transformations of coordinate systems. 7/10/2008 Lecture 4 35

Computer Graphics Transformations of coordinate systems. 7/10/2008 Lecture 4 35

Computer Graphics Transform Left-Right, Right-Left Transforms between world coordinates and viewing coordinates. That is:

Computer Graphics Transform Left-Right, Right-Left Transforms between world coordinates and viewing coordinates. That is: between a right-handed set and a lefthanded set. 7/10/2008 Lecture 4 36