Anda di halaman 1dari 62

Computer p Graphics p

Somsak Walairacht, Computer Engineering, KMITL

Outline

Basic Two-Dimensional Geometric Transformations Matrix Representations and Homogeneous Coordinates Inverse Transformations Two-Dimensional Composite p Transformations Other Two-Dimensional Transformations Raster Methods for Geometric Transformations O OpenGL GL Raster R t Transformations T f ti Transformations between Two-Dimensional Coordinate Systems
2

Outline (2)

Translation Rotation Scaling

Composite Three-Dimensional Three Dimensional Transformations Other Three-Dimensional Transformations Transformations between Three-Dimensional Coordinate Systems Affine Transformations
3

01074410 / 13016218 Computer Graphics

Introduction

Operations that are applied to the geometric description of an object to change its position, orientation, or size are called geometric g transformations Sometimes geometric-transformation operations are also referred to as modeling transformations A distinction between the two

Modeling transformations are used to construct a scene or to give the hierarchical description of a complex object that is composed of several parts Geometric transformations describe how objects might move around in a scene during an animation sequence or simply to view them from another angle
4

5

01074410 / 13016218 Computer Graphics

Two-Dimensional Translation

To translate a two-dimensional position, we add translation distances tx and ty to the original coordinates (x, y) to obtain the new coordinate position (x, y)

6

01074410 / 13016218 Computer Graphics

Polygon Translation

A polygon is translated similarly Adding a translation vector to the coordinate position of each vertex and then regenerate the polygon using the new set of vertex coordinates

01074410 / 13016218 Computer Graphics

Two-Dimensional Rotation

A rotation transformation is generated by specifying a rotation axis and a rotation angle Parameters are the rotation angle and a position (xr, yr) called the rotation point (or pivot point), about which the object is to be rotated Ap positive value for the angle g defines a counterclockwise rotation about the pivot point

Two-Dimensional Rotation (2)

Let r is the constant distance of the point from the origin, angle is the original angular position of the point from the horizontal, horizontal and is the rotation angle

Rotation about Arbitrary Point

Transformation equations for rotation of a point about any specified rotation position (xr, yr)

Rotations are rigid body transformations that move objects without deformation
10

01074410 / 13016218 Computer Graphics

Two-Dimensional Scaling

A simple two-dimensional scaling operation is performed by multiplying object positions (x, y) by scaling factors sx and sy to produce the transformed coordinates (x, y)

11

Scaling by a Fixed Point

Coordinates for the fixed point, (xf, yf ), are often chosen at some object position, such as its centroid Objects are now resized by scaling the distances between object points and the fixed point

where the additive terms xf(1sx) and yf(1sy) are constants for all points in the object

12

Many graphics applications involve sequences of geometric transformations

An animation might require an object to be translated and rotated at each increment of the motion The viewing transformations involve sequences of translations and rotations to take us from the original scene specification to the display on an output device
13

Matrix Representations and Homogeneous Coordinates

Matrix M1 is a 2x2 array containing multiplicative factors and M2 is a two-element factors, two element column matrix containing translational terms Multiplicative and translational terms can be combined bi d into i t a single i l matrix t i if we expand d the th representations to 3x3 A three-element representation p (x ( h, yh, h), ), called homogeneous coordinates, where the homogeneous parameter h is a nonzero value such that

14

Rotation Matrix

Scaling Matrix

01074410 / 13016218 Computer Graphics

15

Inverse Transformations

16

Two-Dimensional Composite Transformations

Forming products of transformation matrices is often referred to as a concatenation, or composition, of matrices We do premultiply the column matrix by the matrices representing any transformation sequence Si Since many positions iti in i a scene are typically t i ll transformed by the same sequence, it is more efficient to first multiply the transformation matrices to form f a single i l composite i matrix i

17

Composite Two-Dimensional Translations

If two successive translation vectors (t1x, t1y) and (t2x, t2y) are applied to a 2-D coordinate position P, the final transformed location P is

18

19

Composite Two-Dimensional Scalings

For two successive scaling operations in 2-D 2 D produces the following composite scaling matrix

20

General Two-Dimensional Pivot-Point Rotation

Graphics package provides only a rotate function with respect to the coordinate origin To generate a 2-D rotation about any other pivot point (xr, yr), follows the sequence of t translate-rotate-translate l t t t t l t operations ti
1. 2. 3.

Translate the object so that the pivot-point position is moved to the coordinate origin Rotate the object about the coordinate origin Translate the object so that the pivot point is g position p returned to its original

21

22

General Two-Dimensional Fixed-Point Scaling

1. 2. 3.

Translate the object so that the fixed point coincides with the coordinate origin Scale the object with respect to the coordinate origin U the Use th inverse i of f the th translation t l ti in i step t (1) to t return t th the object to its original position

23

To accomplish the scaling without changing the orientation of the object

1. 2. 3.

Performs a rotation so that the directions for s1 and s2 coincide with the x and y axes Scaling transformation S(s1, s2) is applied An opposite rotation to return points to their original orientations

24

Example of Scaling Transformation

Turn a unit square into a parallelogram by stretching it along the diagonal from (0, 0) to (1, 1)

Rotate the diagonal onto the y axis using = 45 Double its length with the scaling values s1=1 and s2=2 Rotate again to return the diagonal to its original orientation

25

Depending upon the order in which the transformations

by multiplying from left-to-right (premultiplying) by multiplying from right-to-left right to left (postmultiplying) In OpenGL's convention:

In DX's convention:

26

Transformation products may not be commutative

M2 M1 is not equal to M1 M2 Be careful about the order to translate and rotate an object

27

General Two-Dimensional Composite Transformations and Computational Efficiency

From (5 (5.41), 41) it requires 9 multiplications and 6 additions Actually, only 4 multiplications and 4 additions
Once matrix is concatenated, it is maximum number of computations required Without concatenation, individual transformations would be applied one at a time, and the number of calculations could be significantly increased
28

Computational Efficiency (2)

Rotation calculations require trigonometric evaluations and several multiplications Computational efficiency can become an important consideration in rotation transformations For small enough angles (less than 10), cos is approximately i t l 1.0 1 0 and d sin i h has a value l very close l to t the value of in radians

29

Computational Efficiency (3)

Composite transformations often involve inverse matrices Operations are much simpler than direct inverse matrix calculations

Inverse translation matrix is obtained by changing the signs of the translation distances Inverse rotation matrix is obtained by performing a matrix transpose
30

Two-Dimensional Rigid-Body Transformation

All angles and distances between coordinate positions are unchanged by the t transformation f ti Upper-left 2x2 submatrix is an orthogonal matrix

Two row vectors (rxx, rxy) and (ryx, ryy) (or the two column vectors) form an orthogonal set of unit vectors t Set of vectors is also referred to as an orthonormal vector set
31

Two-Dimensional Rigid-Body Transformation (2)

Each vector has unit length Their dot product is 0 If these unit vectors are transformed by the rotation sub-matrix, then

Example,

32

Constructing Two-Dimensional Rotation Matrices

The orthogonal property of rotation matrices is useful for constructing the matrix when we know the final orientation of an object In modeling application, application we can obtain the transformation matrix within objects co-or system when knowing its orientation within overall word co-or system

33

Reflection Shear

01074410 / 13016218 Computer Graphics

34

Reflection

Reflection about the line y = 0 (the x axis) is accomplished with the transformation matrix

A reflection about the line x = 0 (the y axis) flips x coordinates while keeping y coordinates the same

35

Reflection (2)

01074410 / 13016218 Computer Graphics

36

Shear

A transformation that distorts the shape of an object The transformed shape appears as if the object were composed of internal layers that had been caused to slide over each other An x-direction shear relative to the x axis

37

Shear (2)

38

Raster Methods for Geometric Transformations

All bit settings in the rectangular area shown are copied as a block into another part of the frame buffer

Rotate a two-dimensional object or pattern 90 counterclockwise by g the pixel p values in each row of the array, y, then interchanging g g reversing rows and columns

39

Raster Methods for Geometric Transformations (2)

For array rotations that are not multiples of 90, we need to do some extra processing Si il methods Similar h d to scale l a block bl k of f pixels i l

40

Transformations between TwoDimensional Coordinate Systems

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 co-or or to xy x y co-or co or
1. 2.

Translate so that the origin (x0, y0) of the xy system is moved to the origin (0, 0) of the xy system Rotate the x axis onto the x axis

41

Transformations between 2-D Coordinate Systems (2)

Alternative method Specify a vector V that indicates the direction for the positive y 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

42

Geometric Transformations in Three-Dimensional Space

A position P=(x, y, z) in 3-D is translated to a location P=(x, y, z) by adding translation distances tx, ty, and tz

01074410 / 13016218 Computer Graphics

43

3-Dimensional Rotation

z-axis rotation

44

3-Dimensional Rotation (2)

Transformation equations for rotations about the other two coordinate axes can be obtained with a cyclic y permutation p of the coordinate parameters p x, y, y and z
xyzx

45

x-axis rotation

y-axis rotation

46

Composite Three-Dimensional Transformations

A rotation matrix for any axis that does not coincide with a coordinate axis
1. 2 2. 3.

Translate the object so that the rotation axis coincides with the parallel coordinate axis Perform the specified rotation about that axis Translate the object so that the rotation axis is g position p moved back to its original

47

where he e

48

Composite Three-Dimensional Transformations (3)

Rotate about an axis that is not parallel to one of the coordinate axes Transformation requires 5 steps
1. 2. 3. 4. 5.

Translate the object so that the rotation axis passes through the coordinate origin Rotate the object so that the axis of rotation coincides with one of the coordinate axes Perform the specified rotation about the selected coordinate axis Apply inverse rotations to bring the rotation axis back to its original orientation Apply the inverse translation to bring the rotation axis back to its original spatial position
49

50

Move the point P1 to the origin

x-axis rotation g gets u into the xz plane p y-axis rotation swings u around to the z axis
51

Rotation matrix

52

Composite Three-Dimensional Transformations (7)

Resulting from the rotation about x axis is a vector labeled u Rotation angle The transformation matrix for rotation of u u about the y axis is

53

Composite Three-Dimensional Transformations (8)

The rotation axis is aligned with the positive z axis Apply the specified rotation angle

To complete the required rotation about the given axis, we need to transform the rotation axis back to its original position

54

A more efficient method

Require less storage space than 4x4 matrices Important in animations, which often require complicated motion sequences and motion interpolations between two given positions of an object
q=(a,b,c) MR() = Rx-1() Ry-1() Rz() Ry() Rx()

55

Scaling

56

Reflection

Shear

57

Transformations between ThreeDimensional Coordinate Systems

An xyz system is defined with respect to an xyz system To transfer the xyz coordinate descriptions to the xyz system

Translation that brings the xyz coordinate origin to the xyz origin A sequence of f rotations that h align l corresponding d coordinate d axes A scaling transformation may also be necessary
T(-x0, -y0, -z0)

The composition matrix is RT

01074410 / 13016218 Computer Graphics 58

Affine Transformations

To represent affine transformations with matrices, we must use homogeneous coordinates

a 2-vector (x, y) as a 3-vector (x, y, 1), and similarly for higher dimensions Translation can be expressed with matrix multiplication

59

01074410 / 13016218 Computer Graphics

Affine Transformations

An affine transformation is a form of coordinate transformation

Having H i the th general l properties ti that th t parallel ll l lines li are transformed t f d into parallel lines and finite points map to finite points Examples

An affine transformation involving only translation, rotation, and reflection preserves angles and lengths lengths, as well as parallel lines

Translation, rotation, scaling, reflection, and shear Conversion of coordinate descriptions from one reference system to another

60

Basic OpenGL Geometric Transformations

glTranslate* (tx, ty, tz); glTranslatef (25 (25.0, 0 -10.0, -10 0 0.0); 0 0); glRotate* (theta, vx, vy, vz); glRotatef (90.0, 0.0, 0.0, 1.0); glScale* (sx (sx, sy sy, sz); glScalef (2.0, -3.0, 1.0);

61

End of Chapter 5

62