48
© 2005 Pearson Education © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson Education Computer Graphics with OpenGL 3e

Embed Size (px)

Citation preview

Page 1: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson Education© 2005 Pearson Education

Computer Graphicswith OpenGL 3e

Page 2: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson Education© 2005 Pearson Education

Chapter 5Geometric

Transformations

Page 3: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Geometric Transformations

• Basic transformations:– Translation– Scaling– Rotation

• Purposes:– To move the position of objects– To alter the shape / size of objects– To change the orientation of objects

Page 4: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Basic two-dimensional geometric transformations (1/1)

• Two-Dimensional translation– One of rigid-body transformation, which move objects without

deformation– Translate an object by Adding offsets to coordinates to generate

new coordinates positions

– Set tx,ty be the translation distance, we have

– In matrix format, where T is the translation vector

xtx'x yty'y

y

xP

y

x

t

tT

'y

'x'P

TP'P

Page 5: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

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

Basic two-dimensional geometric transformations (1/2)

Page 6: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Translation Example

y

x0 1

1

2

2

3 4 5 6 7 8 9 10

3

4

5

6

(1, 1) (3, 1)

(2, 3)

Page 7: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Basic two-dimensional geometric transformations (2/1)

• Two-Dimensional rotation– Rotation axis and angle are specified for rotation– Convert coordinates into polar form for calculation

– Example, to rotation an object with angle a• The new position coordinates

• In matrix format

• Rotation about a point (xr, yr)

cosrx sinyy

cossin

sincosR PR'P

cossinsinsinsincos)sin('

sincossinsincoscos)cos('

yxrrry

yxrrrx

cos)(sin)('

sin)(cos)('

rrr

rrr

yyxxyy

yyxxxx

r

r

Page 8: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

– This figure shows the rotation of the house by 45 degrees.

• Positive angles are measured counterclockwise (from x towards y)

• For negative angles, you can use the identities:– cos(-) = cos() and sin(-)=-sin()

Basic two-dimensional geometric transformations (2/2)

6

y

x 0 1

1

2

2

3 4 5 6 7 8 9 10

3

4

5

6

Page 9: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Rotation Example

y

0 1

1

2

2

3 4 5 6 7 8 9 10

3

4

5

6

(3, 1) (5, 1)

(4, 3)

Page 10: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Basic two-dimensional geometric transformations (3/1)

• Two-Dimensional scaling– To alter the size of an object by multiplying the coordinates

with scaling factor sx and sy

– In matrix format, where S is a 2by2 scaling matrix

– Choosing a fix point (xf, yf) as its centroid to perform scaling

xsx'x ysyy

y

x

s0

0s

'y

'x

y

x PS'P

)s1(ysy'y

)s1(xsx'x

yfy

xfx

Page 11: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

– 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

Basic two-dimensional geometric transformations (3/2)

Page 12: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Scaling

Note: House shifts position relative to origin

y

x 0

1

1

2

2

3 4 5 6 7 8 9 10

3

4

5

6

1

2

1

3

3

6

3

9

– If the scale factor had been greater than 1, it would be larger and farther away.

WATCH OUT: Objects grow and move!

Page 13: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Scaling Example

y

0 1

1

2

2

3 4 5 6 7 8 9 10

3

4

5

6

(1, 1) (3, 1)

(2, 3)

Page 14: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Homogeneous Coordinates

• A point (x, y) can be re-written in homogeneous

coordinates as (xh, yh, h)

• The homogeneous parameter h is a non-zero value such that:

• We can then write any point (x, y) as (hx, hy, h)

• We can conveniently choose h = 1 so that

(x, y) becomes (x, y, 1)

h

xx h

h

yy h

Page 15: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Why Homogeneous Coordinates?

• Mathematicians commonly use homogeneous coordinates as they allow scaling factors to be removed from equations • We will see in a moment that all of the transformations we discussed previously can be represented as 3*3 matrices• Using homogeneous coordinates allows us use matrix multiplication to calculate transformations – extremely efficient!

Page 16: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Homogenous Coordinates

• Combine the geometric transformation into a single matrix with 3by3 matrices

• Expand each 2D coordinate to 3D coordinate with homogenous parameter

• Two-Dimensional translation matrix

• Two-Dimensional rotation matrix

• Two-Dimensional scaling matrix

1

y

x

100

t10

t01

1

'y

'x

y

x

1

y

x

100

0cossin

0coscos

1

'y

'x

1

y

x

100

0s0

00s

1

'y

'x

y

x

Page 17: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Inverse transformations

• Inverse translation matrix

• Two-Dimensional translation matrix

• Two-Dimensional translation matrix

100

t10

t01

T y

x1

100

0cossin

0sincos

R 1

100

0s

10

00s

1

Sx

x

1

Page 18: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Page 19: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Page 20: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Page 21: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Page 22: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Page 23: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Page 24: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Page 25: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Basic 2D Transformations

• Basic 2D transformations as 3x3 Matrices

1100

10

01

1

y

x

ty

tx

y

x

1100

0cossin

0sincos

1

y

x

y

x

1100

00

00

1

y

x

sy

sx

y

x

1100

01

01

1

y

x

shy

shx

y

x

Translate

Shear

Scale

Rotate

Page 26: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Geometric transformations in three-dimensional space (1)

• Extend from two-dimensional transformation by includingconsiderations for the z coordinates

• Translation and scaling are similar to two-dimension, include the three Cartesian coordinates

• Rotation method is less straight forward• Representation

– Four-element column vector for homogenous coordinates

– Geometric transformation described 4by4 matrix

Page 27: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Geometric transformations in three-dimensional space (2)

• Three-dimensional translation– A point P (x,y,z) in three-dimensional space translate to new

location with the translation distance T (tx, ty, tz)

– In matrix formatxtx'x yty'y

1

z

y

x

1000

t100

t010

t001

1

'z

'y

'x

z

y

x

PT'P

ztz'z

Page 28: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Geometric transformations in three-dimensional space (3)

• Three-dimensional scaling– Relative to the coordinate origin, just include the parameter

for z coordinate scaling in the transformation matrix

– Relative to a fixed point (xf, yf zf)

• Perform a translate-scaling-translate composite transformation

1000

z)s1(s00

y)s1(0s0

x)s1(00s

)z,y,x(T)s,s,s(S)z,y,x(t

fzz

fyy

fxx

fffzyxfff

PS'P

1

z

y

x

1000

0s00

00s0

000s

1

'z

'y

'x

z

y

x

Page 29: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Geometric transformations in three-dimensional space (4)

• Three-dimensional rotation definition– Assume looking in the negative direction along the axis– Positive angle rotation produce counterclockwise

rotationsabout a coordinate axis

Page 30: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Geometric transformations in three-dimensional space (5)

• Three-dimensional coordinate-axis rotation– Z-axis rotation equations

– Transformation equations for rotation about the other two coordinate axes can be obtained by a cyclic permutation

x y z x– X-axis rotation equations

x'x

coszsiny'z

sinzcosy'y

1

z

y

x

1000

0100

00cossin

00sincos

1

'z

'y

'x

z'z

cosysinx'y

sinycosx'x

Rz

1000

0cossin0

0sincos0

0001

xx RR

Page 31: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Geometric transformations in three-dimensional space (6)

• Three-dimensional coordinate-axis rotation– Y-axis rotation equations

– General Three-dimensional rotations• Translate object so that the rotation axis coincides with the parallel

coordinate axis• Perform the specified rotation about that axis• Translate object back to the original position

y'y

cosxsinz'x

sinxcosz'z

T)(RT)(R

PT)(RT'P

x1

x1

1000

0cos0sin

0010

0sin0cos

yy RR

Page 32: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

• Inverse of a rotation matrix

RR 1

sinsin,coscos

1000

0100

00cossin

00sincos

1000

0100

00cossin

00sincos

1

zz RR

TRR 1 : orthogonal matrix

Geometric transformations in three-dimensional space (7)

Page 33: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Concatenation of Transformations

• Concatenating– affine transformations by multiplying together– sequences of the basic transformations

define an arbitrary transformation directly– ex) three successive transformations

CBApApBCq

A B Cp q

CBAM

Mpq Mp q

CBA

p1 = App2 = Bp1q = Cp2

q = CBp1q = CBAp

p1 p2

Page 34: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Matrix Concatenation Properties

• Associative properties

• Transformation is not commutative (CopyCD!)– Order of transformation may affect transformation

position

321321321 M)MM()MM(MMMM

Page 35: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Two-dimensional composite transformation (1)

• Composite transformation– A sequence of transformations

– Calculate composite transformation matrix rather than applying individual transformations

• Composite two-dimensional translations– Apply two successive translations, T1 and T2

– Composite transformation matrix in coordinate form

PM'P

PMM'P 12

PTTPTTP

ttTT

ttTT

yx

yx

)()('

),(

),(

1212

222

111

)tt,tt(T)t,t(T)t,t(T y2y1x2x1y1x1y2x2

Page 36: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Two-dimensional composite transformation (2)

• Composite two-dimensional rotations– Two successive rotations, R1 and R2 into a point P

– Multiply two rotation matrices to get composite transformation matrix

• Composite two-dimensional scaling

P)}(R)(R{'P

}P)(R{)(R'P

21

21

P)ss,ss(S'P

)ss,ss(S)s,s(S)s,s(S

y2y1x2x1

y2y1x2x1y2x2y1x1

P)(R'P

)(R)(R)(R

21

2121

Page 37: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Two-dimensional composite transformation (3)

• General two-dimensional Pivot-point rotation– Graphics package provide only origin rotation– Perform a translate-rotate-translate sequence

• Translate the object to move pivot-point position to origin

• Rotate the object

• Translate the object back to the original position

– Composite matrix in coordinates form),y,x(R)y,x(T)(R)y,x(T rrrrrr

Page 38: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Two-dimensional composite transformation (4)

• Example of pivot-point rotation

Page 39: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Pivot-Point Rotation

100

sin)cos1(cossin

sin)cos1(sincos

100

10

01

100

0cossin

0sincos

100

10

01

rr

rr

r

r

r

r

xy

yx

y

x

y

x

,,,, rrrrrr yxRyxTRyxT

Translate Rotate Translate

(xr,yr)

(xr,yr)

(xr,yr)

(xr,yr)

Page 40: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Two-dimensional composite transformation (5)

• General two-dimensional Fixed-point scaling– Perform a translate-scaling-translate sequence

• Translate the object to move fixed-point position to origin

• Scale the object wrt. the coordinate origin

• Use inverse of translation in step 1 to return the object back to the original position

– Composite matrix in coordinates form)s,s,y,x(S)y,x(T)s,s(S)y,x(T yxffffyxff

Page 41: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Two-dimensional composite transformation (6)

• Example of fixed-point scaling

Page 42: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

General Fixed-Point Scaling

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 43: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Two-dimensional composite transformation (7)

• General two-dimensional scaling directions– Perform a rotate-scaling-rotate sequence– Composite matrix in coordinates form

100

0cosssinssincos)ss(

0sincos)ss(sinscoss

)(R)s,s(S)(R

22

2112

122

22

1

211

s1

s2

Page 44: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

General Scaling Directions

• Converted to a parallelogram

100

0cossinsincos)(

0sincos)(sincos

)(),()( 22

2112

122

22

1

211

ssss

ssss

RssSR

x

y

(0,0)

(3/2,1/2)

(1/2,3/2)

(2,2)

x

y

(0,0) (1,0)

(0,1) (1,1)

x

y s2

s1

Scale

Page 45: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

General Rotation (1/2)

• Three successive rotations about the three axes

rotation of a cube about the z axis rotation of a cube about the y axis

rotation of a cube about the x axis

?

Page 46: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

General Rotation (2/2)

zyx RRRR

1000

0100

00cossin

00sincos

1000

0cos0sin

0010

0sin0cos

1000

0cossin0

0sincos0

0001

Page 47: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Instance Transformation (1/2)

• Instance of an object’s prototype– occurrence of that object in

the scene

• Instance transformation– applying an affine

transformation to the prototype to obtain desired size, orientation, and location

?

instance transformation

Page 48: © 2005 Pearson Education Computer Graphics with OpenGL 3e

© 2005 Pearson© 2005 Pearson EducationEducationComputer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved

Instance Transformation (2/2)

TRSM

1000

000

000

000

1000

0100

00cossin

00sincos

1000

100

010

001

z

y

x

z

y

x