1 / 82

Geometrical Transformations

Geometrical Transformations. Chapter 5. This chapter introduces the basic 2D and 3D geometrical transformations used in computer graphics.

rio
Download Presentation

Geometrical Transformations

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. Geometrical Transformations Chapter 5

  2. This chapter introduces the basic 2D and 3D geometrical transformations used in computer graphics. • The translation, scaling, and rotation discussed here are essential to many graphics applications and will be referred to extensively in succeeding chapters. Chapter 5 -- Geometric Transformations

  3. 1. Mathematical Preliminaries • This section reviews the most important mathematics used in this book • especially vectors and matrices • It is by no means intended as a comprehensive discussion of linear algebra or geometry. • Rather the assumption made is that your familiarity with these topics has faded somewhat Chapter 5 -- Geometric Transformations

  4. 1.1 Vectors and Their Properties • It may be that your first introduction to the concept of a vector was in a course in physics or mechanics, • typically with speed and direction • Take for example a ball being hit by a bat • at that moment the ball’s state can be represented by a line segment with an arrow head. (the velocity vector of the ball) Chapter 5 -- Geometric Transformations

  5. The notion of a vector has proved to be of great value in physics and mathematics • We use vectors extensively in computer graphics, • the position of points in a world-coordinate set, • the orientation of surfaces in space, • the behavior of light interacting with solid and transparent objects, • and many other purposes. • We shall see them in many future chapters. Chapter 5 -- Geometric Transformations

  6. Whereas some texts choose to describe vectors exclusively from a geometrical standpoint, we shall emphasize their dual nature and exploit their algebraic definition as well. • The algebraic orientation leads to concise and compact formulation (of linear algebra) which we will favor for the math of computer graphics • The geometric interpretations will serve as an aid in understanding certain concepts. Chapter 5 -- Geometric Transformations

  7. Simple definition: • A vector is an n-tuple of real numbers, • where n is 2 for 2D space, 3 for 3D space • Vectors are amenable to two operations: • addition of vectors and • multiplication of vectors by real numbers, called scalar multiplication. Chapter 5 -- Geometric Transformations

  8. Properties: • Addition is commutative, it is associative, and there is a vector (traditionally called 0) with the property that 0+v = v for any vector v • Addition also has an inverse • for every vector v there is a vector w such that v+w = 0 • (w is written as -v) • Scalar multiplication satisfies the rules of: • (ab)v = a(bv) • 1v = v • (a+b)v = av + bv • a(v+w) = av + aw Chapter 5 -- Geometric Transformations

  9. Addition is defined componentwise, as is scalar multiplication. • Vectors are written vertically, so that a 3D vector is: • We can sum elements: Chapter 5 -- Geometric Transformations

  10. To add the vectors v and w, • we take an arrow from the origin to w, • translate it such that the base is at the point v • and define v+w as the new endpoint of the arrow • This is known as the parallelogram rule: • v+w == w+v Chapter 5 -- Geometric Transformations

  11. Scalar Multiplication by a real number a is defined similarly. • We draw an arrow from the origin to point v, • stretch it by a factor of a (holding the end at the origin fixed) • and then av is defined to be the endpoint of the resulting arrow. • Of course, the same definitions can be made for 3D-space. Chapter 5 -- Geometric Transformations

  12. 1.2 The Vector Dot Product • Given two n-dimensional vectors: • We define their inner product or dot product to be: • This is typically notated v .w Chapter 5 -- Geometric Transformations

  13. The distance from the point v = (x,y) to the origin (0,0) is • In general the distance from v = (x1,…,xn) to the origin is: Chapter 5 -- Geometric Transformations

  14. If we let v be the vector: • We can see that this is just • This is our definition of the length of an n-dimensional vector, denoted: Chapter 5 -- Geometric Transformations

  15. 1.3 Properties of the Dot Product • The dot product has several nice properties: • First it is symmetric: • Second it is non-degenerate: • iff v = 0 • Third it is bilinear: Chapter 5 -- Geometric Transformations

  16. The dot product can be used to generate vectors whose length is 1 • this is called normalizing a vector • We simply compute: • The resulting vector v’ has length 1, and is called a unit vector. Chapter 5 -- Geometric Transformations

  17. Dot products can also be used to measure angles. • The angle between the vectors v and w is • Note: if v and w are unit vectors, the division is unnecessary. Chapter 5 -- Geometric Transformations

  18. If we have a unit vector v’ and another vector w, and we project w perpendicularly onto v’, and call the result u. Then the length of u should be the length of w multiplied by cosq, where q is the angle between v and w. Chapter 5 -- Geometric Transformations

  19. We shall encounter many applications of the dot product, especially in Chapter 14, where it is used in describing how light interacts with surfaces. Chapter 5 -- Geometric Transformations

  20. 1.4 Matrices • A matrix is a rectangular array of numbers, which is frequently used in operations on points and vectors. • You can think of a matrix as representing a rule for transforming its operands by a linear transformation. Chapter 5 -- Geometric Transformations

  21. Its elements are doubly subscripted. • We shall use matrices, and their associated operations throughout much of this book. • Matrices play an important role in geometric transformations (C5), 3D viewing (C6), 3D graphics packages (C7), ... Chapter 5 -- Geometric Transformations

  22. 1.5 Matrix Multiplication • Matrices are multiplied according to the following rule: • If A is an n x m matrix with entries aij • and B isa m x p matrix with entries bij • then AB is defined, and is an n x p matrix with entries: Chapter 5 -- Geometric Transformations

  23. The usual properties of multiplication hold • except that matrix multiplication is not commutative: • AB is in general different from BA • Multiplication distributes over addition: • A(B+C) = AB +AC • There is an identity element for multiplication, namely the identity matrix I, • which is the square matrix will all entries 0 except for 1’s on the diagonal Chapter 5 -- Geometric Transformations

  24. 1.6 Determinates • The determinant of a square matrix is a single number that is formed from the elements of the matrix, • The definition is recursive. • for m x m matrices: Chapter 5 -- Geometric Transformations

  25. 1.7 Matrix Transpose • An n x k matrix can be flipped along its diagonal (upper left to lower right) to make a k x n matrix. • This new matrix is called the transpose of the original matrix. • The transpose of A is written AT • Note:u . v = uTv Chapter 5 -- Geometric Transformations

  26. 1.8 Matrix Inverse • Matrix multiplication differs from ordinary multiplication in another way: • A matrix may not have a multiplicative inverse. • In fact inverses are defined only for square matrices, and not even all of them have inverses Chapter 5 -- Geometric Transformations

  27. To be precise, only square matrices whose determinates are nonzero have inverses. • If AB = BA = I, • then B is said to be the inverse of A • If we are given an n x n matrix, the preferred way to find its inverse is by Gaussian elimination, especially for any matrix larger than 3 x 3 Chapter 5 -- Geometric Transformations

  28. 2. 2D Transformations • We can translate points in the (x,y) plane to new positions by adding translation amounts to the coordinates of the points. • Our goal is for point P(x,y) to be moved by dx units parallel to the x axis and by dy units parallel to the y axis, to the new point P’(x’,y’) Chapter 5 -- Geometric Transformations

  29. To do this, we write: • x’ = x + dx • y’ = y + dy • If we define the column vectors: • Then we can express the concept as: • P’=P+T Chapter 5 -- Geometric Transformations

  30. We could translate an object by applying the equation to every point of an object. • Because each line in an object is made up of an infinite set of points, however, this process would take an infinitely long time. • Fortunately we can translate all the points on a line by translating only the line’s endpoints and drawing a new line between the endpoints. • This figure translates the “house” by (3, -4) Chapter 5 -- Geometric Transformations

  31. Points can also be scaled (stretched) by sx along the x axis and by sy along the y axis into new points by the multiplication: • x’ = sx*x, y’ = sy*y • In matrix form this is: • or: P’ = S.P Chapter 5 -- Geometric Transformations

  32. In this figure, the house is scaled by 1/2 in x and 1/4 in y • Notice that the scaling is about the origin: • The house is smaller and closer to the origin • If the scale factor had been greater than 1, it would be larger and farther away. • Techniques for scaling about some point (other than the origin) are covered in Section 5.3 Chapter 5 -- Geometric Transformations

  33. Points can be rotated through an angle q about the origin • A rotation is defined mathematically by: • x’ = x*cosq-y*sinq • y’=x*sinq+y*cosq • In matrix form we have: • Or P’ = R.P • (where R is the rotation matrix) Chapter 5 -- Geometric Transformations

  34. This figure shows the rotation of the house by 45 degrees. • As with scaling, the rotation is about the origin • rotation about a point is discussed in Section 5.3 • Positive angles are measured counterclockwise (from x towards y) • For negative angles, you can use the identities: • cos(-q) = cos(q) and sin(-q)=-sin(q) Chapter 5 -- Geometric Transformations

  35. You can easily derive these equations from the following figure: • x= r.cos(f) • y = r.sin(f) • x’=r.cos(q+f) = r.cosf.cosq-r.sinf.sinq • y’=r.sin(q+f) = r.cosf.sinq+r.sinf.cosq • substituting the second set of equations into the first set, you get • x’ = x.cosq-y.sinq • y’=x.sinq+y.cosq Chapter 5 -- Geometric Transformations

  36. 3. Homogeneous Coordinates and Matrix Representation of 2D Transformations • The matrix representations for translation, scaling, and rotation are, respectively: • P’ = T+P • P’ = S.P • P’ = R.P • Unfortunately, translation is treated differently from scaling and rotation. • We would like to be able to treat them consistently so that they can be combined easily Chapter 5 -- Geometric Transformations

  37. If points can be expressed in homogeneous coordinates, all three transformations can be treated as multiplications. • In homogeneous coordinates, we add a third coordinate. So (x,y) becomes (x,y,W) • You homogenize the points by dividing each part by W, so you can compare them and end up with (x’,y’,1). • Note: If you pick W==1 you do not have to do any division. Chapter 5 -- Geometric Transformations

  38. Because points are now three-element column vectors, the transformation matrices must be 3x3. • Translation becomes: • This is typically denoted: P’ = T(dx,dy)P Chapter 5 -- Geometric Transformations

  39. Successive Translations work the way we would expect: • If P is translated by T(dx1,dy1) to P’ and then translated by T(dx2,dy2) to P’’ We would expect the net translation to be T(dx1+dx2,dy1+dy2) • And Chapter 5 -- Geometric Transformations

  40. Scaling now becomes: • Just as successive translations are additive, successive scalings are multiplicative Chapter 5 -- Geometric Transformations

  41. Rotation now becomes: • Showing that two rotations are additive has been left to an exercise (5.2) Chapter 5 -- Geometric Transformations

  42. Rigid-Body Transformations: • Involve only translations and rotations • Preserve angles and lengths • General form of the rigid-body transformation matrix looks like this: • An arbitrary sequence of rotation and translation matrices creates a matrix of this form. Chapter 5 -- Geometric Transformations

  43. What can be said about an arbitrary sequence of rotation, translation, and scale matrices? • They are called Affine Transformations. • They preserves parallelism of lines, • but do not preserve angles and lengths Chapter 5 -- Geometric Transformations

  44. Another type of affine transformation is a shear transformation • There are two types of shear-transformations: • Shear in x • Shear in y Chapter 5 -- Geometric Transformations

  45. 4. Composition of 2D Transformations • The basic purpose of composing transformations is to gain efficiency by applying a single composed transformation to a point rather than applying a series of transformations, one after another. Chapter 5 -- Geometric Transformations

  46. Consider the rotation of an object about an arbitrary point P1 • Because we know how to rotate about the origin, we convert our original (difficult) problem into three separate (easy) problems. • Translate so that P1 is at the origin. • Rotate • Translate P1 back. Chapter 5 -- Geometric Transformations

  47. The net transformation is: • which, when simplified looks like this: Chapter 5 -- Geometric Transformations

  48. A similar approach is used to scale an object around an arbitrary point P1 • Translate to the origin, Scale, Translate back • In Matrix notation this is: • After you simplify you have: Chapter 5 -- Geometric Transformations

  49. Composition of a series of transformations: • Example: • Translate P1 to origin, scale and rotate, translate to P2 • The matrix you create is: • M=T(x2,y2)R(q)S(sx,sy)T(-x1,-y1) • In general, of course, matrix multiplication is not commutative. • However you can show that in some cases commutativity holds. • So, either preserve the order of operations, or memorize the special cases commutativity holds Chapter 5 -- Geometric Transformations

  50. 5. The Window-to-Viewport Transformation • Some graphics packages allow the programmer to specify output primitive coordinates in a floating-point world-coordinate system, using whatever units are meaningful to the application program: • angstroms, microns, meters, ... Chapter 5 -- Geometric Transformations

More Related