Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
16 views101 pages

Viewing Part 1

The document discusses the concepts of windows and viewports in computer graphics, defining a window as a selected area from the real world for display and a viewport as the corresponding area on a display device. It explains the window-to-viewport transformation, which involves scaling and translating the window area to fit the viewport, and outlines the clipping operation that determines which parts of a picture are displayed within a specified region. Various clipping algorithms for different primitive types, such as point, line, and area clipping, are also introduced.

Uploaded by

reeknaskar33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views101 pages

Viewing Part 1

The document discusses the concepts of windows and viewports in computer graphics, defining a window as a selected area from the real world for display and a viewport as the corresponding area on a display device. It explains the window-to-viewport transformation, which involves scaling and translating the window area to fit the viewport, and outlines the clipping operation that determines which parts of a picture are displayed within a specified region. Various clipping algorithms for different primitive types, such as point, line, and area clipping, are also introduced.

Uploaded by

reeknaskar33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 101

COMPUTER GRAPHICS

SIDDHARTHA BANERJEE

RAMAKRISHNA MISSION RESIDENTIAL


COLLEGE (AUTONOMOUS), NARENDRAPUR
VIEWING
1. INTRODIUCTION

Capturing images from the real world and displaying them


on the screen is an surprising process, only if we do not know
the underlying process.

A world-coordinate area selected for display is called a


window.

An area on a display device to which a window is mapped is


called a viewport.

The window defines what is to be viewed; the viewport


defines where it is to be displayed.
VIEWING
1. INTRODIUCTION

The window port is the area chosen from the real world for
display.

This window port decides what portion of the real world


should be captured and be displayed on the screen.

The widow port can thus be defined as, "A world-coordinate


area selected for display is called a window. A window
defines a rectangular area in the world coordinates."
VIEWING
1. INTRODIUCTION
VIEWING
1. INTRODIUCTION
VIEWING
1. INTRODIUCTION

Now, the Viewport is the area on a display device to which a


window is mapped.

Thus, the viewport is nothing else but our device’s screen.

 The viewport can thus be defined as follows: "A viewport is


a polygon viewing region in computer graphics. The
viewport is an area expressed in rendering-device-specific
coordinates, e.g. pixels for screen coordinates, in which the
objects of interest are going to be rendered.”
VIEWING
1. INTRODIUCTION
VIEWING
1. INTRODIUCTION

 Windows and viewports are rectangles in standard position,


with the rectangle edges parallel to the coordinate axes.

In general, the mapping of a part of a world-coordinate


scene to device coordinates is referred to as a viewing
transformation.

Sometimes the two-dimensional viewing transformation is


simply referred to as the window-to-viewport transformation
or the windowing transformation.
VIEWING
1. INTRODIUCTION
VIEWING
1. INTRODIUCTION
VIEWING
2. WINDOW-TO-VIEWPORT TRANSFORMATION

 It may be possible that the size of the Viewport is much


smaller or greater than the Window.

 In these cases, we have to increase or decrease the size of


the Window according to the Viewport and for this, we
need some mathematical calculations.
VIEWING
2. WINDOW-TO-VIEWPORT TRANSFORMATION

Ywmax Yvmax

(Xv, Yv)
(Xw, Yw)
Ywmin Yvmin

Xwmin Xwmax Xvmin Xvmax


VIEWING
2. WINDOW-TO-VIEWPORT TRANSFORMATION

Ywmax Yvmax

(Xv, Yv)
(Xw, Yw)
Ywmin Yvmin

Xwmin Xwmax Xvmin Xvmax

Normalized Device Coordinate System :

The standardized coordinate system for all devices.


Ranges from (0.0 − 1.0) in each dimension.
VIEWING
2. WINDOW-TO-VIEWPORT TRANSFORMATION

Ywmax Yvmax

(Xv, Yv)
(Xw, Yw)
Ywmin Yvmin

Xwmin Xwmax Xvmin Xvmax


VIEWING
2. WINDOW-TO-VIEWPORT TRANSFORMATION

Ywmax Yvmax

(Xv, Yv)
(Xw, Yw)
Ywmin Yvmin

Xwmin Xwmax Xvmin Xvmax


VIEWING
2. WINDOW-TO-VIEWPORT TRANSFORMATION

Ywmax Yvmax

(Xv, Yv)
(Xw, Yw)
Ywmin Yvmin

Xwmin Xwmax Xvmin Xvmax

Now the relative position of the object in Window and Viewport are
same.
VIEWING
2. WINDOW-TO-VIEWPORT TRANSFORMATION

Ywmax Yvmax

(Xv, Yv)
(Xw, Yw)
Ywmin Yvmin

Xwmin Xwmax Xvmin Xvmax

where sx , sy are the scaling factor of x coordinate and y coordinate


VIEWING
2. WINDOW-TO-VIEWPORT TRANSFORMATION

Ywmax Yvmax

(Xv, Yv)
(Xw, Yw)
Ywmin Yvmin

Xwmin Xwmax Xvmin Xvmax

where sx , sy are the scaling factor of x coordinate and y coordinate


VIEWING
2. WINDOW-TO-VIEWPORT TRANSFORMATION

For window, Xwmin = 20, Xwmax = 80, Ywmin = 40, Ywmax = 80.
For viewport, Xvmin = 30, Xvmax = 60, Yvmin = 40, Yvmax = 60.
Now a point ( Xw, Yw ) be ( 30, 80 ) on the window.
We have to calculate that point on the viewport i.e ( Xv, Yv ).
VIEWING
2. WINDOW-TO-VIEWPORT TRANSFORMATION

For window, Xwmin = 20, Xwmax = 80, Ywmin = 40, Ywmax = 80.
For viewport, Xvmin = 30, Xvmax = 60, Yvmin = 40, Yvmax = 60.
VIEWING
2. WINDOW-TO-VIEWPORT TRANSFORMATION

For window, Xwmin = 20, Xwmax = 80, Ywmin = 40, Ywmax = 80.
For viewport, Xvmin = 30, Xvmax = 60, Yvmin = 40, Yvmax = 60.
VIEWING
2. WINDOW-TO-VIEWPORT TRANSFORMATION

This can also be derived with a set of transformations that


converts the window area into the viewport area.

1. Perform a scaling transformation using a fixed-point


position of (Xwmin, Ywmin) that scales the window area to
the size of the viewport.
2. Translate the scaled window area to the position of the
viewport.
VIEWING
3. CLIPPING OPERATION

Generally, any procedure that identifies those portions of a


picture that are either inside or outside of a specified region of
space is referred to as a clipping algorithm, or simply clipping.

The region against which an object is to clipped is called a


clip window.
VIEWING
3. CLIPPING OPERATION

For the viewing transformation, we want to display only


those picture parts that are within the window area.

 Everything outside the window is discarded.

Clipping algorithms can be applied in world coordinates, so


that only the contents of the window interior are mapped to
device coordinates.
VIEWING
3. CLIPPING OPERATION

Alternatively, the complete world-coordinate picture can be


mapped first to device coordinates, or normalized device
coordinates, then clipped against the viewport boundaries.

 World-coordinate clipping removes those primitives outside


the window from further consideration, thus eliminating the
processing necessary to transform those primitives to device
space.
VIEWING
3. CLIPPING OPERATION

There are several algorithms for clipping the following


primitive types

 Point Clipping
 Line Clipping (straight-line segments)
 Area Clipping (polygons)
 Curve Clipping
 Text Clipping
VIEWING
3. CLIPPING OPERATION
3.1 POINT CLIPPING

Assuming that the clip window is a rectangle in standard


position, we have a point P = (Px, Py) for display if the
following inequalities are satisfied:

where the edges of the clip window (Xwmin, Xwmax,


Ywmin, Ywmax) can be either the world-coordinate window
boundaries or viewport boundaries.
VIEWING
3. CLIPPING OPERATION
3.1 POINT CLIPPING

If any one of these four inequalities is not satisfied, the point
is clipped (not saved for display).

Although point clipping is applied less often than line or


polygon clipping, some applications may require a point
clipping procedure.

For example, point clipping can be applied to scenes


involving explosions that are modeled with particles (points)
distributed in some region of the scene.
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING
A line clipping procedure
involves several parts.

First, we can test a given


line segment to determine
whether it lies completely
inside the clipping
window.
If it does not, we try to
determine whether it lies
completely outside the
window.
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING
A line clipping procedure
involves several parts.

Finally, if we cannot
identify a line as
completely inside or
completely outside, we
must perform intersection
calculations with one or
more clipping boundaries.
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING
We process lines
through the "inside-
outside'' tests by checking
the line endpoints.

A line with both


endpoints inside all
clipping boundaries, such
as the line from P1 to P2 is
saved.
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING
We process lines
through the "inside-
outside'' tests by checking
the line endpoints.

A line with both


endpoints outside any one
of the clip boundaries (line
P3P4) is outside the
window.
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING
We process lines
through the "inside-
outside'' tests by checking
the line endpoints.

All other lines cross one


or more clipping
boundaries, and may
require calculation of
multiple intersection
points.
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING
We process lines
through the "inside-
outside'' tests by checking
the line endpoints.

To minimize calculations,
we try to devise clipping
algorithms that can
efficiently identify outside
lines and reduce
intersection calculations.
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
This is one of the oldest
and most popular line-
clipping procedures.

Generally, the method


speeds up the processing
of line segments by
performing initial tests that
reduce the number of
intersections that must he
calculated.
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Every line end point in a
picture is assigned a four-
digit binary code, called a
region code, that identifies
the location of the point
relative to the boundaries
of the clipping rectangle.
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Every line end point in a
picture is assigned a four-
digit binary code, called a
region code, that identifies
the location of the point
relative to the boundaries
of the clipping rectangle.
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Every line end point in a
picture is assigned a four-
digit binary code, called a
region code, that identifies
the location of the point
relative to the boundaries
of the clipping rectangle.
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Bit 1 is set to 1
if x < Xwmin
Bit 2 is set to 1 Ywmin
if x > Xwmax
Bit 3 is set to 1
if y < Ywmin Xwmax
Bit 4 is set to 1
Xwmin
if y > Ywmax
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Bit 1 is set to 1
if x < Xwmin
Bit 2 is set to 1 Ywmin
if x > Xwmax
Bit 3 is set to 1
if y < Ywmin Xwmax
Bit 4 is set to 1
Xwmin
if y > Ywmax
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Bit 1 is set to 1
if x < Xwmin
Bit 2 is set to 1 Ywmin
if x > Xwmax 0000
Bit 3 is set to 1
if y < Ywmin Xwmax
Bit 4 is set to 1
Xwmin
if y > Ywmax
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Bit 1 is set to 1
if x < Xwmin
Bit 2 is set to 1 Ywmin
if x > Xwmax 0000
Bit 3 is set to 1
if y < Ywmin Xwmax
Bit 4 is set to 1
Xwmin
if y > Ywmax
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Bit 1 is set to 1
if x < Xwmin
Bit 2 is set to 1 Ywmin
if x > Xwmax 0000
Bit 3 is set to 1
if y < Ywmin Xwmax
Bit 4 is set to 1
Xwmin
if y > Ywmax
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Bit 1 is set to 1
if x < Xwmin
Bit 2 is set to 1 Ywmin
if x > Xwmax 0000
Bit 3 is set to 1
if y < Ywmin Xwmax
Bit 4 is set to 1
Xwmin
if y > Ywmax
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Bit 1 is set to 1
if x < Xwmin
Bit 2 is set to 1 Ywmin
0000
if x > Xwmax
Bit 3 is set to 1
if y < Ywmin Xwmax
Bit 4 is set to 1
Xwmin
if y > Ywmax
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Bit 1 is set to 1 1001
if x < Xwmin
Bit 2 is set to 1 Ywmin
0000
if x > Xwmax
Bit 3 is set to 1
if y < Ywmin Xwmax
Bit 4 is set to 1
Xwmin
if y > Ywmax
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Bit 1 is set to 1 1001
if x < Xwmin
Bit 2 is set to 1 Ywmin
0000
if x > Xwmax
Bit 3 is set to 1
if y < Ywmin Xwmax
Bit 4 is set to 1
Xwmin
if y > Ywmax
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Bit 1 is set to 1 1001
if x < Xwmin
Bit 2 is set to 1 Ywmin
0000
if x > Xwmax
Bit 3 is set to 1
if y < Ywmin Xwmax
Bit 4 is set to 1
Xwmin
if y > Ywmax
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Bit 1 is set to 1 1001
if x < Xwmin
Bit 2 is set to 1 Ywmin
0000
if x > Xwmax
Bit 3 is set to 1
if y < Ywmin Xwmax
Bit 4 is set to 1
Xwmin
if y > Ywmax
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Bit 1 is set to 1 1001 1000 1010
if x < Xwmin
Bit 2 is set to 1 Ywmin
0000
if x > Xwmax 0001 0010
Bit 3 is set to 1
if y < Ywmin Xwmax
0101 0100
Bit 4 is set to 1 0110
Xwmin
if y > Ywmax
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
First calculate region 1001 1000 1010
codes for all line
endpoints. Ywmin
0000
0001 0010
After this we can
quickly determine which Xwmax
0101 0100
lines are completely inside 0110
Xwmin
the clip window and which
are clearly outside.
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Step 1: Any lines that are 1001 1000 1010
completely contained
within the window Ywmin
0000
boundaries have a region 0001 0010
code of 0000 for both
endpoints, and we trivially Xwmax
0101 0100
accept these lines. 0110
Xwmin
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Step 1: Any lines that are 1001 1000 1010
completely contained
within the window Ywmin
0000
boundaries have a region 0001 0010
code of 0000 for both L1
endpoints, and we trivially Xwmax
0101 0100
accept these lines. 0110
Xwmin

If OR operation of two
end points code is 0000
then line is completely
inside
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Step 2: Any lines that 1001 1000 1010
have a 1 in the same bit
position in the region Ywmin
0000
codes for each endpoint 0001 0010
are completely outside the L1
clipping rectangle, and we Xwmax
0101 0100
trivially reject these lines. 0110
Xwmin
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Step 2: Any lines that 1001 1000 1010
have a 1 in the same bit
position in the region Ywmin L2
0000
codes for each endpoint 0001 0010
are completely outside the
clipping rectangle, and we Xwmax
0101 0100
trivially reject these lines. 0110
Xwmin L3
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Step 2: Any lines that 1001 1000 1010
have a 1 in the same bit
position in the region Ywmin L2
0000
codes for each endpoint 0001 0010
are completely outside the
clipping rectangle, and we Xwmax
0101 0100
trivially reject these lines. 0110
Xwmin L3
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Step 2: Any lines that 1001 1000 1010
have a 1 in the same bit
position in the region Ywmin L2
0000
codes for each endpoint 0001 0010
are completely outside the
clipping rectangle, and we Xwmax
0101 0100
trivially reject these lines. 0110
Xwmin L3

If AND operation of two


end points code is not
0000 then line is
completely outside
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Step 2: Any lines that 1001 1000 L4 1010
have a 1 in the same bit
position in the region Ywmin
0000
codes for each endpoint 0001 0010
are completely outside the
clipping rectangle, and we Xwmax
0101 0100
trivially reject these lines. L5 0110
Xwmin

If AND operation of two


end points code is not
0000 then line is
completely outside
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Step 2: Any lines that 1001 1000 L4 1010
have a 1 in the same bit
position in the region Ywmin L6 0000
codes for each endpoint 0001 0010
are completely outside the
clipping rectangle, and we Xwmax
0101 0100
trivially reject these lines. L7 L5 0110
Xwmin

If AND operation of two


end points code is not
0000 then line is
completely outside
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Step 3: Lines that cannot 1001 1000 L4 1010
be identified as completely
inside or completely Ywmin L6 0000
outside a clip window by 0001 0010
these tests are checked for
intersection with the Xwmax
0101 0100
window boundaries. L7 L5 0110
Xwmin
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Step 3: Lines that cannot
Ywmax
be identified as completely
inside or completely
outside a clip window by
these tests are checked for
intersection with the
window boundaries. Xwmax
Xwmin

Ywmin
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Step 3:
Ywmax

We begin the clipping


process for a line by
comparing an outside
endpoint to a clipping
boundary to determine Xwmax
Xwmin
how much of the line can
be discarded.
Ywmin
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Step 3:
Ywmax

Then the remaining part of


the Line is checked against
the other boundaries, and
we continue until either
the line is totally discarded Xwmax
Xwmin
or a section is found inside
the window.
Ywmin
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Step 3:
Ywmax

We set up our algorithm


to check line endpoints
against clipping
boundaries in the order
left, right, bottom, top. Xwmax
Xwmin

Ywmin
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1 to P2 1001
Code of P1: 0100
Code of P2: 1001

Xwmax
Xwmin

Ywmin

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1 to P2 1001
Code of P1: 0100
Code of P2: 1001
Chose any one outside
point
P1: 0100 Xwmax
Xwmin

Ywmin

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1 to P2 1001
Code of P1: 0100
Code of P2: 1001
Chose any one outside
point
P1: 0100 Xwmax
Xwmin

Ywmin

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1 to P2 1001
Code of P1: 0100
Code of P2: 1001
Chose any one outside
point
P1: 0100 Xwmax
Xwmin

Ywmin

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1 to P2 1001
Code of P1: 0100
Code of P2: 1001
Chose any one outside
point
P1: 0100 intersect with Xwmax
Xwmin
Ywmin

Ywmin

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1 to P2 1001
Code of P1: 0100
Code of P2: 1001
Chose any one outside
point
P1: 0100 intersect with Xwmax
Xwmin
Ywmin (Find P1ʹ)

Ywmin

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1 to P2 1001
Code of P1: 0100
Code of P2: 1001
Chose any one outside
point
P1: 0100 intersect with Xwmax
Xwmin
Ywmin (Find P1ʹ)
P1ʹ = (X, Ywmin)
Ywmin
(X,Ywmin)

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1 to P2 1001
P1ʹ = (X, Ywmin)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin

Ywmin
(X,Ywmin)

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1 to P2 1001
P1ʹ = (X, Ywmin)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin
(X – x1) = (Y – y1)/m

Ywmin (X,Ywmin)

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1 to P2 1001
P1ʹ = (X, Ywmin)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin
(X – x1) = (Y – y1)/m
X = x1+ (Y – y1)/m
Ywmin (X,Ywmin)

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1 to P2 1001
P1ʹ = (X, Ywmin)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin
(X – x1) = (Y – y1)/m
X = x1+ (Y – y1)/m
P1ʹ is on line Ywmin (X,Ywmin)
X = x1+ (Ywmin – y1)/m
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1 to P2 1001
P1ʹ = (X, Ywmin)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin
(X – x1) = (Y – y1)/m
X = x1+ (Y – y1)/m
P1ʹ is on line Ywmin
X = x1+ (Ywmin – y1)/m
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1ʹ to P2 1001

Xwmax
Xwmin

Ywmin

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1ʹ to P2 1001
Code of P1ʹ: 0000
Code of P2: 1001

Xwmax
Xwmin

Ywmin
0000

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1ʹ to P2 1001
Code of P1ʹ: 0000
Code of P2: 1001
Chose any one outside
point
P2: 1001 Xwmax
Xwmin

Ywmin
0000

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1ʹ to P2 1001
Code of P1ʹ: 0000
Code of P2: 1001
Chose any one outside
point
P2: 1001 Xwmax
Xwmin

Ywmin
0000

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1ʹ to P2 1001
Code of P1ʹ: 0000
Code of P2: 1001
Chose any one outside
point
P2: 1001 intersect with Xwmax
Xwmin
Xwmin (Find P2ʹ)

Ywmin
0000

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1ʹ to P2 1001 (Xwmin,Y)
Code of P1ʹ: 0000
Code of P2: 1001
Chose any one outside
point
P2: 1001 intersect with Xwmax
Xwmin
Xwmin (Find P2ʹ)
P2ʹ = (Xwmin,Y)
Ywmin
0000

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1ʹ to P2 1001 (Xwmin,Y)
P2ʹ = (Xwmin,Y)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin

Ywmin
0000

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1ʹ to P2 1001 (Xwmin,Y)
P2ʹ = (Xwmin,Y)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin
(Y – y1) = (X – x1) * m

Ywmin
0000

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1ʹ to P2 1001 (Xwmin,Y)
P2ʹ = (Xwmin,Y)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin
(Y – y1) = (X – x1) * m
Y = y1 + (X – x1) * m
Ywmin
0000

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1ʹ to P2 1001 (Xwmin,Y)
P2ʹ = (Xwmin,Y)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin
(Y – y1) = (X – x1) * m
Y = y1 + (X – x1) * m
P2ʹ is on line Ywmin
0000

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1ʹ to P2 1001 (Xwmin,Y)
P2ʹ = (Xwmin,Y)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin
(Y – y1) = (X – x1) * m
Y = y1 + (X – x1) * m
P2ʹ is on line Ywmin
0000
Y = y1 + (Xwmin – x1)* m
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1ʹ to P2 1001
P2ʹ = (Xwmin,Y)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin
(Y – y1) = (X – x1) * m
Y = y1 + (X – x1) * m
P2ʹ is on line Ywmin
0000
Y = y1 + (Xwmin – x1)* m
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1ʹ to P2ʹ 1001

Xwmax
Xwmin

Ywmin
0000

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1ʹ to P2ʹ 1001
Find P2ʹʹ

Xwmax
Xwmin

Ywmin
0000

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1ʹ to P2ʹ 1001
Find P2ʹʹ

Xwmax
Xwmin

Ywmin
0000

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P1ʹ to P2ʹʹ 1001 0000
Line is completely within
clip window.

Xwmax
Xwmin

Ywmin
0000

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P3 to P4 1001 0000

Xwmax
Xwmin

Ywmin

0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P3 to P4 1001 0000
Code of P3: 0001
Code of P4: 0100

Xwmax
Xwmin

0001 Ywmin

0100
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P3 to P4 1001 0000
Code of P3: 0001
Code of P4: 0100
Chose any one outside
point Xwmax
Xwmin
P3: 0001

0001 Ywmin

0100
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P3 to P4 1001 0000
Code of P3: 0001
Code of P4: 0100
Chose any one outside
point Xwmax
Xwmin
P3: 0001 intersect with
Xwmin (Find P3ʹ)
0001 Ywmin

0100
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P3ʹ to P4 1001 0000

Xwmax
Xwmin

Ywmin

0100
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P3ʹ to P4 1001 0000
Code of P3ʹ: 0100
Code of P4: 0100

Xwmax
Xwmin

0100 Ywmin

0100
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

Ywmax
Line from P3ʹ to P4 1001 0000
Code of P3ʹ: 0100
Code of P4: 0100

Line is completely outside Xwmax


Xwmin
clip window.

0100 Ywmin

0100
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)

1.

2. Apply Cohen Sutherland algorithm on following:


THANK YOU

You might also like