2 D TRANSFORMATIONS 2 D Transformations What is

  • Slides: 54
Download presentation
2 D TRANSFORMATIONS

2 D TRANSFORMATIONS

2 D Transformations �What is transformations? �The geometrical changes of an object from a

2 D Transformations �What is transformations? �The geometrical changes of an object from a current state to modified state. �Why the transformations is needed? �To manipulate the initially created object and to display the modified object without having to redraw it.

2 D Transformations � 2 ways �Object Transformation � Alter the coordinates descriptions an

2 D Transformations � 2 ways �Object Transformation � Alter the coordinates descriptions an object � Translation, rotation, scaling etc. � Coordinate system unchanged �Coordinate transformation � Produce a different coordinate system

Matrix Math �Why do we use matrix? �More convenient organization of data. �More efficient

Matrix Math �Why do we use matrix? �More convenient organization of data. �More efficient processing �Enable the combination of various concatenations �Matrix addition and subtraction a b c d = a c b d

Matrix Math �How about it? � a b c e d f �Matrix Multiplication

Matrix Math �How about it? � a b c e d f �Matrix Multiplication �Dot product a c b d . e g f = a. e + b. g h c. e + d. g a. f + b. h c. f + d. h

Matrix Math �What about this? 1 2. 1 3 2 3 . 1 3

Matrix Math �What about this? 1 2. 1 3 2 3 . 1 3 �Type of matrix a b Row-vector 2 = 1 6 6 2 1 a b Column-vector

Matrix Math �Is there a difference between possible representations? éa b ù é e

Matrix Math �Is there a difference between possible representations? éa b ù é e ù éae + bf ù ê ú·ê ú = ê + ú ë c d û ë f û ë ce df û [e éa b ù f ]· ê ú = [ae + cf ëc d û be + df ] [e éa c ù f ]· ê ú = [ae + bf ëb d û ce + df ]

Matrix Math �We’ll use the column-vector representation for a point. �Which implies that we

Matrix Math �We’ll use the column-vector representation for a point. �Which implies that we use pre-multiplication of the transformation – it appears before the point to be transformed in the equation.

Translation � A translation moves all points in an object along the same straight-line

Translation � A translation moves all points in an object along the same straight-line path to new positions. � The path is represented by a vector, called the translation or shift vector. � We can write the components: p'x = px + tx p'y = py + ty � or in matrix form: P' = P + T tx x’ x y’ = y + ty ? ty=4 (2, 2) tx= 6

Rotation �A rotation repositions all points in an object along a circular path in

Rotation �A rotation repositions all points in an object along a circular path in the plane centered at the pivot point. �First, we’ll assume the pivot is at the origin. P’ P

Rotation • Review Trigonometry => cos = x/r , sin = y/r • x

Rotation • Review Trigonometry => cos = x/r , sin = y/r • x = r. cos , y = r. sin => cos ( + ) = x’/r • x’ = r. cos ( + ) • x’ = r. cos -r. sin • x’ = x. cos – y. sin =>sin ( + ) = y’/r y’ = r. sin ( + ) • y’ = r. cos sin + r. sin cos • y’ = x. sin + y. cos P’(x’, y’) r y’ x’ P(x, y) r y x Identity of Trigonometry

Rotation • We can write the components: p'x = px cos – py sin

Rotation • We can write the components: p'x = px cos – py sin p'y = px sin + py cos P’(x’, y’) • or in matrix form: P' = R • P • can be clockwise (-ve) or counterclockwise (+ve as our example). • Rotation matrix y’ x’ P(x, y) r x y

Rotation �Example �Find the transformed point, P’, caused by rotating P= (5, 1) about

Rotation �Example �Find the transformed point, P’, caused by rotating P= (5, 1) about the origin through an angle of 90.

Scaling • Scaling changes the size of an object and involves two scale factors,

Scaling • Scaling changes the size of an object and involves two scale factors, Sx and Sy for the xand y- coordinates respectively. • Scales are about the origin. • We can write the components: p'x = sx • px p'y = sy • py or in matrix form: P' = S • P Scale matrix as: P’ P

Scaling • If the scale factors are in between 0 and 1 the points

Scaling • If the scale factors are in between 0 and 1 the points will be moved closer to the origin the object will be smaller. • Example : • P(2, 5), Sx = 0. 5, Sy = 0. 5 • Find P’ ? P(2, 5) P’

Scaling • If the scale factors are in between 0 and 1 the points

Scaling • If the scale factors are in between 0 and 1 the points will be moved closer to the origin the object will be smaller. • Example : • P(2, 5), Sx = 0. 5, Sy = 0. 5 • Find P’ ? • If the scale factors are larger than 1 the points will be moved away from the origin the object will be larger. • Example : • P(2, 5), Sx = 2, Sy = 2 • Find P’ ? P’ P(2, 5) P’

Scaling • If the scale factors are the same, Sx = Sy uniform scaling

Scaling • If the scale factors are the same, Sx = Sy uniform scaling • Only change in size (as previous example) • If Sx Sy differential scaling. • Change in size and shape • Example : square rectangle • P(1, 3), Sx = 2, Sy = 5 , P’ ? P’ P(1, 2) What does scaling by 1 do? What is that matrix called? What does scaling by a negative value do?

Combining transformations We have a general transformation of a point: P' = M •

Combining transformations We have a general transformation of a point: P' = M • P + A When we scale or rotate, we set M, and A is the additive identity. When we translate, we set A, and M is the multiplicative identity. To combine multiple transformations, we must explicitly compute each transformed point. It’d be nicer if we could use the same matrix operation all the time. But we’d have to combine multiplication and addition into a single operation.

Homogenous Coordinates y y w x x �Let’s move our problem into 3 D.

Homogenous Coordinates y y w x x �Let’s move our problem into 3 D. �Let point (x, y) in 2 D be represented by point (x, y, 1) in the new space. �Scaling our new point by any value a puts us somewhere along a particular line: (ax, ay, a). �A point in 2 D can be represented in many ways in the new space. �(2, 4) ----- (8, 16, 4) or (6, 12, 3) or (2, 4, 1) or etc.

Homogenous Coordinates • We can always map back to the original 2 D point

Homogenous Coordinates • We can always map back to the original 2 D point by dividing by the last coordinate • (15, 6, 3) --- (5, 2). • (60, 40, 10) - ? . • Why do we use 1 for the last coordinate? • The fact that all the points along each line can be mapped back to the same point in 2 D gives this coordinate system its name – homogeneous coordinates.

Matrix Representation �Point in column-vector: x y 1 �Our point now has three coordinates.

Matrix Representation �Point in column-vector: x y 1 �Our point now has three coordinates. So our matrix is needs to be 3 x 3. �Translation

Matrix Representation �Rotation �Scaling

Matrix Representation �Rotation �Scaling

Composite Transformation �We can represent any sequence of transformations as a single matrix. �No

Composite Transformation �We can represent any sequence of transformations as a single matrix. �No special cases when transforming a point – matrix • vector. �Composite transformations – matrix • matrix. �Composite transformations: �Rotate about an arbitrary point – translate, rotate, translate �Scale about an arbitrary point – translate, scale, translate �Change coordinate systems – translate, rotate, scale �Does the order of operations matter?

Composition Properties �Is matrix multiplication associative? ? �(A. B). C = A. (B. C)

Composition Properties �Is matrix multiplication associative? ? �(A. B). C = A. (B. C) æ éa b ù é e çê ç c d ú · êg û ë èë f ùö éi ú ÷÷ · ê h û ø ëk j ù éae + bg ú=ê + l û ëce dg af + bhù é i ·ê ú cf + dh û ëk éaei + bgi + afk + bhk =ê ë cei + dgi + cfk + dhk éa b ù æ é e ê ú · çç ê ëc d û è ë g f ù éi ú·ê h û ëk j ù ö éa b ù é ei + fk ú ÷÷ = ê ú·ê + l û ø ë c d û ë gi hk jù ú lû aej + bgj + afl + bhl ù ú cej + dgj + cfl + dhl û ej + fl ù ú gj + hl û éaei + afk + bgi + bhk =ê ë cei + cfk + dgi + dhk aej + afl + bgj + bhl ù ú + + + cej cfl dgj dhl û

Composition Properties �Is matrix multiplication commutative? ? . A �A. B = B

Composition Properties �Is matrix multiplication commutative? ? . A �A. B = B

Order of operations So, it does matter. Let’s look at an example: 1. 2.

Order of operations So, it does matter. Let’s look at an example: 1. 2. Translate Rotate 1. 2. Rotate Translate

Composite Transformation Matrix • Arrange the transformation matrices in order from right to left.

Composite Transformation Matrix • Arrange the transformation matrices in order from right to left. • General Pivot- Point Rotation • Operation : 1. Translate (pivot point is moved to origin) 2. Rotate about origin 3. Translate (pivot point is returned to original position) T(pivot) • R( ) • T(–pivot) 1 0 0 0 1 0 tx ty 1 cos sin 0 . . cos sin 0 -sin 0 cos 0 0 1 . 1 0 0 0 1 0 -tx -ty 1 -sin -tx cos + ty sin cos -tx sin - ty cos 0 1 -sin -tx cos + ty sin + tx cos -tx sin - ty cos + ty 0 1

Composite Transformation Matrix �Example �Perform 60 rotation of a point P(2, 5) about a

Composite Transformation Matrix �Example �Perform 60 rotation of a point P(2, 5) about a pivot point (1, 2). Find P’? cos sin 0 -sin -tx cos + ty sin + tx cos -tx sin - ty cos + ty 0 1 0. 5 -0. 866 -1. 0. 5 + 2. 0. 866 + 1 0. 866 0. 5 -1. 0. 866 - 2. 0. 5 + 2 0 0 1 0. 5 - 0. 866 2. 232 0. 866 0. 5 0. 134 0 0 1 . 2 5 1 = . . x y 1 Sin 60 = 0. 8660 Kos 60 = 1/2 2 5 1 -1. 098 4. 366 1 P’ = (-1, 4)

Without using composite homogenus matrix �Example �Perform 90 rotation of a point P(5, 1)

Without using composite homogenus matrix �Example �Perform 90 rotation of a point P(5, 1) about a pivot point (2, 2). Find P’? � 1. Translate pivot point ke asalan ( tx = -2, ty = -2) � Titik P(5, 1 ) P’ (3, -1) � 2. Rotate P ‘ = 90 degree � P’(3, -1) -- > kos 90 -sin 90 3 = 0 -1 3 � sin 90 kos 90 -1 1 0 -1 � 3. Translate back ke pivot point (tx = 2 , ty = 2) � titik (1, 3 ) titik akhir (3, 5) = 1 3

Composite Transformation Matrix General Fixed-Point Scaling Operation : 1. Translate (fixed point is moved

Composite Transformation Matrix General Fixed-Point Scaling Operation : 1. Translate (fixed point is moved to origin) 2. Scale with respect to origin 3. Translate (fixed point is returned to original position) T(fixed) • S(scale) • T(–fixed) Find the matrix that represents scaling of an object with respect to any fixed point? Given P(6, 8) , Sx = 2, Sy = 3 and fixed point (2, 2). Use that matrix to find P’?

Answer 1 0 0 0 1 0 tx ty 1 . . Sx 0

Answer 1 0 0 0 1 0 tx ty 1 . . Sx 0 0 Sy 0 0 1 . 1 0 0 0 1 0 -tx -ty 1 Sx 0 -tx Sx 0 Sy -ty Sy 0 0 1 = x =6, y = 8, Sx = 2, Sy = 3, tx =2, ty = 2 2 0 0 0 3 0 -2( 2) + 2 -2(3) + 2 1 . 6 8 1 = 10 20 1 Sx 0 -tx Sx + tx 0 Sy -ty Sy + ty 0 0 1

Composite Transformation Matrix General Scaling Direction Operation : 1. Rotate (scaling direction align with

Composite Transformation Matrix General Scaling Direction Operation : 1. Rotate (scaling direction align with the coordinate axes) 2. Scale with respect to origin 3. Rotate (scaling direction is returned to original position) R(– ) • S(scale) • R( ) Find the composite transformation matrix by yourself !!

S . Sx 0 0 Sy 0 0 0 0 1 Sxcos Sy sin

S . Sx 0 0 Sy 0 0 0 0 1 Sxcos Sy sin 0 T . 1 0 0 0 1 0 . cos sin 0 . tx ty 1 -sin tx cos ty 0 1 Sx(-sin ) Sx tx Sy cos Sy ty 0 1 . R cos sin 0 -sin 0 cos 0 0 1

Other transformations Reflection: x-axis y-axis

Other transformations Reflection: x-axis y-axis

Other transformations Reflection: origin line x=y

Other transformations Reflection: origin line x=y

Other transformations Shear: x-direction y-direction

Other transformations Shear: x-direction y-direction

Coordinate System Transformations • We often need to transform points from one coordinate system

Coordinate System Transformations • We often need to transform points from one coordinate system to another: 1. We might model an object in non-Cartesian space (polar) 2. Objects may be described in their own local system 3. Other reasons: textures, display, etc

3 D TRANSFORMATIONS

3 D TRANSFORMATIONS

Basic 3 D transformations: scaling Some of the 3 D transformations are just like

Basic 3 D transformations: scaling Some of the 3 D transformations are just like 2 D ones. For example, scaling Scaling

Translation in 3 D

Translation in 3 D

Rotation in 3 D Rotation now has more possibilities in 3 D:

Rotation in 3 D Rotation now has more possibilities in 3 D:

Rotation in 3 D What about the inverses of 3 D rotations?

Rotation in 3 D What about the inverses of 3 D rotations?

Shearing in 3 D

Shearing in 3 D

Compositing multiple transformations �Expressed as matrix multiplications: p’ = M 1 M 2 p

Compositing multiple transformations �Expressed as matrix multiplications: p’ = M 1 M 2 p means apply transformation M 2 first, followed by M 1 Historically, the vectors in graphics were row vectors, but columns are more popular.

Compositing multiple transformations 3 steps 1) T(-2, -3) 2) R(30) 3) T(2, 3) q’=T(2,

Compositing multiple transformations 3 steps 1) T(-2, -3) 2) R(30) 3) T(2, 3) q’=T(2, 3) R(30) T(-2, -3) q

Change of the coordinate frame, Change of basis Specify: an origin, and two vectors

Change of the coordinate frame, Change of basis Specify: an origin, and two vectors Let’s first look at a 2 D example p �p=(2, 1)T, what are the coordinates of p with respect to the new basis (coordinate system)?

�Linear dependence or independence �Spanning a space or a subspace, ‘generators’ �Basis for a

�Linear dependence or independence �Spanning a space or a subspace, ‘generators’ �Basis for a space or a subspace (a set of vectors) �Dimension of a subspace (a number) �A basis for V is a set of vectors: linearly independent (not too many) and span the space V (not too few) �Basis is not unique, coordinates are, when the basis is fixed.

p • New basis: O=(4, 3)T, e 0=(-1, 0)T, e 1=(0, -1)T

p • New basis: O=(4, 3)T, e 0=(-1, 0)T, e 1=(0, -1)T

Let coordinates of p in new basis be ( 0, 1)T • • •

Let coordinates of p in new basis be ( 0, 1)T • • • New basis: O=(4, 3)T, e 0=(-1, 0)T, e 1=(0, -1)T Represent as homogeneous coordinates: O=(4, 3, 1)T, e 0=(-1, 0, 0)T, e 1=(0, -1, 0)T For vectors, last component of homogeneous coordinates is 0, for convenience only for the time being.

 • • Basis change: e’_i = B e_i Pt change, x’ = A

• • Basis change: e’_i = B e_i Pt change, x’ = A x x=sum x_i e_i, x=sum x_i B^{-1} e’ = sum • B^{-1} x_i e’ x’ = B^{-1} x

Change of basis in 3 D one origine, three vectors 3 D case �Given

Change of basis in 3 D one origine, three vectors 3 D case �Given an orthonormal basis (O, e 0, e 1, e 2) �e 0, e 1, e 2 are unit length vectors �e 0, e 1, e 2 are mutually orthogonal �To change basis, need matrix M=(e 0 e 1 e 2 O) �It is easy to find the inverse of such a matrix

� We can write M as � Finding the inverse � Transformation between two

� We can write M as � Finding the inverse � Transformation between two coordinate systems involves a translation, followed by a general rotation.

Cross product The cross product of two vectors in 3 -space is An easy

Cross product The cross product of two vectors in 3 -space is An easy way to remember this is to write it in the form

Cross product: define coordinate system �Given two vectors u and v (not parallel) �Define

Cross product: define coordinate system �Given two vectors u and v (not parallel) �Define a coordinate system such that �One of the axis is in the direction of u �Another axis is perpendicular to both u and v �Solution: �Direction of x-axis: e 0 = u �Direction of z-axis: e 2 = u x v �Direction of y-axis: e 1 = e 2 x e 0 (note: e 0 x e 2 ) �The Gram-Shmidt process