Lec 2.1.2
Lec 2.1.2
1
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Contents
1. Accept the end points of the line segment and window boundaries
i.e.x1,y1,x2,y2,xmin,xmax,ymin,ymax.
2. Assign a 4 bit code to each end point of the line segment i.e. b 1b2b3b4, as
follows
1 if y ymax 1 if y ymin
b1 b2
0 otherwise 0 otherwise
1 if x xmax 1 if x xmin
b3 b4
0 otherwise 0 otherwise
3. Check for visibility of line using end point codes & Logical AND
a) If both the end point codes are 0000,the line is visible.
b) If the logical AND of the endpoint codes is not 0000,the line segment is not visible.
c) If the logical AND of the endpoint codes is 0000,the line segment is clipping
candidate.
4. Determine the intersecting boundary
a) If bit1 is 1,intersect with line y=ymax
b) If bit2 is 1,intersect with line y=ymin
c) If bit3 is 1,intersect with line x=xmax
d) If bit4 is 1,intersect with line x=xmin
5. Divide the partially visible line segments in equal parts such that
m x x x
2 1
2
y y
y
2 1
m
2
and repeat steps 2 through 5 for both subdivided line segments until the
line is completely visible and completely invisible.
6. Stop.
1000
D(0,40) C(40,40)
Mid Point
A(0,0) B(40,0)
2
y y
y
2 1
m
2
50 ( 10) 10 20
xm ym
2 2
xm 20 ym 15
(-1,17) (1,17) 0,17 Success. It is the intersection point of the line with left
window edge.
(20,15) (50,10) 35,12 Recalled Saved Mid Point & Continue with mid Point
(38,11) (42,11) 40,11 Success. It is the intersection point of the line with Right
window edge.
Polygon Clipping
References
• Computer Graphics C Version, Donald Hearn and M.Pauline Baker
Pearson Education.
• Computer Graphics Principles and Practice C.foley, VanDam, Feiner and
Hughes, Pearson Education
• Newman, William M., Sproull, Robert F., “Principles of Interactive
Computer Graphics”, Tata McGraw Hill Company, 2nd Edition. Link:
http://archive.mu.ac.in/myweb_test/S.Y.B.Sc.(IT)%20(Sem%20%20III
%20)%20Computer%20Graphics.pdf
Thanks…..