1 EEL 5771-001 Course: Introduction to Computer Graphics PPT4: Geometric Transformations Submitted by: First Name: Lakshminarasimha Jagannadha Last Name:

Post on 20-Jan-2016

216 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

1

EEL 5771-001

Course: Introduction to Computer Graphics

PPT4: Geometric Transformations

Submitted by:First Name: Lakshminarasimha Jagannadha

Last Name: Chaitanya NukalaU01681651

2-D Transformations

• Transformations are a fundamental part of computer graphics.

• Transformations are used to position objects, to shape objects, to change viewing positions, and even to change how something is viewed.

2

3

There are 4 main types of transformations that one can perform in 2 dimensions:They are:1.Translation2.Scaling3.Rotation 4.Shearing

These basic transformations can also be combined to obtain more complex transformations. In order to make the representation of these complex transformations easier to understand and more efficient, we introduce the idea of homogenous coordinates.

4

A point p in 2D is represented as a pair of numbers:  p= (x, y) where x is the x-coordinate of the point p and y is the y-coordinate of p . 2D objects are often represented as a set of points (vertices), {p1,p2,...,pn}, and an associated set of edges {e1,e2,...,em}. An edge is defined as a pair of points e = {pi,pj}. We can also write points in vector/matrix notation as:

5

2-D Transformations

2D Translation:•Moving an object is called a translation. We translate a point by adding to the x and y coordinates, respectively, the amount the point should be shifted in the x and y directions. We translate an object by translating each vertex in the object.

6

Translation Example:

•Assume you are given a point at (x,y)=(2,1). And suppose, the point is moved 3 units to the right and 1 unit up.The resultant points will be, (x',y') = (5,2). (x',y') = (x+3,y+1). •That is, to move a point by some amount dx to the right and dy up, you must add dx to the x-coordinate and add dy to the y-coordinate.

7

Matrix Notation:A translation can also be represented by a pair of numbers, t=(tx,ty) where tx is the change in the x-coordinate and ty is the change in y coordinate. To translate the point p by t, we simply add to obtain the new (translated) point q = p + t.

q = p + t =

2D Rotation

Rotation in the X-Y plane around origin (0,0) is a linear transformation. Rotation of α around (0,0) transforms the vector [1 0]T to [cos α sin α]T . The vector [0 1]T is transformed to the vector [− sin α cos α]T .

8

Matrix NotationThe matrix notation for the rotation is:

Consider the following figure where a position vector p(x,y) which makes an angle φ to x-axis after transformation to p’(x’,y’) makes an angle φ+θ degrees.

9

10

P= [x y] = [rcosφ rsinφ]P’= [x’ y’] = [rcos(φ+θ ) rsin(φ+θ )] = [r(cosφcosθ - sinφsinθ) r(cosφsinθ+ sinφcosθ) ]Using the definition of x=rcosφ and y=rsinφ, we can write,P’= [x’ y’] = [x cosθ – y sinθ x sinθ +y cosθ ] or the transformation matrix is:

11

Some Common Cases of Rotation

1.Rotation of 90° counter clockwise about the origin

2. Rotation of 180° counter clockwise about the origin

3. Rotation of 270° counter clockwise about the origin

4. In all the above cases det[T]=1

12

2D scalingChanging the size of an object is called a scale. We scale an object by scaling the x and y coordinates of each vertex in the object.

Uniform Scaling

It means the scalar is same for all the components.

X and Y components transform by same multiplier.

Non – Uniform Scaling

In this type, the scalars have different components.

X and Y components can be transformed by different multipliter.

13

14

Representing Uniform Scaling in matrix notation:

15

Representing 2D Non – Uniform Scaling in matrix notation

16

Homogeneous coordinatesIn order to represent a translation as a matrix multiplication operation we use 3 x 3 matrices and pad our points to become 3 x 1 matrices. This coordinate system (using three values to represent a 2D point) is called homogeneous coordinates.

•Mapping between Euclidean and homogeneous coordinates•Graphical interpretation

17

Homogeneous Coordinates Contd.

•Replace 2d points with 3d points, last coordinate 1•For a 3d point (x,y,w) the corresponding 2d point is (x/w,y/w) if w is not zero•Each 2d point (x,y) corresponds to a line in 3d; all points on this line can be written as [kx,ky,k] for some k. •(x,y,0) does not correspond to a 2d point, corresponds to a direction.•Geometric construction: 3d points are mapped to 2d points by projection to the plane z =1 from the origin

18

Homogeneous Coordinates Contd.•From homogeneous to 2d: [x,y,w] becomes [x/w,y/w] •From 2d to homogeneous: [x,y] becomes [kx,ky,k] (can pick any nonzero k!)

19

Euclidean Mapping•The Euclidean mapping or isometry is a special case of affine mapping that, besides collinearity and ratios of distances, keeps also distances and angles. Because of this, a Euclidean mapping is also called a rigid motion.•The Euclidean transformations or Euclidean motions are the (bijective) mappings of points of the Euclidean plane to themselves which preserve distances between points. There are four types of these mappings (also called isometries) 1.Translations 2.Rotations 3.Reflections 4. Glide Reflections.

20

Translation:Translating a set of points of the plane, preserving the distances and directions between them,   is equivalent to adding a fixed pair of numbers (a, b) to the Cartesian coordinates of every point in the set. That is, if the original coordinates of a point are (x, y), after the translation they will be

Rotation:To rotate a figure counterclockwise around the origin by some angle θ is equivalent to replacing every point with coordinates (x,y) by the point with coordinates (x',y'), where

21

Reflection:If (x, y) are the Cartesian coordinates of a point, then (−x, y) are the coordinates of its reflection across the second coordinate axis (the Y-axis), as if that line were a mirror. Likewise, (x, −y) are the coordinates of its reflection across the first coordinate axis (the X-axis). In more generality, reflection across a line through the origin making an angle θ with the x-axis, is equivalent to replacing every point with coordinates (x, y) by the point with coordinates (x′,y′), where:

22

Glide Reflection:A glide reflection is the composition of a reflection across a line followed by a translation in the direction of that line. It can be seen that the order of these operations does not matter (the translation can come first, followed by the reflection).

23

Graphical InterpretationThe graph of a linear equation  ax+by = c  is a straight line. Two distinct lines always intersect at exactly one point unless they are parallel (have the same slope). The coordinates of the intersection point of the lines is the solution to the simultaneous linear equations describing the lines. So we would normally expect a pair of simultaneous equations to have just onesolution

24

Let's look at an example graphically:2x + 3y = 74x + y = 9

From the graph we see that the point of intersection of the two lines is (2, 1) Hence, the solution of the simultaneous equations is x = 2, y =1.If you solved the two equations using either Gaussian elimination or substitution, you would obtain the same result.

25

2D transformation in homogeneous coordinatesThe Homogeneous coordinates for Transitional (Tx,y), Rotational (Rθ), and Scaling (Sx,y) for a point ‘P’ can be written as follows:

26

Examples

Any linear transformation can be written in matrix form in homogeneous coordinates. Example 1: Translations

[x,y] in homogeneous coordinates is [x,y,1]

27

Example 2: Perspective Projectionx´ = 1 y´ = y/x w´= 1. Can multiply all three

components by the same number - - the 2D point won’t change! Multiply by x.

28

Inverse translation, scaling and rotationIn simple form this can be written as:Translation: T-1(a, b) = T(-a, -b)

Rotation: R-1(q) = RT(q) = R(-q)

Scaling: S-1(a,b) = S(1/a, 1/b)

29

Composites of translation, scaling and rotation•To compose transformations, multiply the matrices:

–composition of a rotation and a translation:

M=RT

•all transformations can be expressed as matrices

–even transformations that are not translations, rotations and scaling

Matrix notations

30

Composing Transformations:Matrix multiplication is associative: C(B(Ax)) = C((BA)x) = (C(BA))x = ((CB)A)x = (CB)(Ax) • Matrix multiplication is not commutative:

AB = BA (in general) A rotation followed by a translation is not the same as a translation followed by a rotation

Matrix notations: -3 × 3 composite matrix

31

Rotation with respect (wrt) to an arbitrary point1.Translate the coordinates so that the origin is at (x0,y0) 2.Rotate by θ 3.Translate back

32

Rotation about an arbitrary point contd.In simple we can write down the steps as followsM = T(Ax,Ay) R(-90) T(-Ax,-Ay)

33

Rotation about an arbitrary point contd.

34

Math via the composite of various transformations

The composition of two rotations from the same center, is a rotation whose degree of rotation equals the sum of the degree rotations of the two initial rotations.

35

Scaling with respect to an arbitrary point1. Translate the point(-m, -n) to the origin

2. Scale the object by Sx, Sy scale factors

3. Translate the point back (m, n)

36

Is order of transformations relevant?When performing multiple transformations order is relevant but at times when performing multiple 2D rotations, order doesn’t matter. Sometimes (but be careful) order does not matter, For example, if you apply multiple 2D rotations, order makes no difference.

Example to show relevanceFor example, if we want to scale the triangle by 2 in each direction about the point fp = (1.5,1), we first translate all the points of the triangle by T = (-1.5,-1), scale by 2 (S) , and then translate back by -T=(1.5,1).

37

Example contd.Mathematically this looks like

Notice the order in which these transformations are performed. The first (rightmost) transformation is T and the last (leftmost) is -T. If you apply these transformations in a different order then you will get very different results. For example, what happens when you first apply T followed by -T followed by S? Here T and -T cancel each other out and you are simply left with S

38

Computational Efficiency:it requires 9 multiplications and multiplications and 6 additions. Actually, only 4 multiplications and 4 additions

•Once matrix is concatenated, it is maximum number of computations required computations required .•Without concatenation, individual transformations would be applied one at a time, and the number of calculations could be significantly increased

39

• Rotation calculations require trigonometric evaluations and several multiplications.

• Computational efficiency can become an omputational efficiency can become an important important consideration in rotation transformations.

• For small enough angles (less than 10 ), cos θ is approxi tl ma t ely 1.0 and i s n θ h l lt as a value very close to the value of θ in radians

40

Efficiency Considerations :A 2D point transformation requires 9 multiplies and 6 adds

But since affine transformations have always the form:

The number of operations can be reduced to 4 multiplies and 4 adds

41

Rigid motions•A transform made up of only translation and rotation is a rigid motion or a rigid body transformation. •The linear part is an orthonormal matrix.•Inverse of orthonormal matrix is transpose

– so inverse of rigid motion is easy:

•Rotation using orthogonal vectors

42

Rotation using orthogonal vectorsIn linear algebra, an orthogonal matrix is a square matrix with real entries whose columns and rows are orthogonal unit vectors (i.e., orthonormal vectors), i.e.where I is the identity matrix.This leads to the equivalent characterization: a matrix Q is orthogonal if its transpose is equal to its inverse:When discussing a rotation, there are two possible conventions: rotation of the axes, and rotation of the object relative to fixed axes.

Reflections wrt to x- and y-axis

Reflection wrt y-axis Reflection wrt x-axis

43

44

Reflections wrt to an arbitrary axis

1. Translate (0, -b) so that the line passes through the origin

2. Rotate the line about the x axis by –θ0

3. Reflect object about the x axis

4. Rotate back the line by θ0

5. Translate back (0,b)

45

Shear in x- and y-direction and Matrix representation•Shear transformations produce a shape distortion. (old coordinates are (x, y) and the new coordinates are (x', y'))•X-Direction Shear is given by the following matrix:

46

The above produces shearing along x that is proportional to y:

Y-Direction Shear is given by the following matrix:

The above produces shearing along y that is proportional to x:

47

2D transformations as pixel block copyA pixel is the smallest building block of what a screen displays. Pixel art is the arrangement of these blocks on a pixel-by-pixel basis to make images and animations intended for screen display.

Translations and rotations Processing treats the screen as a rectangular array of pixels. By default, Processing labels each pixel in (column, row) form, starting at 0 in both the rows and columns. Thus, on the screen, the pixel in the upper-left corner is (0, 0), because it is in row 0 and column 0.

48

In other words, we can say that the default coordinate system for Processing puts the origin point (0, 0) in the upper-left corner of the screen, and the x-axis and y-axis are parallel to the sides of the screen.As we will see, Processing lets you move the origin, and also rotate the entire coordinate system around the origin. By combining sequences of rotations and translations, you have complete control over the location and orientation of any object.

49

Translation:Translation is a geometric term that means “move”. When we translate a point, we move it to a new location by specifying how far it moves along the x and y axes.If we call translate(80,100) before drawing an object, then the origin moves 80 pixels to the right and 100 pixels down.In general, calling translate(a,b) uses the current coordinate system to move the origin a, pixels along the x-axis, and b pixels along the y-axis:

Rotation with arbitrary degree and Scaling with arbitrary factor

50

51

2D coordinate system mapping•All transformations we have looked at involve transforming points in a fixed coordinate system (CS).•Computer-graphics applications involve coordinate transformations from one reference frame to another during various stages of scene processing.• To transform object descriptions from xy co To transform object descriptions from xy co-or to x or to x y’ ’ co-or All steps of the composite map•Translate so that the origin (x0, y0) of the x’y’ system is moved to the origin (0, 0) of the xy system •Rotate the x’ axis onto the x axis

52

All steps of the composite map contd.

53

All steps of the composite map contd.Alternative method:• Specify a vector V that indicates the direction for the positive y positive y ’ axis•Obtain the unit vector u along the x’ axis by applying a 90 clockwise rotation to vector v •Rotation matrix could be expressed as elements of a set of orthonormal vectors

54

Transforming Coordinate System(CS) examples:

55

3D translationA position P=(x, y, z) in 3-D is translated to a location P’=(x’, y’, z’) by adding translation distances t x, t y, and t z.

•Each of the defining points are translated. •If the object is a polygon, each vertex of the polygon is translated.

56

Homogeneous coordinate representationA 4 by 4 homogenized matrix

The inverse translation matrix is obtained by replacing tx, ty and tz with -tx,-ty and -tz..

57

3D rotationsThese involve roations of lines, points and objects along any one of the three axes or two axes, or all the three axes. Which are:•z- axis rotation•Y-axis rotation and •X-axis rotation

58

Rotations around the three main axes

59

3D rotation about an arbitrary axisThis is similar to 2D rotation about an arbitrary point. The general procedure is as follows:1. Translate rotation axis to coordinate axis2. Perform rotation3. Do inverse translation

60

All steps in the creation of the composite matrixFirst we must define the axis of Rotation by 2 points - P1, P2 then do

the following:1. Translate so that rotation axis passes through origin.

2. Rotate so that the rotation axis is aligned with one of the principle coordinate axes.3. Perform rotation of object about coordinate axis.4. Perform inverse rotation of 2.5.Perform inverse translation of 1.

We will arbitrarily choose the Z axis to map the rotation axis onto. The rotation axis is defined by 2 points: P1(x1,y1,z1) and P2(x2,y2,z2.). These 2 points define a vector:V = (x2 - x1 , y2 - y1 , z2 - z1) = (dx, dy, dz)

61

• It has a unit vectorU = V . |V| where |V| is the length of V = (VxV) = (dx^2 + dy^2 + dz^2)^1/2

• Now U = (a,b,c) wherea = dx/|V|, b = dy/|V|, c = dz/|V|

(these are called the direction cosines of x, y, and z)(Note: the direction cosine of x = cos A where A = angle of V with respect to x axis)• Now we can perform the first translation (of the rotation axis to pass through the

origin) by using the matrix T (-x1, -y1, -z 1), i.e., move the point P1 to the origin.

Next we want to rotate to align V with Z axis. We do this in 2 steps:1. Rotate V about X axis to put V in XZ plane.

2. Rotate V about Y to align with Z.For rotation about X axis we need to find cos A, sin A where A = angle between

projection of U (in YZ plane) and Z axis. Note: U' is no longer a unit vector, i.e. |U'| = 1

Uz = unit vector along z axis = (0,0,1)now (U)' * (Uz ) = |U'| * |Uz| cos A = d * cos A

62

|Uz | = (1)1/2 = 1(U')(Uz) = 0 * 0 + b * 0 + c * 1 = ctherefore c = d * (cos A) => cos A = c/dNow the cross product of 2 vectors (V1) X (V2) = W |V| * |V2|sin q where W is perpendicular to plane of V1, V2 so (U') X (Uz) = Ux|U' |* |Uz|sin A = Ux d * sin A

Rx(a) --> Rotates U into XZ planeNow compute Ry(B) for rotation to z-axis.

63

After rotation about x-axis the vector is as below:Uy" = 0 since in XZ planeUz" = d = |U'| since just rotated U' into XZ planeagain from dot product:cos B = U" *(Uz) / |U"||Uz| = 0 * a + 0 * 0 + 1 * d = dNote: |U"|*|Uz| = 1 since both are unit vectorsfrom the cross product U" x Uz = Uz|U"||Uz|sin B(from matrix) = Uy x (-a)therefore sin B = - aThe result of this transformation is that V (= Rotation axis) is coincident with z axis.Then apply

64

Then we must apply inverse transformations to get R.A. back to original position. Therefore, the complete composite transformation matrix is as follows:.R(q) = T * Rx(A) * Ry(B) * Rz(q) * RY-1(B) * Rx-1(A) * T-1n1 = a(x), n2 = b(y), n3 = c(z)[R] =

65

3D rotation using quaternions•A quaternion represents two things.  It has an x, y, and z component, which represents the axis about which a rotation will occur.  It also has a w component, which represents the amount of rotation which will occur about this axis.  In short, a vector, and a float.  With these four numbers, it is possible to build a matrix which will represent all the rotations perfectly. A quaternion is technically four numbers, three of which have an imaginary component.  As many of you probably know from math class, i is defined as sqrt(-1).  •Well, with quaternions, i = j = k = sqrt(-1).  The quaternion itself is defined as q = w + xi + yj + zk.  w, x, y, and z are all real numbers. •Any rotation in three dimensions can be represented as a combination of a vector. and a scalar θ. Quaternions give a simple way to encode this axis–angle representation in four numbers, and can be used to apply the corresponding rotation to a position vector, representing a point relative to the origin in R3

 

66

Math and matrix notationA quaternion rotation can be algebraically manipulated into a quaternion-derived rotation matrix. By simplifying the quaternion multiplications q p q*, they can be rewritten as a rotation matrix given an axis–angle representation:

where s and c are shorthand for sin θ and cos θ, respectively. Although care should be taken (due to degeneracy as the quaternion approaches the identity quaternion (1) or the sine of the angle approaches zero) the axis and angle can be extracted via:

67

Note that the θ equality holds only when qr is non-negative.Alternatively, the rotation matrix can be expressed as

As with other schemes to apply rotations, the centre of rotation must be translated to the origin before the rotation is applied and translated back to its original position afterwards

68

3D scaling wrt to an arbitrary point

69

3D scaling wrt to an arbitrary point contd.

Math and matrix notation

70

Math and matrix notation contd.

71

3D reflections wrt to the principal planesIn 3D-reflection the reflection takes place about a plane whereas 2D reflection it used take place about an axis. The matrix in case of pure reflections, along basic planes, viz. X-Y plane, Y-Z plane and Z-X plane are given below:

72

Transformation matrix for a reflection through X-Y plane is

Transformation matrix for a reflection through Y-Z plane is:

73

Transformation matrix for a reflection through Z-X plane is

General x/y/z axis shearing:In 3D we can shear along the x-axis, y-axis or z-axis. AS an example, the shear along the z axis leaves the z coordinate of points the same but changes the x and y coordinates by amounts proportional to their z coordinate:

74

The Shearing can be represented by the matrix:

75

Transformation between 3D coordinate systems•An x’y’z’ system is defined with respect to an xyz system.•To transfer the xyz coordinate descriptions to the To transfer the xyz coordinate descriptions to the x’y’z’ system.•Translation that brings the x’y’z’ coordinate origin to the xyz origin A sequence of hl d d f rotations that align corresponding coordinate axes .•A scaling transformation may also be necessary

76

Transformation between 3D coordinate systems contd.

top related