Anda di halaman 1dari 62

Computer p Graphics p

Chapter 5 Geometric Transformations

Somsak Walairacht, Computer Engineering, KMITL


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

01074410 / 13016218 Computer Graphics

Outline (2)

Geometric Transformations in Three-Dimensional Space

Translation Rotation Scaling

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

01074410 / 13016218 Computer Graphics


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

01074410 / 13016218 Computer Graphics

Basic Two-Dimensional Geometric Transformations

Available in all graphics packages are

Translation Rotation Scaling Reflection R fl ti Shearing


Other useful transformation routines are

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)

Translation equations in the matrix

Translation is a rigid-body transformation that moves objects without ith t d deformation f ti


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

01074410 / 13016218 Computer Graphics

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

01074410 / 13016218 Computer Graphics

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

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)

In matrix format, format where S is a 2x2 scaling matrix

01074410 / 13016218 Computer Graphics


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

01074410 / 13016218 Computer Graphics


Matrix Representations and Homogeneous Coordinates

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

01074410 / 13016218 Computer Graphics

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

01074410 / 13016218 Computer Graphics


Matrix Representations and Homogeneous Coordinates

Two-Dimensional Translation Matrix

Rotation Matrix

Scaling Matrix

01074410 / 13016218 Computer Graphics


Inverse Transformations

Inverse translation matrix

Translate in the opposite direction

Inverse rotation matrix

Rotate in the clockwise direction

Inverse scaling matrix

01074410 / 13016218 Computer Graphics


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

01074410 / 13016218 Computer Graphics


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

The composite transformation matrix for this sequence of translations is

01074410 / 13016218 Computer Graphics


Composite Two-Dimensional Rotations

Two successive rotations applied to a point P

We can verify that two successive rotations are additive:

Th composition The iti matrix ti

01074410 / 13016218 Computer Graphics


Composite Two-Dimensional Scalings

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

01074410 / 13016218 Computer Graphics


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

01074410 / 13016218 Computer Graphics


General Two-Dimensional Pivot-Point Rotation (2)

01074410 / 13016218 Computer Graphics


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

01074410 / 13016218 Computer Graphics


General Two-Dimensional Scaling Directions

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

01074410 / 13016218 Computer Graphics


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

01074410 / 13016218 Computer Graphics


Matrix Concatenation Properties

Multiplication of matrices is associative

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:

V'=B*(A*V), V'=(B*A)*V, C=B*A; V'=C*V; V'=(V*A)*B, C=A*B; V'=V*C;

01074410 / 13016218 Computer Graphics


Matrix Concatenation Properties (2)

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

Some special cases the multiplication of transformation matrices is commutative

Two successive rotations give the same final position

01074410 / 13016218 Computer Graphics


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

01074410 / 13016218 Computer Graphics

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

01074410 / 13016218 Computer Graphics


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

01074410 / 13016218 Computer Graphics

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

01074410 / 13016218 Computer Graphics

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


01074410 / 13016218 Computer Graphics


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

01074410 / 13016218 Computer Graphics


Other Two-Dimensional Transformations

Reflection Shear

01074410 / 13016218 Computer Graphics



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

01074410 / 13016218 Computer Graphics


Reflection (2)

Reflection relative to the coordinate origin

Reflection axis as the diagonal line y = x

01074410 / 13016218 Computer Graphics



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

01074410 / 13016218 Computer Graphics


Shear (2)

x-direction shears relative to other reference lines

y-direction shear relative to the line x = xref

01074410 / 13016218 Computer Graphics


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

01074410 / 13016218 Computer Graphics


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

01074410 / 13016218 Computer Graphics


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

01074410 / 13016218 Computer Graphics


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

01074410 / 13016218 Computer Graphics


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


3-Dimensional Rotation

z-axis rotation

01074410 / 13016218 Computer Graphics


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

01074410 / 13016218 Computer Graphics


3-Dimensional Rotation (3)

x-axis rotation

y-axis rotation

01074410 / 13016218 Computer Graphics


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

01074410 / 13016218 Computer Graphics


Composite Three-Dimensional Transformations (2)

A coordinate position P is transformed with the sequence

where he e

01074410 / 13016218 Computer Graphics


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

01074410 / 13016218 Computer Graphics

Composite Three-Dimensional Transformations (4)

01074410 / 13016218 Computer Graphics


Composite Three-Dimensional Transformations (5)

The components of the rotation-axis vector

The unit rotation-axis vector u

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

01074410 / 13016218 Computer Graphics

Composite Three-Dimensional Transformations (6)

Rotate around the x axis to get u into the xz plane

Rotation matrix

|uz| |=1, |u|=d |u | d

01074410 / 13016218 Computer Graphics


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

01074410 / 13016218 Computer Graphics


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

01074410 / 13016218 Computer Graphics


Quaternion Methods for Three-Dimensional Rotations

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()

01074410 / 13016218 Computer Graphics


Other Three-Dimensional Transformations


01074410 / 13016218 Computer Graphics


Other Three-Dimensional Transformations (2)



01074410 / 13016218 Computer Graphics


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

The h functional f l form f x' ' = x + tx; y' ' = y + ty

Any linear transformation can be represented by a general transformation matrix

Translations can be seamlessly intermixed with all other types of t transformations f ti


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

01074410 / 13016218 Computer Graphics


OpenGL GeometricTransformation Functions

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);

OpenGL Matrix Operations

glMatrixMode (GL_MODELVIEW); glMatrixMode (GL_PROJECTION);


01074410 / 13016218 Computer Graphics

End of Chapter 5

01074410 / 13016218 Computer Graphics