two dimensional viewing dr. s.m. malaek assistant: m. younesi

127
Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Upload: edgar-lawson

Post on 30-Dec-2015

222 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Two Dimensional Viewing

Dr. S.M. MalaekAssistant: M. Younesi

Page 2: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Two Dimensional Viewing

Basic Interactive Programming

Page 3: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Basic Interactive Programming

User controls contents, structure, and appearance of objects and their displayed images via rapid visual feedback.

Page 4: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Model

Model: a pattern, plan, representation, or description designed to show the structure or working of an object, system, or concept.

Page 5: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Modeling

Modeling is the process of creating, storing and manipulating a model of an object or a system.

Page 6: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Modeling In Modeling, we often use a geometric

model i.e.. A description of an object that provides a

numerical description of its shape, size and various other properties.

Dimensions of the object are usually given in units appropriate to the object:

meters for a ship kilometres for a country

Page 7: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Modeling The shape of the object is often

described in terms of sub-parts, such as circles, lines, polygons, or cubes.

Example: Model of a house units are in meters

6

9

6

y

x

Page 8: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

6

9

y

x

Instances of this object may then be placed in various positions in a scene, or world, scaled to different sizes, rotated, or deformed.

Each house is created with instances of the same model, but with different parameters.

Instances of Objects

Page 9: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

2D Viewing

Page 10: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

2D Viewing

Viewing is the process of drawing a view of a

model on a 2-dimensional display.

Page 11: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

2D Viewing The geometric description of the object

or scene provided by the model, is converted into a set of graphical primitives, which are displayed where desired on a 2D display.

The same abstract model may be viewed in many different ways:

e.g. faraway, near, looking down, looking up

Page 12: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Real World Coordinates It is logical to use dimensions which are

appropriate to the object e.g. meters for buildings nanometers or microns for molecules, cells, atoms light years for astronomy

The objects are described with respect to their actual physical size in the real world, and then mappedmapped onto screenscreen co-ordinates.

It is therefore possible to view an object at various sizes by zooming in and out, without actually having to change the model.

Page 13: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

2D Viewing How muchHow much of the model should be drawn? WhereWhere should it appear on the display?

HowHow do we convert Real-world coordinates into screen co-ordinates?

We could have a model of a whole room, full of objects such as chairs, tablets and students.

We may want to view the whole room in one go, or zoom in on one single object in the room.

We may want to display the object or scene on the full screen, or we may only want to display it on a portion of the screen.

Page 14: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

2D Viewing Once a model has been constructed, the

programmer can specify a view.

A 2-Dimensional view consists of twotwo rectangles:

A WindowWindow, given in real-world co-ordinates, which defines the portion of the model that is to be drawn

A ViewportViewport given in screen co-ordinates, which defines the portion of the screen on which the contents of the window will be displayed

Page 15: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Basic Interactive Programming WindowWindow: What is to be viewed

ViewportViewport: Where is to be displayed

Scene Image

Viewport

Page 16: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Coordinate Representations

Page 17: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Coordinate Representations General graphics packages

are designed to be used with Cartesian coordinate specifications.

Several different Cartesian reference frame are used to construct and display a scene.

Page 18: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Coordinate Representations Modeling coordinates: We can construct the

shape of individual objects in a scene within separate coordinate reference frames called modeling (local) coordinates.

Page 19: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Coordinate Representations World coordinates: Once individual object

shapes have been specified, we can place the objects into appropriate positions within the scene using reference frame called world coordinate.

Page 20: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Coordinate Representations Device Coordinates: Finally, the world

coordinates description of the scene is transferred to one or more output-device reference frames for display, called device (screen) coordinates.

Page 21: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Coordinate Representations Normalized Coordinates: A graphic system

first converts world coordinate positions to normalized device coordinates, in the range 0 to 1.This makes the system independent of the output-devices.

Page 22: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Coordinate Representations An initial modeling coordinate position is

transferred to a device coordinate position with the sequence:

The modeling and world coordinate positions in this transformation can be any floating values; normalized coordinates satisfy the inequalities:

The device coordinates are integers within the range (0,0) to for a particular output device.

),(),(),(),( dcdcncncwcwcmcmc yxyxyxyx

10 ncx 10 ncy

),(maxmax

yx

Page 23: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

The Viewing Pipeline

Page 24: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

The Viewing Pipeline A world coordinate area selected for display is

called window. An area on a display device to which a window

is mapped a viewport.

Windows and viewports are rectangular in standard position.

Page 25: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

The Viewing Pipeline The mapping of a part of a world coordinate

scene to device coordinate is referred to as viewing transformation or window-to-viewport transformation or windowing transformation.

Viewport

window-to-viewport transformation

Page 26: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

The Viewing Pipeline1. Construct the scene in world coordinate using the output

primitives.

2. Obtain a particular orientation for the window by set up a two

dimensional viewing coordinateviewing coordinate system in the world coordinate, and define a window in the viewing coordinate system. Transform descriptions in world coordinates to viewing

coordinates (clippingclipping).

Page 27: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

The Viewing Pipeline3. Define a viewport in normalized coordinate, and map the

viewing coordinate description of the scene to normalized coordinate

4. (All parts lie outside the viewport are clippedclipped), and contents of the viewport are transferred to device coordinates.

Viewing Coordinate Normalized Coordinate Device Coordinate

1

1

Page 28: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

The Viewing Pipeline

Page 29: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

The Viewing Pipeline By Changing the position of the viewport, we

can view objects at different position on the display area of an output device.

Page 30: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

The Viewing Pipeline By varying the size of viewport, we can change

the size of displayed objects (zooming).

Page 31: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

2D Geometric Transformations

Page 32: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

2D Geometric Transformations Operations that are applied to the

geometric description of an object to change its position, orientation or size.

Basic transformation:

Translation

Rotation

Scaling

Page 33: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

2D Translation 2D Translation: Move a point along a

straight-line path to its new location.

yx tyytxx ,

y

x

t

t

y

x

y

x

TPP

Page 34: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

2D Tranlation Rigid-body translation: moves objects

without deformation (every point of the object is translated by the same amount)

Note: House shifts position relative to origin

tx = 2ty = 3

Y

X 0

1

1

2

2

3 4 5 6 7 8 9 10

3

4

5

6

1

2

4

4

Page 35: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

2D Rotation 2D Rotation: Rotate the points a specified

rotation angle about the rotation axis.

Axis is perpendicular to xy plane; specify only rotation point (pivot point ) ),( rr yx

rx

ry

Page 36: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

2D Rotation Simplify: rotate around origin: 0,0

rryx

),( yx

)','( yx

r

r

θcosφsinθsinφcos)θφsin(

θsinφsinθcosφcos)θφcos(

rrry

rrrx

φsin,φcos ryrx

θcosθsin

θsinθcos

yxy

yxx

PRP

θcosθsin

θsinθcosR

Page 37: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

2D Rotation Rotation of a point about an arbitrary pivot position:

The matrix expression could be modified to include pivot coordinates by matrix addition of a column vector whose elements contain the additive (translational) term.

θcos)(θsin)(

θsin)(θcos)(

rrr

rrr

yyxxyy

yyxxxx

Page 38: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

2D Rotation Rigid-body translation: Rotates objects

without deformation (every point of the object is rotated through the same angle.

6

Y

X 0

1

1

2

2

3 4 5 6 7 8 9 10

3

4

5

6

Page 39: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

2D Scaling 2D Scaling: Alters the size of an object.

This operation can be carried out for polygons by multiplying the coordinate values of each vertex by scaling factors and to produce the transformed coordinates

),( yxx

s ys

x

y

x

y2xs1ys

Page 40: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

2D Scaling

x

y

x

y2xs1ys

yx syysxx ,

y

x

s

s

y

x

y

x

0

0

PSP

Page 41: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

2D Scaling An positive numeric values can be assigned to the scaling factors.

Values less than 1 reduce the size of objects, and greater than 1 produce an enlargement.

Uniform Scaling:Uniform Scaling: Differential Scaling:Differential Scaling: , used in modeling

applications.

yxss

yxss

original

Uniform scaling Differential scaling

yxss

yxss

Page 42: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

2D Scaling Scale an object moving its origin (upper right)

Page 43: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

2D Scaling We can control the location of a scaled object by

choosing a position, called fixes point Fixes point can be chosen as one of the

vertices, the object centroid, or any other position

),( ff yx

xff sxxxx )('

yff syyyy )('

)1('xfx sxsxx

)1('yfy sysyy

Page 44: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

2D Scaling

The matrix expression could be modified to include fixed coordinates.

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

2

6

2

9

2

3

y

x

s

s

)1('xfx sxsxx

)1('yfy sysyy

Page 45: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Matrix Representations

And

Homogeneous Coordinates

Page 46: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Matrix Representations In Modeling, we perform sequences of

geometric transformation: translation, rotation, and scaling to model components into their proper positions.

HowHow the matrix representations can be reformulated so that transformation

sequences can be efficiently processed??

Page 47: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Matrix Representations We have seen:

)1('xfx sxsxx

)1('yfy sysyy

θcos)(θsin)(

θsin)(θcos)(

rrr

rrr

yyxxyy

yyxxxx

The basic transformations can be expressed in the general matrix form:

21 MPMP

Rotation:

Scaling:

Page 48: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Matrix Representations

M1 is a 2×2 array containing multiplicative

factors. M2 is a two element column matrix containing

translation terms.

Translation: M1 is the identity matrix.

Rotation: M2 contains the translation terms associated with the pivot point.

Scaling: M2 contains the translation terms associated with the fixed point.

21 MPMP

Page 49: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Matrix Representations

To produce a sequence of transformations, we must calculate

the transformed coordinates one step at a time.

21 MPMP

We need to eliminate the matrix addition associated with the translation terms in M2.

Page 50: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Matrix Representations

We can combine the multiplicative and translation terms for 2D transformation

into a single matrix representation

byby expanding 2×2 matrix to 3×3 matrix.

Page 51: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Matrix Representationsand

Homogeneous Coordinate Homogeneous Coordinate: To express any 2D

transformation as a matrix multiplication, we represent each Cartesian coordinate position (x,y) with the homogeneous Coordinate triple (xh,yh,h):

h

yy

h

xx hh ,

Simply: h=1

Page 52: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Matrix Representationsand

Homogeneous Coordinate

(X,Y,h)

h

Page 53: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Matrix Representationsand

Homogeneous Coordinate

Expressing position in homogeneous Coordinates,

(x,y,1) allows us to represent all geometric transformation as

matrix multiplication

Page 54: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Matrix Representationsand

Homogeneous Coordinate Basic 2D transformations as 3x3 matrices:

1100

10

01

1

y

x

t

t

y

x

y

x

1100

00

00

1

y

x

s

s

y

x

y

x

1100

0cossin

0sincos

1

y

x

y

x

TranslationTranslation RotationRotation

ScalingScaling

Page 55: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Composite Transformation

Page 56: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Composite Transformation Combined transformations

By matrix multiplication

Efficiency with pre-multiplication)))((( pSRTp pSRTp )(

w

y

x

s

s

θθ

θ -θ

t

t

w

y

x

y

x

y

x

100

00

00

100

0cossin

0sincos

100

10

01

p )( yx t,tT )(R )( yx s,sS p

Page 57: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

General Pivot Point Rotation

Page 58: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

General 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

yxyxyx RTRT

Translation Rotation Translation

(xr,yr) (xr,yr) (xr,yr)(xr,yr)

Page 59: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

General Fixed Point Scaling

Page 60: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

General Fixed Point Scaling

100

)1(0

)1(0

100

10

01

100

00

00

100

10

01

yry

xrx

r

rx

r

r

sys

sxs

y

x

s

s

y

x

y

yxrrrryxrr

ssyxyxssyx ,,,,,,

STST

Translation Scaling Translation

(xr,yr) (xr,yr) (xr,yr)(xr,yr)

Page 61: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

General Scaling Direction

Page 62: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

General Scaling Direction

100

0θcosθsinθsinθcos)(

0θsinθcos)(θsinθcos

)θ(),()θ( 22

2112

122

22

1

211 ssss

ssss

ss RSR

Page 63: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Reflection

Page 64: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Reflection Reflection: Produces a mirror image of an

object.

100

010

001

100

010

001

100

010

001

x

y 1

32

1’

3’2’

1

32

1’

3’ 2’

x

y

3

1’

3’ 2’

1

2

x

y

X AxisX Axis Y AxisY Axis OriginOrigin

X AxisX Axis Y AxisY Axis OriginOrigin

Page 65: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Reflection

100

001

010 y=x

x

y

x

y

x

y 1

32

1’

3’2’ x

y

Reflection with respect to a line y=x

We can drive this matrix by : Clockwise : Clockwise rotation of 45º Reflection about the x axis CounterclockwiseCounterclockwise rotation of 45º

Page 66: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Reflection Reflection with respect to a line y=-x

y= -x

x

y

100

001

010

Reflection with respect to a line y=mx+b:

1. Translate the line so that it passes through the origin.

2. Rotate the onto one of the coordinate axes

3. Reflect about that axis

4. Inverse rotation

5. Inverse translation

Page 67: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Shear

Page 68: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Shear Shear: A transformation that distorts the

shape of an object such that transformed shape appears as if the object were composed of internal layers that had been caused to slide over each other is called a shear.

Page 69: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Shear x-direction: yyyhxx x ' ,'

(0,0) (1,0)

(1,1)(0,1) hx= 2

x

y(3,1)

(0,0) (1,0)

(2,1)

x

y

(0,0) (1,0)

(1,1)(0,1)

(0,0)

(0,1)

(1,3)

(1,2)hy= 2

x

y

x

y

100

010

01 xh

100

01

001

yh

y-direction: xhyyxx y ' ,'

Page 70: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Shear x-direction shears relative to a reference line

yyyyhxx refx ' ,'

y-direction shears relative to a reference line

(0,0) (1,0)

(1,1)(0,1)

hx= 0.5yref= -1

x

y

yref= –1 yref= –1(0.5,0) (1.5,0)

(2,1)(1,1)

x

y

refyy

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

hy= 0.5xref= -1

x

y

(0,0.5)(1,1)

(1,2)

(0,1.5)

x

y

xref= –1xref= –1

100

010

1 refxx yhh

refxx refy xxhyyxx ' ,'

100

1

001

refyy xhh

Page 71: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Transformations Between

Coordinates Systems

Page 72: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Transformations Between Coordinates Systems

It is often requires the transformation of object description from one coordinate system to another.

How do we transform between two How do we transform between two Cartesian coordinate systems?Cartesian coordinate systems?

Page 73: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Transformations Between Coordinates Systems

Rule: Transform one coordinate frames towards the other in the opposite direction of the representation change.

Page 74: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Transformations Between Coordinates Systems

Two Steps:

1. Translate so that the origin (x0,y0) of the x´y´ system is moved to the origin of the xy system.

2. Rotate the x´ axis onto the x axis.

Page 75: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Transformations Between Coordinates Systems

100

10

01

),( 0

0

00 y

x

yxT

100

0θcosθsin

0θsinθcos

)θ(R

),()θ( 00 yxyxxy TRM

Page 76: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Transformations Between Coordinates Systems

Alternative Method: Assume x´=(ux,,uy) and y´=(vx,vy) in the (x,y) coordinate

systems:

100

10

01

100

0

0

0

0

y

x

vv

uu

Myx

yx

PP M

TRM

Page 77: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Transformations Between Coordinates Systems

Example: If V=(-1,0) then the xx´́ axis is in the positivepositive

direction yy and the rotation transformation matrix is:

100

001

010

R

Page 78: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Transformations Between Coordinates Systems

In an interactive application, it may be more convenient to choose the direction for V relative

to position P0 than it is to specify it relative to

the xy coordinate origin.

01

01

- PP

PPv

Page 79: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Viewing Coordinate Reference Frame

Page 80: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Viewing Coordinate Reference Frame

This coordinate system provides the reference frame for specifying the world coordinate window.

Page 81: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Viewing Coordinate Reference FrameSet up the viewing coordinate:1. Origin is selected at some world position:

2. Established the orientation. Specify a world vector V that defines the viewing y direction.

3. Obtain the matrix for converting world to viewing coordinates (Translate and rotate)

),( 000 yxP

TRM VCWC ,

Page 82: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Window to Viewport Coordinate

Transformation

Page 83: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Window to Viewport Coordinate Transformation

Select the viewport in normalized coordinate, and then object description transferred to normalized device coordinate.

To maintain the same relative placement in the viewport as in the window:

minmax

min

minmax

min

minmax

min

minmax

min

ywyw

ywyw

yvyv

yvyv

xwxw

xwxw

xvxv

xvxv

Page 84: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Window to Viewport Coordinate Transformation

1. Perform a scaling transformation that scales the window area to the size of the viewport.

2. Translate the scaled window area to the position of the vieport.

minmax

min

minmax

min

minmax

min

minmax

min

ywyw

ywyw

yvyv

yvyv

xwxw

xwxw

xvxv

xvxv

y

x

sywywyvyv

sxwxwxvxv

)(

)(

minmin

minmin

minmax

minmax

minmax

minmax

ywyw

yvyvs

xwxw

xvxvs

y

x

Page 85: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Clipping

Page 86: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Clipping

Page 87: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Clipping Clipping Algorithm or Clipping: Any

procedure that identifies those portion of a picture that are either inside or outside of a specified region of space.

The region against which an object is to clipped is called a clip windowclip window.

Page 88: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Point Clipping

Page 89: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Point Clipping

(x, y)

wx2wx1wy1

wy2maxmin

maxmin

ywyyw

xwxxw

Page 90: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Line Clipping

Page 91: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Line Clipping Possible relationship between line position

and a standard clipping region.

Before Clipping After Clipping

Page 92: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Line Clipping A line clipping procedure involves

several parts:1. Determine whether line lies completely

inside the clipping window.

2. Determine whether line lies completely outside the clipping window.

3. Perform intersection calculation with one or more clipping boundaries.

Page 93: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Line Clipping A line with both endpoints inside all

clipping boundaries is saved ( )

Before Clipping After Clipping

43PP

Page 94: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Line Clipping A line with both endpoints outside all

clipping boundaries is reject ( & )

Before Clipping After Clipping

21PP

109PP

Page 95: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

If one or both endpoints outside the clipping rectangular, the parametric representation could be used to determine values of parameter u for intersection with the clipping boundary coordinates.

Before Clipping After Clipping

)(

10

)(

121

121

yyuyy

u

xxuxx

Page 96: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Line Clipping1. If the value of u is outside the range 0 to 1: The

line dose not enter the interior of the window at that boundary.

2. If the value of u is within the range 0 to 1, the line segment does cross into the clipping area.

Clipping line segments with these parametric tests requires a good deal of computation, and faster approaches to clipper are possible.

Page 97: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Cohen Sutherland Line Clipping

Page 98: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Cohen Sutherland Line Clipping

The method speeds up the processing of line segments by performing initial tests that reduce the number of intersections that must be calculated.

Page 99: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Cohen Sutherland Line Clipping Every line endpoint is assigned a four digit

binary code, called region coderegion code, that identifies the location of the point relative to the boundaries of the clipping rectangle.

Page 100: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Each bit position in the region code is used to indicate one of the four relative coordinate positions of the point with respect to the clip window. Bit 1: Left

Bit 2: Right

Bit 3: Below

Bit 4: Above

Page 101: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Bit values in the region code are determined by comparing endpoint coordinates values (x,y) to the clip boundaries. Bit 1 is set to 1 if Bit 1:

Bit 2:

Bit 3:

Bit 4:

)(min

xxwsign

)( maxxwxsign

)( min yywsign

)( maxywysign

minxwx

Page 102: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Once we have established region codes for all line endpoints, we can quickly determine lines are completely outside or inside the clip window.

Page 103: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Once we have established region codes for all line endpoints, we can quickly determine lines are completely outside or inside the clip window.

Page 104: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Lines that cannot be identified as completely inside or outside a clip window are checked for intersection with boundaries.

Page 105: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Lines that cannot be identified as completely inside or outside a clip window are checked for intersection with boundaries.

Page 106: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Lines that cannot be identified as completely inside or outside a clip window are checked for intersection with boundaries.

Page 107: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Lines that cannot be identified as completely inside or outside a clip window are checked for intersection with boundaries.

Page 108: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Lines that cannot be identified as completely inside or outside a clip window are checked for intersection with boundaries.

Page 109: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Lines that cannot be identified as completely inside or outside a clip window are checked for intersection with boundaries.

Page 110: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Lines that cannot be identified as completely inside or outside a clip window are checked for intersection with boundaries.

Page 111: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Lines that cannot be identified as completely inside or outside a clip window are checked for intersection with boundaries.

Page 112: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Lines that cannot be identified as completely inside or outside a clip window are checked for intersection with boundaries.

Page 113: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Lines that cannot be identified as completely inside or outside a clip window are checked for intersection with boundaries.

Page 114: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Lines that cannot be identified as completely inside or outside a clip window are checked for intersection with boundaries.

Page 115: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Lines that cannot be identified as completely inside or outside a clip window are checked for intersection with boundaries.

Page 116: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Lines that cannot be identified as completely inside or outside a clip window are checked for intersection with boundaries.

Page 117: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Lines that cannot be identified as completely inside or outside a clip window are checked for intersection with boundaries.

Page 118: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Lines that cannot be identified as completely inside or outside a clip window are checked for intersection with boundaries.

Page 119: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Intersection points with a clipping boundary can be calculated using the slope-intercept form of the line equation.

)()( 1212 xxyym

Cohen Sutherland Line Clipping

)( 11 xxmyy max

min

xwx

xwx

m

yyxx 1

1

max

min

ywy

ywy

Page 120: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Liang barsky Clipping

Page 121: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Liang barsky Clipping: Faster line clippers, that are based on analysis of the parametric of a line segment:

Liang barsky Clipping

yuyy

u

xuxx

Δ

10

Δ

1

1

12Δ xxx

12Δ yyy

Page 122: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

When we traverse along the extended line with u increasing from to ,

we first move from the outside to the inside of the clipping window’s two boundary lines (bottom and left)

Then move from the inside to the outside of the other two boundary lines (top and right)

Liang barsky Clipping

Page 123: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

ul: intersection the window’s left

ub: intersection the window’s bottom

ul: intersection the window’s right

ur: intersection the window’s top

Liang barsky Clipping21 uu ),,0( 11 buuMaxu ),,1(2 rt uuMinu

Page 124: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

Point (x,y) inside the clipping window

Liang barsky Clipping

max1min

max1min

Δ

Δ

ywyuyyw

xwxuxxw

4,3,2,1, kqupkk

)(

)(

)(

)(

1max4

min13

1max2

min11

4

3

2

1

top

bottom

right

left

yywq

yyq

xxwq

xxq

yp

yp

xp

xp

Rewrite the four inequalities as:

Page 125: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

If , the line is parallel to the boundary:

if the line is completely outside (can be eliminated)

if the line is completely inside (need further consideration) If the extended line proceeds from the outside to the inside. If the extended line proceeds from the inside to the outside. When , u corresponding to the intersection point is

)(

)(

)(

)(

1max4

min13

1max2

min11

4

3

2

1

top

bottom

right

left

yywq

yyq

xxwq

xxq

yp

yp

xp

xp

0kp

0kq

0kq

0kp

0kp

kkpq0

kp

Page 126: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

A four step process for finding the visible portion of the line:

1. If and for any k, eliminate the line and stop, Otherwise proceed to the next step.

2. For all k such that , calculate . Let be the maximum of the set containing 0 and the calculated

r r values.

Liang barsky Clipping

)(

)(

)(

)(

1max4

min13

1max2

min11

4

3

2

1

top

bottom

right

left

yywq

yyq

xxwq

xxq

yp

yp

xp

xp

0kp 0kq

0kpkkk pqr 1u

Page 127: Two Dimensional Viewing Dr. S.M. Malaek Assistant: M. Younesi

A four step process … 3. For all k such that , calculate . Let be

the minimum of the set containing 1 and the calculated

rr values.

4. If , eliminate the line since it is completely outside the clipping window, Otherwise, use and to calculate the endpoints of the clipped line.

Liang barsky Clipping

)(

)(

)(

)(

1max4

min13

1max2

min11

4

3

2

1

top

bottom

right

left

yywq

yyq

xxwq

xxq

yp

yp

xp

xp

0kp kkk pqr 2u

21 uu 1u 2u