1 / 52

Chapter 2 – Making them Move

Chapter 2 – Making them Move. Dr. Paige H. Meeker CSC 458. Geometric Transformations. We can now create points, lines, and polygons. Let’s learn how to manipulate them. Geometric Transformations allow us to: Move (Translate) Orient (Rotate) Resize (Scale). Geometric Transformations.

kendall
Download Presentation

Chapter 2 – Making them Move

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 2 – Making them Move Dr. Paige H. Meeker CSC 458

  2. Geometric Transformations • We can now create points, lines, and polygons. Let’s learn how to manipulate them. • Geometric Transformations allow us to: • Move (Translate) • Orient (Rotate) • Resize (Scale)

  3. Geometric Transformations • Why do we care about transformations? • Usually we define our shapes in a coordinate system convenient to us. Using transformation equations enables us to easily modify object locations in the world coordinate system. In addition, if we transform our objects and play back the CG images fast enough, our eyes will be tricked to believe we are seeing motion. This principle is used extensively in animation, and we shall look into it in detail in Chapter 7. When we study 3D models, we will also see how we can use transformations to define hierarchical objects and to "transform" the camera position. • This chapter introduces the basic 2D transformations.

  4. Concepts: • Vectors and matrices • 2D Transformations: translation, scaling, and rotation • How to use OpenGL to transform objects • Composition of transforms

  5. Math We Need to Know • Vectors • Matrices

  6. Vectors • One of the most important mathematical devices in computer graphics, physics, and engineering is the vector. • Vectors are used to express displacement. • Length and direction are the most important vector properties.

  7. Vectors • Line with both length and direction. • A 2D vector has a length of x units along the x axis and y units along the y-axis and is denoted like this - • The vector between points P and Q below is denoted as (the displacement from one point to the other.

  8. Vectors • Interestingly, any point P1 with coordinates (x,y) corresponds to the vector vPI, with its head at (x,y) and tail at (0,O) • So, there is a one-to-one correspondence between a vector, with its tail at the origin, and a point on the plane. This means that we can also represent the point P(x,y) by the vector • Why is this important? Because often, the mathematical representation of points for transformation equations will use vectors to represent points.

  9. Vector Operations • Fundamental: addition, subtraction, and multiplication with a real number.

  10. Vector Addition • Arguably the simplest of all vector operations. • Add each component of the vectors with each other • p = (5,3) q = (-2, -5) • p + q = [5 + (-2), 3 + (-5)] = (3,-2)

  11. Vector Addition

  12. Vector Multiplication • Multiplying a vector by a numbers results in a vector whose length has been scaled by s. For this reason, the number s is also referred to as a scalar. If s is negative, then this results in a vector whose direction is flipped as well.

  13. Vector Multiplication • Multiplying s by a vector – • s > 1 Increases length • s = 1 No change • 0 < s < 1 Decreases length • s = 0 Null vector (0 length, direction undefined) • -1 < s < 0 Decreases length and reverses direction • s = -1 Reverses direction only • s < -1 Reverses direction and increases length

  14. Properties of Vector Addition and Multiplication • Given vectors a, b, and c and scalars k and l: • a + b = b + a • a + (b + c) = (a + b) + c • k(la) = kla • (k + l)a = ka + la • k(a + b) = ka + kb

  15. Vector Subtraction • Addition of a vector that has been flipped.

  16. Vector Magnitude • The length of the vector • The magnitude of a vector is the distance from the tail to the head of the vector. It is represented as IVI and is equal to • It is often useful to scale the vector to a length of 1 while keeping it’s direction. This is called normalizing the vector. To do this, we scale it by 1/|V| • This is also known as a unit vector and is denoted in mathematical circles as

  17. Dot Product • The dot product of two vectors is a scalar quantity. The dot product is used to solve a number of important geometric problems in graphics. The dot product is written as V1 .V2 and is calculated as:

  18. Practice Exercises • Given a = [-2, 0] and b = [4,1], compute • a’s unit vector • b’s unit vector • c = a – 2b • c = 3a • c = a + b • c = a – b • Length of a, |a| • Length of b, |b|

  19. Vectors • The Internet is a wonderful thing… be sure to take advantage of it. A nice site to look at can be found at: http://zonalandeducation.com/mstm/physics/mechanics/vectors/vectors.html • Or their more general site: http://zonalandeducation.com/index.html

  20. Matrices • A matrix is a set of numbers or other mathematical elements arranged in a rectangular array of rows and columns. The structure of a matrix makes it easy to assemble and work with certain kinds of mathematical data. • One matrix can operate on another matrix to change the data in some way. • Matrices can be used to represent geometric objects in computer data bases, to perform geometric transformations like translation, rotation, and scale, etc.

  21. Matrices • A matrix is an array of numbers. The number of rows (m) and columns (n) in the array defines the cardinality (or order) of the matrix (m x n). • A vector is simply a matrix with one column (or a one-dimensional matrix). • Displays are just a matrix of pixels. • A frame buffer is a matrix of pixel values for each pixel on the display.

  22. Special Matrices • Square Matrix: number of rows = number of columns (m=n) • Row or Column Matrix: a matrix with a single row (or column) – also called vectors • Diagonal Matrix: has zero elements except along the diagonal (If all the elements along the diagonal are also equal, then the diagonal matrix is called a scalar matrix.) • Null Matrix: One whose elements are all zero. • Symmetric Matrix: One whose elements are symmetric about the main diagonal • Antisymmetric Matrix: aij = -aji

  23. Identity Matrix • A square matrix (an equal number of rows and columns) with all zeroes, except for 1’s in its diagonal. • Multiplication of a vector/matrix by an identity matrix has no effect.

  24. Matrix Addition • Matrices can be added component wise, provided they have the same cardinality. • Similarly, matrices can be subtracted component wise as well. • We can add or subtract a sequence of more than two matrices as long as they are the same order.

  25. Matrix Multiplication • Multiplication of a matrix by a scalar is simply the multiplication of its components by this scalar. It produces a new matrix of the same cardinality.

  26. Matrix Multiplication • Two matrices can be multiplied if and only if the number of columns of the first matrix (m x n) is equal to the number of rows of the second (n x p). The result is calculated by applying the dot product of each row of the first matrix with each column of the second. The resultant matrix has a cardinality of (m x p).

  27. Matrix Multiplication

  28. Matrix Transpose • Interchanging the rows and columns of a matrix A and we obtain its transpose. (AT) • aijT = aji A = |a c e| |b d f|

  29. Matrix Properties • Addition and Scalar Multiplication (A, B, C are matrices; b, d are scalars) • A + B = B + A • A + (B + C) = (A + B) + C • b(A + B) = bA + bB • (b+d)A = bA + dA • b(dA) = (bd)A = d(bA)

  30. Matrix Properties • Matrix Multiplication • (AB) C = A(BC) • A(B+C) = AB + AC • (A+B)C = AC + BC • A(kB) = k(AB) = (kA)B

  31. Matrix Properties • Matrix Transpose • (A+B)T = AT + BT • (kA)T = kAT • (AB)T = BT AT • If AAT = I, then A is an orthogonal matrix

  32. Practice Exercises

  33. Why am I telling you all this? • How do you think we make things move in computer graphics? • We use matrices to perform geometric transformations – to move, orient, and resize objects.

  34. Geometric Transformations • The functions used for modifying the size, location, and orientation of objects or of the camera in a CG world.

  35. Object Transformations • Transformations are applied within a particular space domain, be it an object space or the camera space or a texture space. • We shall mainly be discussing transformations applied in the object space, also called object transformations. • Internally, this is represented as a matrix. Operations on the matrix then transform each object.

  36. Common Transformations • Translation • Rotation • Scale

  37. Translation

  38. Translation – we want to MOVE! • In a 2D world, we can move the object from left to right (translate along the x-axis) or up and down (translate along the y-axis). • This is denoted as Tx and Ty. • Consider a circular shape, P, as shown on the previous slide. To move P by a distance of (tx,ty) then all points P(x,y) on this shape will move to a new location P'(x,y) = P(x+Tx, y+Ty)

  39. Translation • All transformations are represented as vectors. So, the point P is represented as: • The translation transformation is also represented as a vector:

  40. Translation • Mathematically, then, the transformation becomes just the result of adding together two vectors. P’ = P + T

  41. Translating Objects • Mathematically, we can translate an object by applying this equation to every point on the object. Usually, we can get away with just applying the translation to the vertices of the shape and then recalculating the translated shape.

  42. Scaling • An object can be scaled (stretched or shrunk) along the x- and y- axis by multiplying all its points by the scale factors Sx and Sy. • P' = (x',y') such that x' = Sx.x, y' = Sy.y.

  43. Scaling

  44. Rotation • A shape can be rotated about any of the three axes. • A rotation about the z-axis produces a reorientation about the xy-plane, which is what we desire in our 2D world. • The points are rotated through an angle about the world origin • Mathematically, a rotation about the z-axis by an angle q would result in point P (x,y) transforming to P' (x',y') as defined here: x’ = xcos(theta) – ysin(theta) y’ = xsin(theta + ycos(theta)

  45. Rotation • In matrix form: P’ = R.P

  46. Rotation

  47. Homogeneous Coordinates • The matrix representations for translation, rotation, and scale all use different matrix representations; wouldn’t it be nice if they could all agree on one representation so that many transformations could take place at once? • To get this representation, we borrow an idea from geometry called “homogeneous coordinates” – the location of the point in projected space.

  48. Homogeneous Coordinates • With homogenous coordinates, we add a third coordinate to a (2D) point. • Instead of being represented by a pair of numbers (x,y), each point is now represented by a triplet (x,y, W), or in vector notation as • To go from homogenous coordinates back to our original non-homogenous world, we just divide the coordinates by W - (x/W, y/W). • (Typically, W=1)

  49. Homogenous Coordinates • Two points of homogenous coordinates (x,y, W) and (x ',y ', W') are the same point if one is a multiple of the other. • (1,2,1) and (2,4,2) are the same points represented by different coordinate triples. • The points with W=O are points at infinity.

  50. Homogenous Coordinates • What does this buy us? • Because 2D points are now three element column vectors, transformation matrices used to transform a point to a new location must be of cardinality 3x3.

More Related