Top Banner
Transformation of Graphics University of Science and Technology of Beijing 沈沈沈 د ی ی رما ف ت ی رعا را وت ک س ا ف لط.
69

Transformation of Graphics

Jan 03, 2016

Download

Documents

kelly-weeks

Transformation of Graphics. University of Science and Technology of Beijing 沈政伟. What is geometric transformation? Operations that are applied to the geometric description of an object to change its position, orientation, or size are called geometric transformations. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Transformation of Graphics

Transformation of Graphics

University of Science and Technology of Beijing

沈政伟

.لطفا سکوت را رعایت فرمایید

Page 2: Transformation of Graphics

• What is geometric transformation?

• Operations that are applied to the geometric description of an object to change its position, orientation, or size are called geometric transformations.

.لطفا سکوت را رعایت فرمایید

Page 3: Transformation of Graphics

• So the geometric-transformation functions that are available in some system are following:

1. Translation2. Rotation 3. Scaling 4. Other useful transforms includes: reflection

and shear.

In our lesson, we first consider operation in two dimensions, then we discuss how these basic ideas can be extended to three-dimensional scenes.

.لطفا سکوت را رعایت فرمایید

Page 4: Transformation of Graphics

• Translation

• Rotation

.لطفا سکوت را رعایت فرمایید

Page 5: Transformation of Graphics

• Scaling

• Uniform Scaling

• Un-uniform Scaling

.لطفا سکوت را رعایت فرمایید

Page 6: Transformation of Graphics

• Reflection

• Shear

.لطفا سکوت را رعایت فرمایید

Page 7: Transformation of Graphics

• Why do we need geometric transformations in CG( motivation )?

• As a viewing aid

• As a modeling tool

• As an image manipulation tool

.لطفا سکوت را رعایت فرمایید

Page 8: Transformation of Graphics

• Two-Dimensional(2D) Translation

We perform a translation on a single coordinate point by adding offsets to its coordinates so as to generate a new coordinate position.

Similarly, a translation is applied to an object that is defined with multiple coordinate positions by relocating all the coordinate positions by the same displacement along parallel paths.

Suppose tx and ty is the translation distances, (x, y) is the original coordinates, is the new coordinate position.

txxx y y ty

'( , ')x y

.لطفا سکوت را رعایت فرمایید

Page 9: Transformation of Graphics

• Express the translation use matrix equation as following:

• Translation is a rigid-body transformation that moves objects without deformation.

x x tx

y y ty

Question : How to translate a line segment or a polygon?

.لطفا سکوت را رعایت فرمایید

Page 10: Transformation of Graphics

• Two-Dimensional Rotation• We generate a rotation transformation of an object

by specifying a rotation axis and a rotation angle. All points of the object are then transformed to new positions by rotating the points through the specified angle about the rotation axis.

• A 2D rotation of an object is obtained by repositioning the object along a circular path in the xy plane, the rotation axis is perpendicular to the xy plane.

• Parameters for 2D rotation is rotation angle and a rotation point( pivot point) .

• Rotation angle define a positive values for counterclockwise rotation about the pivot point.

),( rr yx

.لطفا سکوت را رعایت فرمایید

Page 11: Transformation of Graphics

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

• Substitute expression (1) into (2)

cos

sin

x r

y r

cossinsincos)sin('

sinsin-coscos)cos('

rrry

rrrx

( 1)

( 2)

.لطفا سکوت را رعایت فرمایید

Page 12: Transformation of Graphics

Matrix form

' cos sin

' sin cos

x x y

y x y

( 3)

cos sin

sin cosx y x y

.لطفا سکوت را رعایت فرمایید

Page 13: Transformation of Graphics

• Question 1:• If the rotation point is an arbitrary pivot position ,

can you give the correct rotation expression?

• How to rotate a line segment or a polygon?

),( rr yx

' ( ) cos ( )sin

' ( )sin ( )cosr r r

r r r

x x x x y y

y y x x y y

( 3)

.لطفا سکوت را رعایت فرمایید

Page 14: Transformation of Graphics

.لطفا سکوت را رعایت فرمایید

Page 15: Transformation of Graphics

.لطفا سکوت را رعایت فرمایید

Page 16: Transformation of Graphics

• Two-Dimensional(2D) Scaling• To alter the size of an object, we apply a scaling

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

• Scaling factors sx scales an object in the x coordinate.

),( rr yx

'

'x

y

x x S

y y S

0

0x

y

Sx y x y

S

لطفا سکوت را رعایت فرمایید.

Page 17: Transformation of Graphics

• Properties of the scaling transformation.

• Any positive values can be assigned to the scaling factors sx and sy. Values less then 1 reduce the size of object, the object will close up the original at the same time. In contrast , enlarge the size of object.

• When sx and sy are assigned to the same values, a uniform scaling is produced which maintains relative object proportions.

.لطفا سکوت را رعایت فرمایید

Page 18: Transformation of Graphics

• Unequal values for sx and sy result in a differential scaling that is often used in design applications.

• Negative values can also be specified for the scaling parameters, this not only resizes an object, it reflects the object one or more of the coordinate axes.

.لطفا سکوت را رعایت فرمایید

Page 19: Transformation of Graphics

.لطفا سکوت را رعایت فرمایید

Page 20: Transformation of Graphics

.لطفا سکوت را رعایت فرمایید

Page 21: Transformation of Graphics

• Matrix Representations and Homogeneous Coordinates

• It is well known that many application involves sequences of geometric transformations. For example, an animation might require an object to be translated, rotated and scaled at each increment of the motion. If you want to first rotates an object, then scales it, you can combine those two transformation to a composite transformation like the following equation:

• 0 cos sincos sin

* 0 sin cossin cosx x x

y y y

S S SA S R

S S S

.لطفا سکوت را رعایت فرمایید

Page 22: Transformation of Graphics

• However, it will be difficult to deal with the above composite transformation and translation together. Because, translation is not 2 by 2 matrix representation.

• So ,here we consider how the matrix representations discussed in the previous sections can be reformulated so that such transformation sequences can be efficiently processed.

.لطفا سکوت را رعایت فرمایید

Page 23: Transformation of Graphics

• In fact, we can expressed three basic two-dimensional transformation( translation, rotation, and scaling) in the general matrix form:

• Now this equation can be reformulated to eliminate the matrix addition operation using Homogeneous Coordinates.

21' MPMP

.لطفا سکوت را رعایت فرمایید

Page 24: Transformation of Graphics

• What is Homogeneous Coordinates?• A standard technique for expanding each two-

dimensional coordinate position representation (x, y) to three-element representation , called Homogeneous Coordinates, where homogeneous h is a nonzero value such that

• • For geometric transformation, we can chose the

homogeneous parameter h to be any nonzero value. Thus there are an infinite number of equivalent homogeneous representations for each coordinate point (x, y) .

( , , )h hx y h

,h hx yx y

h h

.لطفا سکوت را رعایت فرمایید

Page 25: Transformation of Graphics

• A convenient choice is simply to set h=1, so each two-dimensional position is then represented with homogeneous coordinate (x,y,1).

• Expressing positions in homogenous coordinates allows us to represent all geometric transformation equations as matrix multiplications, which is the standard method used in graphics systems. Two dimensional coordinate positions are represented with three-elements column vectors, and two-dimensional transformation operations are expressed as 3X3 matrices. .لطفا سکوت را رعایت فرمایید

Page 26: Transformation of Graphics

• Homogeneous coordinate representation of 2D Translation

• This translation operation can be written in the abbreviated form

1100

10

01

1

y

x

ty

tx

y

x

' ( , )x yP T t t P

.لطفا سکوت را رعایت فرمایید

Page 27: Transformation of Graphics

• Homogeneous coordinate representation of 2D Rotation

' ( )P R P

This translation operation can be written in the abbreviated form

1100

0cossin

0sincos

1

y

x

y

x

.لطفا سکوت را رعایت فرمایید

Page 28: Transformation of Graphics

• Homogeneous coordinate representation of 2D Scaling

1100

00

00

1

y

x

sy

sx

y

x

' ( , )P S sx sy P

This scaling operation can be written in the abbreviatedform

.لطفا سکوت را رعایت فرمایید

Page 29: Transformation of Graphics

• Properties of homogeneous coordinate 2D transformation.

• (1) translation and rotation have additive properties.

• (2) scaling transformation has multiplicative properties.

( , ) ( , ) ( , )x y h l x h y lT t t T t t T t t t t

1 2 1 2( ) ( ) ( )R R R

( , ) ( , ) ( , )S sx st S sh sl S sx sh st sl

.لطفا سکوت را رعایت فرمایید

Page 30: Transformation of Graphics

• Question :

• Write out the inverse homogeneous matrix representation of 2D transformation.

.لطفا سکوت را رعایت فرمایید

Page 31: Transformation of Graphics

• Two-Dimensional Composite Transformation• Using matrix representations, we can set up a

sequence of transformation as a composite transformation matrix, by calculating the product of the individual transformations.

• And, since many positions in a scene are typically transformed by the same sequence, its is more efficient to first multiply the transformation matrices to form a single composite matrix.

• So the coordinate position is transformed using the composite matrix M, rather than applying the individual transformations M1 and then M2

'2 1P M M P

M P

.لطفا سکوت را رعایت فرمایید

Page 32: Transformation of Graphics

• Composite Two-Dimensional Translations, Rotation and Scaling:

( , ) ( , ) ( , )x y h l x h y lT t t T t t T t t t t

1 2 1 2( ) ( ) ( )R R R

( , ) ( , ) ( , )S sx st S sh sl S sx sh st sl

.لطفا سکوت را رعایت فرمایید

Page 33: Transformation of Graphics

• General Two-Dimensional Pivot-Point Rotation

• So we can generate a 2D rotation about any other pivot point (x, y) by performing the following sequence of translate-rotate-translate operations.

(xr,yr)

(xr,yr)

(xr,yr)

(xr,yr)

.لطفا سکوت را رعایت فرمایید

Page 34: Transformation of Graphics

• (1) Translate the object so that the pivot-point position is moved to the coordinate origin.

• (2) Rotate the object about the coordinate origin.• (3) Translate the object so that the pivot point is

returned to its original position.• The composite transformation matrix for this

sequence is obtained with the concatenation:

1 0 1 0 cos sin (1 cos ) sincos sin 0

0 1 sin cos 0 0 1 sin cos (1 cos ) sin

0 0 10 0 1 0 0 1 0 0 1

r r r r

r r r r

x x x y

y y y x

.لطفا سکوت را رعایت فرمایید

Page 35: Transformation of Graphics

• Which can be expressed in the form

( , ) ( ) ( , ) ( , , )r r r r r rT x y R T x y R x y

.لطفا سکوت را رعایت فرمایید

Page 36: Transformation of Graphics

• Similarly, we can obtain the matrix representation of General 2D Fixed-Point Scaling.( question ).

• (1) Translate the object to so that the fixed point coincides with the coordinate origin.

• (2) Scale the object with respect to the coordinate origin.

• (3) Use the inverse of the translation in step (1) to return the object to its original position.

.لطفا سکوت را رعایت فرمایید

Page 37: Transformation of Graphics

100

)1(0

)1(0

100

10

01

100

00

00

100

10

01

yfy

xfx

f

fx

f

f

sys

sxs

y

x

s

s

y

x

y

Translate Scale Translate

(xr,y

r)(xr,yr)

(xr,yr)

(xr,yr)

yxffffyxff ssyxSyxTssSyxT ,,,, ,,

.لطفا سکوت را رعایت فرمایید

Page 38: Transformation of Graphics

• We also obtain General 2D Scaling Directions.• Suppose we want to apply scaling factors with

values specified by parameters s1 and s2 in the directions shown in the following fig.

.لطفا سکوت را رعایت فرمایید

Page 39: Transformation of Graphics

• To accomplish the scaling without changing the orientation of the object.(1) we perform a rotation so that the directions for s1 and s2 coincide with the x and y axes, respectively.

(2) Then the scaling transformation S(s1,s2) is applied.

(3) An opposite rotation to return points to their original orientations.

.لطفا سکوت را رعایت فرمایید

Page 40: Transformation of Graphics

100

0cossinsincos)(

0sincos)(sincos

)(),()( 22

2112

122

22

1

211

ssss

ssss

RssSR

.لطفا سکوت را رعایت فرمایید

Page 41: Transformation of Graphics

• For example, we turn a unit square into a parallelogram by stretching it along the diagonal from (0,0) to (1,1).

x

y

(0,0)

(3/2,1/2)

(1/2,3/2)

(2,2)

x

y

(0,0) (1,0)

(0,1) (1,1)

Scale

.لطفا سکوت را رعایت فرمایید

Page 42: Transformation of Graphics

• We first rotate the diagonal onto the y axis using angle 45 degree. Then we double its length with the scaling values s1=1 and s2=2, and then we rotate again to return the diagonal to its original orientation.

.لطفا سکوت را رعایت فرمایید

Page 43: Transformation of Graphics

• Matrix Concatenation Properties

• (1) Multiplication of matrices is associative.

• (2) Transformation products, on the other hand, may not be commutative.

.لطفا سکوت را رعایت فرمایید

Page 44: Transformation of Graphics

• Other 2D transformations:

• Reflection with respect to the axis

• • X axis • y axis • original point

100

010

001

100

010

001

100

010

001

x

y 1

32

1’

3’2’x

y1

32

1’

3’ 2

x

y

3

1’

3’ 2

1

2

.لطفا سکوت را رعایت فرمایید

Page 45: Transformation of Graphics

• Reflection with respect to a line

100

001

010

x

y

.لطفا سکوت را رعایت فرمایید

Page 46: Transformation of Graphics

Shear

.لطفا سکوت را رعایت فرمایید

Page 47: Transformation of Graphics

Three-Dimensional Transformations

.لطفا سکوت را رعایت فرمایید

Page 48: Transformation of Graphics

• Methods for geometric transformations in three dimensions are extended from two-dimensional methods by including considerations for the z coordinate.

• A three-dimensional position, expressed in homogeneous coordinates, is represented as a four-element column vector. Thus , each geometric transformation operator is now 4 by 4 matrix.

.لطفا سکوت را رعایت فرمایید

Page 49: Transformation of Graphics

• We can express the 3D translation operation in matrix form.

1 0 0

0 1 0

0 0 1

1 0 0 0 1 1

x

y

z

x t x

y t y

z t z

' ' ', ,x y zx x t y y t z z t

.لطفا سکوت را رعایت فرمایید

Page 50: Transformation of Graphics

• Three-Dimensional Rotation

• (1) 3D Coordinate-Axis Rotations

• z-axis rotation (counter-clockwise)

.لطفا سکوت را رعایت فرمایید

Page 51: Transformation of Graphics

• x-axis rotation (counter-clockwise)

.لطفا سکوت را رعایت فرمایید

Page 52: Transformation of Graphics

•y-axis rotation (counter-clockwise)

.لطفا سکوت را رعایت فرمایید

Page 53: Transformation of Graphics

• General 3D Rotations

• (1) Rotating about an axis that is parallel to one of the coordinates axes.

• Step1, Translate the object so that the rotation axis coincides with the parallel coordinate axis.

• Step2, Perform the specified rotation about that axis.

• Step3, Translate the object so that rotation axis is moved back to its original.

.لطفا سکوت را رعایت فرمایید

Page 54: Transformation of Graphics

• A coordinate position P is transformed with the sequence

' 1 ( )xP T R T P

.لطفا سکوت را رعایت فرمایید

Page 55: Transformation of Graphics

• (2) Rotated about an axis that is not parallel to one of the coordinate axes.

• In this case, we also need rotation to align the rotation axis with a selected coordinate axis and then to bring the rotation axis back to its original orientation.

• A rotation axis can be defined with two coordinate position, or one position and direction angles (direction cosines ).

• Now we assume that the rotation axis is defined by two points, and that the direction of rotation is to be counter clockwise when looking along the axis from p2 to p1.لطفا سکوت را رعایت فرمایید.

Page 56: Transformation of Graphics

• The components of the rotation axis vector are then computed as:

• And the unit rotation-axis vector u is

• Where

2 1

2 1 2 1 2 1( , , )

V P P

x x y y z z

( , , )V

u a b cV

2 1 2 1 2 1, ,x x y y z z

a b cV V V

.لطفا سکوت را رعایت فرمایید

Page 57: Transformation of Graphics

• Step1. Translate the object so that the rotation axis passes through the coordinate origin

• Step2, Rotate the object so that the axis of rotation coincides with one of the coordinate axes.

• Step3, Perform the specified rotation about the selected coordinate axis

• Step4, Apply inverse rotations to bring the rotation axis back to its original orientation.

• Step5 ,Apply the inverse translation to bring the rotation axis to its original spatial position.

• we can transform the rotation axis onto any one of the three coordinate axes. But the z axis is often a convenient choice.لطفا سکوت را رعایت فرمایید.

Page 58: Transformation of Graphics

.لطفا سکوت را رعایت فرمایید

Page 59: Transformation of Graphics

.لطفا سکوت را رعایت فرمایید

Page 60: Transformation of Graphics

• The first step in the rotation sequence is to set up the translation matrix that repositions the rotation axis so that it passes through the coordinate origin. We move p1 to the origin.

.لطفا سکوت را رعایت فرمایید

Page 61: Transformation of Graphics

• The next step we will put the rotation axis onto the z axis. We can use the coordinate-axis rotations to accomplish this alignment in two steps. For this example, we first rotate about the x axis, then rotate about y axis. The x axis rotation gets vector u into the x-z plane, and the y-axis rotation swings u around to the z axis.

x

z

yu

.لطفا سکوت را رعایت فرمایید

Page 62: Transformation of Graphics

• Since rotation calculations involve sine and cosine functions, so we can use standard vector operation to obtain elements of the two rotation matrices. A vector dot product can be used to determine the cosine term, and a vector cross product can be used to calculate the sine term.

• Firstly, we establish the transformation matrix for rotation around the x axis by determining the values for the sine and cosine of the rotation angle necessary to get u into the x-z plane.

.لطفا سکوت را رعایت فرمایید

Page 63: Transformation of Graphics

• We need the angle between vector u and x-z plane .

• We directly calculate cosine and sine values of .

• If we represent the projection of u in the zoy plane as the vector

• Then the cosine of the rotation angle can be determined from the dot product of and then

unit vector along the z axis.

zz

xx

yy

' (0, , )u b c

'u

zu

'2 2

'cos ( )z

z

u u cd b c

du u

.لطفا سکوت را رعایت فرمایید

Page 64: Transformation of Graphics

Similarly, we can determine the sine of from the cross product of

So

' ' sinz x zu u u u u

'z xu u u b

' sinx z xu u u u b

sinb

d

.لطفا سکوت را رعایت فرمایید

Page 65: Transformation of Graphics

• So the matrix elements for rotation of this vector about the x axis and into the xz plane:

1 0 0 01 0 0 0

0 00 cos sin 0

0 sin cos 00 0

0 0 0 10 0 0 1

x

c b

d dRb c

d d

.لطفا سکوت را رعایت فرمایید

Page 66: Transformation of Graphics

• The rotation matrix about y axis is

cos 0 sin 0 0 0

0 1 0 0 0 1 0 0

sin 0 cos 0 0 0

0 0 0 1 0 0 0 1

y

d a

Ra d

.لطفا سکوت را رعایت فرمایید

Page 67: Transformation of Graphics

• The third step we have aligned the rotation axis with the positive z axis. The specified rotation angle we can now be applied as a rotation about the z axis

cos sin 0 0

sin cos 0 0

0 0 1 0

0 0 0 1

zR

zz

xx

yy

.لطفا سکوت را رعایت فرمایید

Page 68: Transformation of Graphics

• So the transformation matrix for rotation about an arbitrary axis can then be expressed as the composition of these seven individual transformations:

TRRRRRTR xyzyx )()()()()()( 111

.لطفا سکوت را رعایت فرمایید

Page 69: Transformation of Graphics

• 3D Scaling

• The matrix expression for the three-dimensional transformation of a position P=(x,y,z) relative to the coordinate origin is a simple extension of two dimensional scaling

'

'

'

0 0 0

0 0 0

0 0 0

0 0 0 1 11

x

y

z

x S x

S yy

S zz

.لطفا سکوت را رعایت فرمایید