Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport...

88
Window to Viewport Transformation 3/13/2020 1

Transcript of Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport...

Page 1: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Window to Viewport

Transformation

3/13/2020 1

Page 2: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Viewing

• Transformation worldscreen

• Clipping: Removing parts outside screen

3/13/2020 2

Page 3: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

3/13/2020

minxw maxxw

minyw

maxywClipping Window

minxv maxxv

minyv

maxyvViewport

Viewport Coordinates

The clipping window is

mapped into a viewport.

Viewing world has its own

coordinates, which may be

a non-uniform scaling of

world coordinates.

World Coordinates

3

Page 4: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

3/13/2020

2D viewing transformation pipeline

Construct World-

Coordinate Scene

From Modeling-

Coordinate

Transformations

World

Coordinates

Modeling

CoordinatesConvert World-

Coordinates to

Viewing-

Coordinates

Viewing Coordinates

Transform Viewing-

Coordinates to

Normalized-

Coordinates

Normalized

CoordinatesMap Normalized-

Coordinates to

Device-Coordinates

Device

Coordinates

4

Page 5: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

2D Viewing pipeline

Clipping window:

What do we want to see?

xwmin xwmax

ywmax

ywmin

Viewport:

Where do we want to see it?

Clipping window

World:

xvmin xvmax

yvmax

yvmin

Viewport

Screen:

3/13/2020 5

Page 6: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

2D Viewing pipeline

Clipping window:

Panning…

ywmax

ywmin

xwmin xwmax

Clipping window

World:

xvmin xvmax

yvmax

yvmin

Viewport

Screen:

3/13/2020 6

Page 7: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

2D Viewing pipeline

Clipping window:

Panning…

ywmax

ywmin

xwmin xwmax

Clipping window

World:

xvmin xvmax

yvmax

yvmin

Viewport

Screen:

3/13/2020 7

Page 8: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

2D Viewing pipeline

Clipping window:

Zooming…

ywmax

ywmin

xwmin xwmax

World:

xvmin xvmax

yvmax

yvmin

Viewport

Screen:

3/13/2020 8

Page 9: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

2D Viewing pipeline

Clipping window:

Zooming…

ywmax

ywmin

xwmin xwmax

World:

xvmin xvmax

yvmax

yvmin

Viewport

Screen:

3/13/2020 9

Page 10: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

2D Viewing pipeline

MC: Modeling Coordinates

WC: World Coordinates

VC: Viewing Coordinates

NC: Normalized Coordinates

DC: Device Coordinates

Apply model transformations

Determine visible parts

To standard coordinates

Clip and determine pixels

3/13/2020 10

Page 11: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Window to Viewport

Transformation

• What is window?

3/13/2020 11

Page 12: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Window to Viewport

Transformation

• What is viewport?

3/13/2020 12

Page 13: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

3/13/2020 13

Page 14: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

3/13/2020 14

Page 15: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

3/13/2020 15

Page 16: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

3/13/2020 16

leave some 4 lines gap here

Page 17: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

3/13/2020 17

Page 18: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

3/13/2020 18

Page 19: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

3/13/2020 19

Page 20: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

3/13/2020 20

Similarly, do for Yv

Page 21: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

3/13/2020 21

Page 22: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

3/13/2020 22

Page 23: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

3/13/2020 23

Page 24: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

3/13/2020 24

Page 25: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

3/13/2020 25

Now, go back to that gap...

Page 26: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

3/13/2020 26

Apparently, in 5th lab program (cohen

Sutherland line clip)

Page 27: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Clipping window

xwmin xwmax

ywmax

ywmin

Clipping window

- Clipping window usually an axis-aligned rectangle- Sometimes rotation- From world to view coordinates:

possibly followed by rotation- More complex in 3D

xwmax xwmin

ywmax ywmin

minmin , ywxw T

3/13/2020 27

Page 28: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

To normalized coordinates

xvmax-xvmin

yvmax -yvmin

xwmax-xwmin

ywmax -ywmin

!distortion :changes ratio-aspect then the

unequal, are factors scale two theIf

,

: withScale

minmax

minmax

minmax

minmax

ywyw

yvyv

xwxw

xvxvS

3/13/2020 28

Page 29: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

To normalized coordinates

xvmax-xvmin

yvmax -yvmin

xvmin xvmax

yvmax

yvmin

Viewport

1

1

minmin ,

: withTranslate

yvxvT

3/13/2020 29

Page 30: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

To normalized coordinates

xwmin xwmax

ywmax

ywmin

Clipping window

xvmin xvmax

yvmax

yvmin

Viewport

1

1

),(,),(

: togetherAll

minminminmax

minmax

minmax

minmaxminmin ywxw

ywyw

yvyv

xwxw

xvxvyvxv

TST

3/13/2020 30

Page 31: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

OpenGL 2D Viewing

Specification of 2D Viewing in OpenGL:

- Standard pattern, follows terminology.

First, this is about projection. Hence, select and the

Projection Matrix (instead of the ModelView

matrix) with:

glMatrixMode(GL_PROJECTION);

3/13/2020 31

Page 32: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

OpenGL 2D Viewing

Next, specify the 2D clipping window:gluOrtho2D(xwmin, xwmax, ywmin, ywmax);

xwmin, xwmax: horizontal range, world coordinates

ywmin, ywmax: vertical range, world coordinates

xwmin xwmax

ywmin

ywmax

3/13/2020 32

Page 33: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

OpenGL 2D Viewing

Finally, specify the viewport:glViewport(xvmin, yvmin, vpWidth, vpHeight);

xvmin, yvmin: coordinates lower left corner (in pixel coordinates);

vpWidth, vpHeight: width and height (in pixel coordinates);

(xvmin, yvmin)

vpWidth

vpHeight

3/13/2020 33

Page 34: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

OpenGL 2D Viewing

In short:

glMatrixMode(GL_PROJECTION);

gluOrtho2D(xwmin, xwmax, ywmin, ywmax);

glViewport(xvmin, yvmin, vpWidth, vpHeight);

To prevent distortion, make sure that:

(ywmax – ywmin)/(xwmax – xwmin) = vpWidth/vpHeight

3/13/2020 34

Page 35: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

OpenGL 2D viewing functions

3/13/2020 35

• glMatrixMode(GL_PROJECTION);

• glLoadIdentity();

• glMatrixMode(GL_MODELVIEW);

• gluOrtho2D(xwmin, xwmax, ywmin, ywmax);

• glViewport(xvmin, yvmin, vpWidth, vpHeight);

• glGetIntegerv (GL_VIEWPORT, vpArray);

• glutInit(&argc,argv);

• glutInitWindowPosition(10,10);

• glutInitWindowSize(500,500);

• glutCreateWindow(“My First”);

• glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

• windowID = glutCreateWindow(“My First”);

• glutDestroyWindow(windowID);

Page 36: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

OpenGL 2D viewing functions

3/13/2020 36

• glutSetWindow(windowID);

• currentWindowID = glutGetWindow();

• glutReshapeWindow(width,height); //reset

• glutFullScreen();

• glutReshapeFunc(reshapeFunction);

• glitIconifyWindow();

• glutSetIconTitle(“Icon Name”);

• glutSetWindowTitle(“New Window Name”);

• glutSetWindow (windowID);

• glutPopWindow ( );

• glutSetWindow (windowID);

• glutPushWindow ( );

• glutHideWindow ( );

Page 37: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

• glutShowWindow ( );

• glutCreateSubWindow (windowID,

xBottomLeft, yBottomLeft,width, height);

• glutDisplayFunc (pictureDescrip);

• glutPostRedisplay ( );

• glutMainLoop ( );

3/13/2020 37

OpenGL 2D viewing functions

Page 38: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Module-2

2D Geometric Transformations

3/13/2020 1

Page 39: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

“Transformations are the operations applied togeometrical description of an object to change itsposition, orientation, or size are called geometrictransformations”.

2D Transformations

3/13/2020 2

Page 40: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Why Transformations ?

“Transformations are needed to manipulate

the initially created object and to display the

modified object without having to redraw it.”

3/13/2020 3

Page 41: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

• Translation

• Rotation

3/13/2020 4

Page 42: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

• Scaling

• Uniform Scaling

• Un-uniform Scaling

3/13/2020 5

Page 43: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

• Reflection

• Shear

3/13/2020 6

Page 44: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Translation• A translation moves all points

in an object along the same

straight-line path to new

positions.

• The path is represented by a

vector, called the translation or

shift vector.

• We can write the components:

p'x = px + tx

p'y = py + ty

• or in matrix form:

P' = P + T

tx

ty

x'

y'

x

y

tx

ty = +

P(2, 2)= 6

=4

P'(8,6)

3/13/2020 7

Page 45: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Rotation• A rotation repositions

all points in an objectalong a circular path inthe plane centered atthe pivot point.

• First, we’ll assume thepivot is at the origin.

P

P

3/13/2020 8

Page 46: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Rotation• Review Trigonometry

=> cos = x/r , sin = y/r

• x = r. cos , y = r.sin

P(x,y)

x

yr

x’

y’

P’(x’, y’)

r

=> cos (+ ) = x’/r

•x’ = r. cos (+ )

•x’ = r.coscos -r.sinsin

•x’ = x.cos – y.sin

=>sin (+ ) = y’/r

y’ = r. sin (+ )

•y’ = r.cossin + r.sincos

•y’ = x.sin + y.cos

Identity of Trigonometry

3/13/2020 9

Page 47: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Rotation• We can write the components:

p'x = px cos – py sin

p'y = px sin + py cos

• or in matrix form:

P' = R • P

• can be clockwise (-ve) or

counterclockwise (+ve as our

example).

• Rotation matrix

P(x,y)

x

yr

x’

y’

P’(x’, y’)

cossin

sincosR

3/13/2020 10

Page 48: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Scaling• Scaling changes the size of an

object and involves two scale

factors, Sx and Sy for the x-

and y- coordinates

respectively.

• Scales are about the origin.

• We can write the components:

p'x = sx • px

p'y = sy • py

or in matrix form:

P' = S • P

Scale matrix as:

y

x

s

sS

0

0

P

P’

3/13/2020 11

Page 49: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Scaling

• If the scale factors are in between 0and 1:----

• the points will be moved closerto the origin

• the object will be smaller.

P(2, 5)

P’

• Example :

•P(2, 5), Sx = 0.5, Sy = 0.5

3/13/2020 12

Page 50: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Scaling• If the scale factors are in between 0

and 1 the points will be movedcloser to the origin the objectwill be smaller.

P(2, 5)

P’

• Example :

•P(2, 5), Sx = 0.5, Sy = 0.5

•If the scale factors are larger than 1

the points will be moved away

from the origin the object will be

larger.

P’

• Example :

•P(2, 5), Sx = 2, Sy = 2

3/13/2020 13

Page 51: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Scaling

• If the scale factors are the same,

Sx = Sy uniform scaling

• Only change in size (as previous

example)

P(1, 2)

P’

•If Sx Sy differential scaling.

•Change in size and shape

•Example : square rectangle

•P(1, 3), Sx = 2, Sy = 5

3/13/2020 14

Page 52: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Matrix Representations &

Homogenous Coordinates

Combining above equations, we can say that

3/13/2020 15

Page 53: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

3/13/2020 16

Page 54: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Problem: Rotate the given Triangle by 90 degrees about the origin

3/13/2020 17

Page 55: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Problem: Prove that successive translations are additive

3/13/2020 18

Page 56: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Problem: Prove that successive scaling is multiplicative

3/13/2020 19

Page 57: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

General pivot point rotation

• Translate the object so that pivot-position is moved to thecoordinate origin

• Rotate the object about the coordinate origin

• Translate the object so that the pivot point is returned to itsoriginal position

(xr,yr)

(a)

Original

Position of

Object and

pivot point

(b)

Translation of

object so that

pivot point

(xr,yr) is at

origin

(c)

Rotation was

about origin

(d)

Translation of the

object so that the

pivot point is returned

to position (xr,yr)

3/13/2020 20

Page 58: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

General fixed point scaling• Translate object so that the fixed point coincides with the

coordinate origin

• Scale the object with respect to the coordinate origin

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

(xf,yf)

(a)

Original

Position of

Object and

Fixed point

(b)

Translation of

object so that

fixed point

(xf,yf)is at

origin

(c)

scaling was

about origin

(d)

Translation of the

object so that the

Fixed point is

returned to position

(xf,yf)3/13/2020 21

Page 59: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Composite Transformations(A) Translations

If two successive translation vectors (tx1,ty1) and (tx2,ty2) are applied to

a coordinate position P, the final transformed location P’ is calculated

as: -

P’=T(tx2,ty2) . {T(tx1,ty1) .P}

={T(tx2,ty2) . T(tx1,ty1)} .P

Where P and P’ are represented as homogeneous-coordinate column

vectors. We can verify this result by calculating the matrix product for

the two associative groupings. Also, the composite transformation

matrix for this sequence of transformations is: -

1 0 tx2

0 1 ty2

0 0 1

1 0 tx1

0 1 ty1

0 0 1

1 0 tx1+tx2

0 1 ty1+ty2

0 0 1

. =

Or, T(tx2,ty2) . T(tx1,ty1) = T(tx1+tx2, ty1+ty2)

Which demonstrate that two successive translations are additive.3/13/2020 22

Page 60: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

(B) Rotations

Two successive rotations applied to point P produce the transformed

position: -

P’= R(Ө2) . {R(Ө1 ) . P}

= {R(Ө2) . R(Ө1)} . P

By multiplication the two rotation matrices, we can verify that two

successive rotations are additive:

R(Ө2) . R(Ө1) = R (Ө1+ Ө2)

So that the final rotated coordinates can be calculated with the

composite rotation matrix as: -

P’ = R(Ө1+ Ө2) . P

3/13/2020 23

Page 61: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

(C) Scaling

Concatenating transformation matrices for two successive scaling

operations produces the following composite scaling matrix: -

Sx2 0 0

0 Sy2 0

0 0 1

. =

Sx1 0 0

0 Sy1 0

0 0 1

Sx1 . Sx2 0 0

0 Sy1 .Sy2 0

0 0 1

Or, S(Sx2, Sy2 ) . S(Sx1, Sy1) = S (Sx1 . Sx2, Sy1 .Sy2 )

The resulting matrix in this case indicates that successive scaling

operations are multiplicative.

3/13/2020 24

Page 62: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

2D Composition Problems

THEORY

3/13/2020 25

Page 63: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

problem Step 1

Step 2Step 3

PROBLEM 1

3/13/2020 26

Page 64: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

3/13/2020 27

Page 65: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

3/13/2020 28

Page 66: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

THEORY

3/13/2020 29

Page 67: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

PROBLEM 2

3/13/2020 30

Page 68: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Other transformations

• Reflection is a transformation that produces a mirror image of an object. It is obtained by rotating the object by 180 deg about the reflection axis

1

2 3

3’2’

1’

Original position

Reflected position

Reflection about the line y=0, the

X- axis , is accomplished with the

transformation matrix

1 0 0

0 -1 0

0 0 1

3/13/2020 31

Page 69: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Reflection

-1 0 0

0 1 0

0 0 1

1’

3’

2’

3

2

1

Original position Reflected position

Reflection about the line x=0, the

Y- axis , is accomplished with the

transformation matrix

3/13/2020 32

Page 70: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Reflection

-1 0 0

0 -1 0

0 0 1

1’

2’

3’

3

2

1

Original position

Reflected position

Reflection of an object relative to an axis perpendicular to

the xy plane and passing through the coordinate origin

X-axis

Y-axis

Origin

O (0,0)

The above reflection matrix is

the rotation matrix with

angle=180 degree.

This can be generalized to any

reflection point in the xy plane.

This reflection is the same as a

180 degree rotation in the xy

plane using the reflection point

as the pivot point.3/13/2020 33

Page 71: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Reflection of an object w.r.t the straight line y=x

0 1 0

1 0 0

0 0 1

1’

3’

2’

3

2 1

Original position

Reflected position

X-axis

Y-axis

Origin O

(0,0)

3/13/2020 34

Page 72: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Reflection of an object w.r.t the straight line y=-x

0 -1 0

-1 0 0

0 0 1

1’

3’

2’

3

X-axis

1Original position

Reflected position

2

Y-axis

Origin

O (0,0)

Line Y = - X

3/13/2020 35

Page 73: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Reflection of an arbitrary axis y=mx+b

3

2 1

Original position

3/13/2020 36

Page 74: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

3

2 1

Original position

3

2 1

Original position

Translation so that it passes through origin

1’

3’2’

32

1

Reflected position

Original position

Rotate so that it coincides with x-axis and reflect also about x-axis

1’

3’

2’

3

2 1

Original position

Reflected position 1’3’

2’

3

21

Original position

Reflected position

Rotate back Translate back

3/13/2020 37

Page 75: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Shear Transformations

• Shear is a transformation that distorts the shape ofan object such that the transformed shape appearsas if the object were composed of internal layers thathad been caused to slide over each other

• Two common shearing transformations are thosethat shift coordinate x values and those that shift yvalues

3/13/2020 38

Page 76: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Shears

Original Data y Shear x Shear

1 0 0 1 shx 0

shy 1 0 0 1 0

0 0 1 0 0 1

3/13/2020 39

Page 77: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

An X- direction Shear

(0,1) (1,1)

(1,0)(0,0) (0,0) (1,0)

(2,1) (3,1)

For example, Shx=2

3/13/2020 40

Page 78: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

An Y- direction Shear

(0,1) (1,1)

(1,0)(0,0) (0,0)

(0,1)

(1,3)

(1,2)

For example, Shy=2

X X

Y Y

3/13/2020 41

Page 79: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Scanned with CamScanner

Page 80: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Scanned with CamScanner

Page 81: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Scanned with CamScanner

Page 82: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Scanned with CamScanner

Page 83: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Scanned with CamScanner

Page 84: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Scanned with CamScanner

Page 85: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Scanned with CamScanner

Page 86: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Scanned with CamScanner

Page 87: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Scanned with CamScanner

Page 88: Window to Viewport Transformation › DOWNLOAD › CGV_MOD2_SHAN… · Window to Viewport Transformation 3/13/2020 1. Viewing •Transformation world screen •Clipping: Removing

Scanned with CamScanner