Computer Graphics (CSE 4103)
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].
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
ymin
y<ymin, Bit-2=1, else 0
xmin xmax
Cohen-Sutherland Algorithm..
1001 1000 1010
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
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
I
Cohen-Sutherland Algorithm..
B (0000)
Trivially Accepted
0001 0000 0010
A (0000)
C (0000)
0001 0000 0010
C (0000)
0001 0000 0010
Trivially
Rejected
E(0001) 0001 0000 0010
1010
1001 1000
H(0010)
G(0000)
1010
1001 1000
H(0010)
G(0000)
1010
1001 1000
H(0010)
G(0000)
1010
1001 1000
G(0000)
1010
1001 1000
J(0010)
I(0100)
Cohen-Sutherland Algorithm..
1010
1001 1000
J(0010)
I(0010)
0101 0100 0110
I(0100)
Cohen-Sutherland Algorithm..
1010
1001 1000
J(0010)
I(0010)
0101 0100 0110
Cohen-Sutherland Algorithm..
1010
1001 1000
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
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
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