0% found this document useful (0 votes)
55 views34 pages

Computer Graphics (CSE 4103)

The document discusses two algorithms for clipping lines: Cohen-Sutherland and Cyrus-Beck. Cohen-Sutherland divides the viewport into 9 regions and assigns each line segment an outcode based on which regions its endpoints are in. It can quickly reject lines not intersecting the viewport and clips intersecting lines. Cyrus-Beck computes the t value of intersections with viewport edges and classifies them as potentially entering or leaving, clipping the line between the largest entering and smallest leaving t values.

Uploaded by

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

Computer Graphics (CSE 4103)

The document discusses two algorithms for clipping lines: Cohen-Sutherland and Cyrus-Beck. Cohen-Sutherland divides the viewport into 9 regions and assigns each line segment an outcode based on which regions its endpoints are in. It can quickly reject lines not intersecting the viewport and clips intersecting lines. Cyrus-Beck computes the t value of intersections with viewport edges and classifies them as potentially entering or leaving, clipping the line between the largest entering and smallest leaving t values.

Uploaded by

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

Department of Computer Science and Engineering,

Computer Graphics (CSE 4103)

University of Dhaka
Lecture 6
Basic Raster Graphics Algorithm for
Drawing 2D Primitives

Clipping Line
Last Classes
1. Incremental Line-drawing Algorithm
2. Mid-point Algorithm for Line-drawing
i) In only one Octant
ii) In all 8 octants
iii) 8-way Symmetry
iv) Tangent Independent mid-point line drawing algorithm
3. Mid-point Algorithm for drawing Circle
4. Mid-point Algorithm for drawing Ellipse
This Class
1. Clipping lines using
a) Cohen-Sutherland Algorithm
b) Cyrus-Bech Algorithm
What is Clipping
From Computer Graphics context, Clipping is a method to
selectively enable or disable rendering operations within a
defined region of interest [Wiki].

In general, Clipping is a technique to trimming down a given


primitive with respect to an object.
What is Clipping..

Before Clipping
What is Clipping..

After Clipping
Clipping Lines by Solving Simultaneous
Equations D
F

B H

E C

J
A

I
Clipping Lines by Solving Simultaneous
Equations..
Input: Coordinates of Lines, Four corners of rectangle {(xmin, ymin) (xmax, ymax)}
Output: Clipped lines with respect to given rectangle

Step 1. For every line segment


Step 2: If the line is trivially accepted, do nothing
Step 3: else convert the line segment to equation of line (EL)
Step 4. consider the edges to equation of lines (EE)
Step 5. consider every pair or (EL, EEj)
Step 6. find the intersecting point between (EL, EEj)
Step 7. validate the intersecting point with respect to {(xmin, ymin) (xmax, ymax)}
Cohen-Sutherland Algorithm

Divide viewplane into regions defined by viewport edges


Assign each region a 4-bit outcode:
y>ymax, Bit-1=1, else 0

1001 1000 1010


x<xmin, Bit-4=1, else 0

x>xmin, Bit-3=1, else 0


ymax

0001 0000 0010

ymin
y<ymin, Bit-2=1, else 0

0101 0100 0110

xmin xmax
Cohen-Sutherland Algorithm..
1001 1000 1010

0001 0000 0010

0101 0100 0110

1. Check for trivial accept (both endpoints are in, i.e., outcode
for both endpoints are 0000)
2. Check whether it line segment is trivially reject
(Trivially reject condition: Bit-wise AND of two outcode
should be non-zero)
3. If line can be neither trivially accepted or trivially rejected,
then split in two at a clip edge and iterate the same process.
Cohen-Sutherland Algorithm..
1001 1000 1010

0001 0000 0010

0101 0100 0110

1. Check for trivial accept (both endpoints are in, i.e., outcode
for both endpoints are 0000)
2. Check whether it line segment is trivially reject
(Trivially reject condition: Bit-wise AND of two outcode
should be non-zero)
3. If line can be neither trivially accepted or trivially rejected,
then split in two at a clip edge and iterate the same process.
Cohen-Sutherland Algorithm..
D
F
H
1010
1001 1000

E C
0001 0000 0010

J
A

0101 0100 G 0110

I
Cohen-Sutherland Algorithm..

1001 1000 1010

B (0000)

Trivially Accepted
0001 0000 0010

A (0000)

0101 0100 0110


Cohen-Sutherland Algorithm..
D (1000)

1001 1000 1010

C (0000)
0001 0000 0010

0101 0100 0110


Cohen-Sutherland Algorithm..
D (1000)

1001 1000 1010


C (0000)

C (0000)
0001 0000 0010

0101 0100 0110


Cohen-Sutherland Algorithm..
F(1001)

1001 1000 1010

Trivially
Rejected
E(0001) 0001 0000 0010

0101 0100 0110


Cohen-Sutherland Algorithm..
H(1010)
1010
1001 1000

0001 0000 0010

0101 0100 G(0100) 0110


Cohen-Sutherland Algorithm..
H(1010)
1010
1001 1000
H(0010)

0001 0000 0010

0101 0100 G(0100) 0110


Cohen-Sutherland Algorithm..

1010
1001 1000
H(0010)

0001 0000 0010

G(0000)

0101 0100 0110


G(0100)
Cohen-Sutherland Algorithm..

1010
1001 1000
H(0010)

0001 0000 0010

G(0000)

0101 0100 0110


Cohen-Sutherland Algorithm..

1010
1001 1000
H(0010)

0001 0000 H(0000) 0010

G(0000)

0101 0100 0110


Cohen-Sutherland Algorithm..

1010
1001 1000

0001 0000 H(0000) 0010

G(0000)

0101 0100 0110


Cohen-Sutherland Algorithm..

1010
1001 1000

0001 0000 0010

J(0010)

0101 0100 0110

I(0100)
Cohen-Sutherland Algorithm..

1010
1001 1000

0001 0000 0010

J(0010)

I(0010)
0101 0100 0110

I(0100)
Cohen-Sutherland Algorithm..

1010
1001 1000

0001 0000 0010

J(0010)

I(0010)
0101 0100 0110
Cohen-Sutherland Algorithm..

1010
1001 1000

0001 0000 0010

J(0010)
Trivially Rejected
I(0010)
0101 0100 0110
Cyrus Beck Line Clipping Algorithm
Parametric Line Equation:
P(t) = P0 + (P1 -P0)t
P(0) = P0
P(1) = P1

PE is any arbitrary value on the edge


PE
P(t)-PE
N.[P(t)-PE]<0 P1

N.[P(t)-PE]>0

N.[P(t)-PE]=0

P0
N

N.[P(t)-PE]=0
=>N.[P0 + (P1 -P0)t -PE]=0 Let, D = (P1 -P0)
=>N.[P0 -PE]+ N.[P1 -P0]t=0
Cyrus Beck Line Clipping Algorithm
PE
P(t)-PE
N.[P(t)-PE]<0 P1

N.[P(t)-PE]>0

N.[P(t)-PE]=0

P0
N

For this to be true, the algorithm checks that


N!= 0, normal should not be zero
D!=0, (P1 !=P0)
N.D !=0 (Edge and line should not be parallel)
Cyrus Beck Line Clipping Algorithm
Compute t for line intersection with all four edges by
selecting in each of the four edges of clip rectangle
Obtain the values for t
Discard all (t < 0) and (t > 1)
Classify each remaining intersection as
Potentially Entering (PE)
Potentially Leaving (PL)
NL [P1 - P0] > 0 implies PL
NL [P1 - P0] < 0 implies PE
Note that we computed this term when computing t
Cyrus Beck Line Clipping Algorithm..
Compute PE with largest t
Compute PL with smallest t
Clip to these two points

PL P1
PL

PE
PE
P0
Cyrus Beck Line Clipping Algorithm..

PE
PL
PL PL
PL
PE

PE

PE
Cyrus Beck Line Clipping Algorithm..

PL
PL
PE

PE
Thank you

You might also like