Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 450: Computer Graphics 2D TRANSFORMATIONS

Similar presentations


Presentation on theme: "CS 450: Computer Graphics 2D TRANSFORMATIONS"— Presentation transcript:

1 CS 450: Computer Graphics 2D TRANSFORMATIONS
Spring 2015 Dr. Michael J. Reale

2 INTRODUCTION Now that we have some linear algebra under our respective belts, we can start using it in graphics! So far, for each primitive, we have a description that includes the positions of the vertices  model coordinates Examples: A square with vertices (-1,-1), (1,-1), (1,1), (-1,1) A teapot with its vertices relative to its bottom We would like to be able to place this primitive in the world wherever we want (as well as rotate it and/or scale it)  use a model transform Recall: Model coordinates (relative to model)  MODEL TRANSFORM  World coordinates We would also like to be able to get the world coordinates relative to the camera  use view transform Recall: World coordinates  VIEW TRANSFORM  Camera (Eye) Coordinates

3 TRANSFORMATIONS Transformations or transforms = operations that change position, orientation, and/or size of geometric object Use matrices to perform transformations on vectors/points Examples: model transforms, the view transform, projection transform, etc. Geometric vs. Modeling transformation Sometimes considered the same Sometimes: Geometric = transforming the whole “object” Modeling = gives hierarchy for pieces of the object (e.g., arms relative to torso in human body model)

4 OVERVIEW Three most basic transformations:
Rotation Scaling (i.e., resizing the object) Translation (i.e., moving/placing the object) Other transformations: shear, reflection, etc. We’re going to start with 2D transformations first Then, later, we’ll move on to 3D transformations Keep in mind, we will be building simple transformations (with certain implicit assumptions) However, we will combine these to make more powerful transformations

5 ROTATION

6 ROTATION: INTRODUCTION
To rotate an object, we need: Rotation angle  how much to rotate Counterclockwise in plane we’re rotating Rotation axis  what we’re rotating around In 2D, just use z axis WARNING: Rotation performed around ORIGIN Origin (0,0) = rotation point (or pivot point) (We’ll talk later about how to rotate around an arbitrary rotation point)

7 ROTATION: DERIVING Recall: P = (x,y)  original point
P’ = (x’,y’)  transformed point ϕ = original angle of point (x,y) from x axis θ = difference in angle between old and new point So, our original point (x,y) and transformed point (x’,y’) in polar coordinates are as follows  After substitution, we can express the transformed point in terms of θ only:

8 ROTATION MATRIX We have: If our rotation matrix transform is R, then:
Therefore, our 2D rotation matrix is:

9 SCALING

10 SCALING: INTRODUCTION
Scaling an object = altering the size of an object The scaling we will be doing here  simply multiplying each coordinate by a scaling factor: The corresponding scaling matrix transformation 

11 SCALING: FACTORS Scaling factor > 1.0  enlarge
Scaling factor < 1.0  shrink Scaling factor < 0  negative scaling  resizes AND reflects object Uniform scaling = scaling factors are all the same (e.g., sx = sy) Otherwise, called differential scaling

12 SCALING: ASSUMPTIONS WARNING: Because of the way we are doing scaling:
Only scaling in X or Y direction (or both), but NOT in arbitrary direction! Scaling relative to ORIGIN! ORIGIN = fixed point (point unaffected by scaling) (We’ll talk later about how to use a different fixed point)

13 TRANSLATION

14 TRANSLATION: INTRODUCTION
Translation = moving a point by a certain distance (tx , ty) (tx , ty) = translation distances = translation vector = shift vector If we’re stuck with 2x2 matrices and 2x1 vectors, we have to add vectors to perform a translation:

15 TRANSLATION: PROBLEM At some point, we would like to be able to combine multiple transformations into a single matrix: This means we can multiply all our transformations together first (M), and then apply it to each point we want HOWEVER, because translation is handled as addition, we need to compute intermediate steps:

16 HOMOGENEOUS COORDINATES

17 HOMoGENEOUS COORDINATES
To fix this, we will extend our 2x2 matrices (and our 2x1 vectors) to 3x3 matrices (and to 3x1 vectors) Homogeneous coordinates = for 2D coordinates, extension to (xh , yh , h) h = homogeneous parameter  nonzero value such that: Often just set h = 1  (x, y) becomes (x, y, 1) Often use “w” instead of “h” (especially for 3D vectors  (x,y,z,w) ) As we’ll see, this allows us to represent translation as a matrix multiplication!

18 TRANSLATION MATRIX WITH HOMOGENEOUS COORDINATES
The 2D translation matrix is sometimes represented as T(tx , ty )

19 ROTATION MATRIX WITH HOMOGENEOUS COORDINATES
The 2D rotation matrix is sometimes represented as R(θ)

20 SCALING MATRIX WITH HOMOGENEOUS COORDINATES
The 2D scaling matrix is sometimes represented as S(sx , sy)

21 PATTERN WITH HOMOGENEOUS COORDINATE MATRICES
With the translation matrix, we purposely use the additional elements of the matrix (in this case, the extra column): For rotation, scaling, and shear matrices (discussed later), the original matrix is augmented with an extra row and column of zeros (except for the last (row,column) position, which is set to 1):

22 HOMOGENEOUS COORDINATES: POINTS VS. VECTORS
Recall: a vector can also be interpreted as: Location (w = 1) Direction (w = 0) …in space Note: sometimes, location  called “point” and direction  called “vector” Depending on how we want to interpret the vector, we will set a different value for w

23 HOMOGENEOUS COORDINATES: POINTS VS. VECTORS
Points  all transformations should have an effect (translation, rotation, scaling, etc.) w set to 1 Direction  translation has no meaning (other transformation should work though) w set to 0

24 INVERSE TRANSFORMATIONS

25 INVERSE TRANSFORMATIONS
Fortunately, the inverses of the translation, rotation, and scaling matrices can be computed directly: Applying an inverse transformation  does the opposite transformation T-1  translate object (-tx , -ty )

26 QUICK ASIDE: INVERSE OF ROTATION MATRIX
We computed the inverse directly by using the negative angle (-θ)  only sine was affected by this It turns out, any rotation matrix is ORTHOGONAL  inverse = transpose = swapping rows and columns Also note: |R| = cos2 θ + sin2 θ = 1

27 CHANGING COORDINATE SYSTEMS

28 CHANGING 2D COORDINATE SYSTEMS
Given a point P, many times we want to get the coordinates of this point relative to some OTHER coordinate basis vectors and origin point Example: viewing transform  getting coordinates with respect to camera’s view (camera’s basis vectors) and camera’s starting point (camera’s origin) As with all our slides thus far, we’ll stick to 2D for now. For a 2D coordinate system, we need: An origin point (x0, y0) Two axes  x’ and y’

29 CHANGING 2D COORDINATE SYSTEMS
To change 2D coordinate systems: Translate so that the new origin is at (0,0)  T(-x0, -y0) Rotate the x’ axis onto the x axis  need to get angle θ between x’ and x  R(-θ) Final transformation: R(-θ) T(-x0, -y0)

30 COMPUTING NEW COORDINATE AXES
If we only know one vector V (and we want y’ to point in the same direction): Alternatively, we might be given P0 (origin) and P1 (endpoint of y’ axis):

31 CHANGING 2D COORDINATE AXES ONLY
If our new coordinate axes are u = (ux, uy) and v = (vx, vy), then we can construct the ROTATION matrix directly: When multiplying by a point P, P will be projected on each axis (P dotted with each axis):

32 CHANGING 2D COORDINATE AXES ONLY
Recall: CHANGING 2D COORDINATE AXES ONLY To drive the point home:

33 “UNDOING” a 2D COORDINATE AXIS CHANGE
To go back to the standard basis, we need to get the original coordinates back To get the x coordinate  P’x * ux + P’y * vx  P’x * x’ To get the y coordinate  P’x * uy + P’y * vy  P’y * y’ The matrix form becomes:

34 “UNDOING” a 2D COORDINATE AXIS CHANGE
Note: If coordinate axes are orthonormal  matrix R is orthogonal  R-1 = RT

35 COMPOSITE TRANSFORMATIONS

36 COMPOSITE TRANSFORMATIONS
Composite transformation matrix = product of individual transformations Process of forming one is called concatenation or composition of matrices Example: apply M1 then M2  M = M2M1 NOTE THE ORDER! Must multiply from RIGHT to LEFT!!!

37 WHY USE COMPOSITE TRANSFORMATIONS?
There are a LOT of different things you can do with these; we’ll talk about a few very common examples: Rotation around an arbitrary pivot point Scaling around an arbitrary fixed point Scaling in an arbitrary direction

38 ROTATION AROUND AN ARBITRARY PIVOT POINT
Let’s say we want to rotate around an pivot point (px , py) Basic idea: Translate (-px , -py)  (px , py) is now at origin Rotate points Translate back to (px , py)

39 Scaling around an arbitrary fixed point
Say we want to scale an object relative a fixed point (px , py) Basic idea: Translate (-px , -py)  (px , py) is now at origin Scale points Translate back to (px , py)

40 Scaling in an arbitrary direction
Let’s assume our fixed point is already at the origin Basic idea: Rotate our arbitrary axis u into the x axis Scale along x Rotate back If u is our x’ axis, then our y’ axis = v = (-uy , ux):

41 ORDER MATTERS! What order you apply your matrices will affect what transformations you perform!!! Example: rotation then scale vs. scale then rotation First transformation  RIGHT-most matrix when multiplying!

42 RIGID-BODY TRANSFORMATIONS

43 RIGID-BODY TRANSFORMATIONS
Rigid-body transformation = only includes translation and/or rotation All angles and distances between coordinate positions preserved Intuitively, object doesn’t change shape  only changes position and/or orientation Also called a rigid-motion transformation In 2D, has the general form: WARNING: (trx , try) != (tx , ty ) from earlier! (Depends on order of transformations) Upper-left 2x2 matrix  orthonormal vector set

44 OTHER TRANSFORMATIONS (REFLECTION AND SHEAR)

45 REFLECTION TRANSFORMATION
Reflection transformation = transformation that produces a mirror image of object In 2D  180° rotation about axis of reflection axis Reflection about line y = 0 (x axis): Reflection about line x = 0 (y axis): Reflection about origin:

46 REFLECTION ACROSS DIAGONALS
Reflection across y = x: Reflection across y = -x:

47 SHEAR TRANSFORMATION Shear transformation = distorts shape of object like as if the object is composed of layers sliding over each other Shear in x-direction: Shear in y-direction:

48 SHEAR TRANSFORMATION WARNING: By default, assumes reference line is either the x axis or the y axis (for the x-shear and y- shear, respectively)


Download ppt "CS 450: Computer Graphics 2D TRANSFORMATIONS"

Similar presentations


Ads by Google