2D Transformations What is transformations? The geometrical changes of an object from a current state to modified state. Why the transformations is needed?

Slides:



Advertisements
Similar presentations
Computer Graphics: 2D Transformations
Advertisements

COMPUTER GRAPHICS 2D TRANSFORMATIONS.
Gursharan Singh Tatla TRANSFORMATIONS Gursharan Singh Tatla Gursharan Singh Tatla.
Computer Graphics Lecture 4 Geometry & Transformations.
Arbitrary Rotations in 3D Lecture 18 Wed, Oct 8, 2003.
1 Computer Graphics Chapter 6 2D Transformations.
Chapter 5 Geometric Transformations
Two-Dimensional Geometric Transformations
2D TRANSFORMATIONS. 2D Transformations What is transformations? –The geometrical changes of an object from a current state to modified state. Why the.
25 May May May 2015Week 5-2D Transformations1 2D Transformations By: KanwarjeetSingh.
2D TRANSFORMATIONS.
CMPE 466 COMPUTER GRAPHICS
HCI 530 : Seminar (HCI) Damian Schofield. HCI 530: Seminar (HCI) Transforms –Two Dimensional –Three Dimensional The Graphics Pipeline.
2D Geometric Transformations
Linear Algebra and SVD (Some slides adapted from Octavia Camps)
Elementary 3D Transformations - a "Graphics Engine" Transformation procedures Transformations of coordinate systems Translation Scaling Rotation.
1 CSCE 441 Computer Graphics: 2D Transformations Jinxiang Chai.
Ch. 2: Rigid Body Motions and Homogeneous Transforms
CSCE 590E Spring 2007 Basic Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
Computer Graphics with OpenGL 3e
2D Transformations x y x y x y. 2D Transformation Given a 2D object, transformation is to change the object’s Position (translation) Size (scaling) Orientation.
2D Transformations Unit - 3. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale it.
3D Graphics Goal: To produce 2D images of a mathematically described 3D environment Issues: –Describing the environment: Modeling (mostly later) –Computing.
CS 450: Computer Graphics 2D TRANSFORMATIONS
Mathematical Fundamentals
COS 397 Computer Graphics Svetla Boytcheva AUBG, Spring 2013.
Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations.
Transformation of Graphics
2D Transformation of Graphics
Lecture Notes: Computer Graphics.
Dx = 2 dy = 3 Y X D Translation A translation is applied to an object by repositioning it along a straight-line path.
2D Geometric Transformations
Part7: Geometric Transformations
GRAFIKA KOMPUTER ~ M. Ali Fauzi. Drawing 2 D Graphics.
 2D Transformations 2D Transformations  Translation Translation  Rotation Rotation  Scaling Scaling.
CSE 681 Review: Transformations. CSE 681 Transformations Modeling transformations build complex models by positioning (transforming) simple components.
Transformations Jehee Lee Seoul National University.
Geometric Transformations
CS 376 Introduction to Computer Graphics 02 / 16 / 2007 Instructor: Michael Eckmann.
Computer Graphics 2D Transformations. 2 of 74 Contents In today’s lecture we’ll cover the following: –Why transformations –Transformations Translation.
Transformation.
Introduction to Computer Graphics Geometric Transformations
Computer Graphics 3D Transformations. Translation.
Two-Dimensional Geometric Transformations ch5. 참조 Subjects : Basic Transformations Homogeneous Coordinates Composite Transformations Other Transformations.
Two-Dimensional Geometric Transformations A two dimensional transformation is any operation on a point in space (x, y) that maps that point's coordinates.
Geometric Transformations Hearn & Baker Chapter 5 Some slides are taken from Robert Thomsons notes.
Geometric Transformations
2D Geometric Transformation Translation A translation is applied to an object by repositioning it along a straight-line path from one coordinate location.
Geometric Transformations UBI 516 Advanced Computer Graphics Aydın Öztürk
Lecture 3: Introduction to 2D Graphics
Affine Geometry.
CS552: Computer Graphics Lecture 4: 2D Graphics. Recap 2D Graphics Coordinate systems 2D Transformations o Translation o Scaling o Rotation Combining.
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
Jinxiang Chai CSCE441: Computer Graphics 3D Transformations 0.
1 Teaching Innovation - Entrepreneurial - Global The Centre for Technology enabled Teaching & Learning, N Y S S, India DTEL DTEL (Department for Technology.
CS 551 / 645: Introductory Computer Graphics Viewing Transforms.
4. Affine transformations. Reading Required:  Watt, Section 1.1. Further reading:  Foley, et al, Chapter  David F. Rogers and J. Alan Adams,
Computer Graphics Lecture 11 2D Transformations I Taqdees A. Siddiqi
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
Computer Graphic 2 D Transformation.
CSCE 441 Computer Graphics: 2D Transformations
Modeling Transformation
Transformations. Modeling Transformations  Specify transformations for objects  Allows definitions of objects in own coordinate systems  Allows use.
Transformations University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2016 Tamara Munzner.
Geometric Transformations Hearn & Baker Chapter 5
2D TRANSFORMATIONS.
2D Transformations By: KanwarjeetSingh
Review: Transformations
Review: Transformations
Line and Character Attributes 2-D Transformation
Presentation transcript:

2D 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 ways Object Transformation Alter the coordinates descriptions an object Translation, rotation, scaling etc. Coordinate system unchanged Coordinate transformation Produce a different coordinate system 2D Transformations

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? Matrix Multiplication Dot product a b c d e f  abcdabcd efghefgh. = a.e + b.g a.f + b.h c.e + d.g c.f + d.h

Matrix Math What about this? Type of matrix = abab a b Row-vectorColumn-vector

Matrix Math Is there a difference between possible representations?          dfce bfae              f e dc ba  dfbecfae    dc ba fe         dfcebfae    db ca fe       

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 path to new positions. The path is represented by a vector, called the translation or shift vector. We can write the components: p' x = p x + t x p' y = p y + t y or in matrix form: P' = P + T tx tx ty ty x’ y’ xyxy txtytxty = + (2, 2) = 6 =4 ?

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 = r. cos , y = r.sin    P(x,y) x y r x’ y’  P’(x’, y’) r  => cos (  +  ) = x’/r x’ = r. cos (  +  ) x’ = r.cos  cos  -r.sin  sin  x’ = x.cos  – y.sin   =>sin (  +  ) = y’/r  y’ = r. sin (  +  ) y’ = r.cos  sin  + r.sin  cos  y’ = x.sin  + y.cos  Identity of Trigonometry

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

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, S x and S y for the x- and y- coordinates respectively. Scales are about the origin. We can write the components: p' x = s x p x p' y = s y p y 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 will be moved closer to the origin  the object will be smaller. P(2, 5) P’ Example : P(2, 5), Sx = 0.5, Sy = 0.5 Find P’ ?

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. P(2, 5) P’ 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. P’ Example : P(2, 5), Sx = 2, Sy = 2 Find P’ ?

Scaling If the scale factors are the same, S x = S y  uniform scaling Only change in size (as previous example) P(1, 2) P’ If S x  S y  differential scaling. Change in size and shape Example : square  rectangle P(1, 3), S x = 2, S y = 5, P’ ? 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 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 Let’s move our problem into 3D. Let point (x, y) in 2D 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 2D 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. yy x x w 

Homogenous Coordinates We can always map back to the original 2D 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 2D gives this coordinate system its name – homogeneous coordinates.

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

Matrix Representation Rotation Scaling

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)                          dhlcfldgjcejdhkcfkdgicei bhlaflbgjaejbhkafkbgiaei lk ji dhcfdgce bhafbgae                             lk ji hg fe dc ba                          dhldgjcflcejdhkdgicfkcei bhlbgjaflaejbhkbgiafkaei hlgjhkgi flejfkei dc ba                             lk ji hg fe dc ba ?

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

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

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 -t x 0 1 -t y cos  -sin  0 sin  cos  t x 0 1 t y cos  -sin  -t x cos  + t y sin  + t x sin  cos  -t x sin  - t y cos  + t y cos  -sin  -t x cos  + t y sin  sin  cos  -t x sin  - t y cos  t x 0 1 t y

Composite Transformation Matrix Example Perform 60  rotation of a point P(2, 5) about a pivot point (1,2). Find P’? cos  -sin  -t x cos  + t y sin  + t x sin  cos  -t x sin  - t y cos  + t y xy1xy = P’ = (-1, 4) Sin 60 = Kos 60 = 1/2

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 = = 1 sin 90 kos Translate back ke pivot point (tx = 2, ty = 2) titik (1, 3 )  titik akhir (3, 5)

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 -t x 0 1 -t y Sx Sy t x 0 1 t y Sx 0 -t x Sx 0 Sy -t y Sy t x 0 1 t y = x =6, y = 8, Sx = 2, Sy = 3, t x =2, t y = 2 Sx 0 -t x Sx + t x 0 Sy -t y Sy + t y ( 2) (3) =

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 !!

cos  -sin  0 sin  cos  Sx Sy t x 0 1 t y S. T. R cos  -sin  t x sin  cos  t y Sx Sy Sxcos  Sx(-sin  ) Sx t x Sy sin  Sy cos  Sy t y 0 0 1

Other transformations Reflection: x-axisy-axis

Other transformations Reflection: origin line x=y

Other transformations Shear: x-direction y-direction

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

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

Translation in 3D

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

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

Shearing in 3D

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,3) R(30) T(-2,-3) q

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

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

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 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 3D one origine, three vectors 3D 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 coordinate systems involves a translation, followed by a general rotation.

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 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