0% found this document useful (0 votes)
13 views13 pages

Lec 2.1.2

The document outlines the Midpoint Subdivision Algorithm used for line clipping in computer graphics, detailing the steps involved in determining the visibility of line segments within specified window boundaries. It describes the process of assigning endpoint codes, checking visibility, and subdividing line segments until they are either fully visible or invisible. Additionally, it touches on polygon clipping and references key texts in computer graphics for further reading.

Uploaded by

alamtauhid2003
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)
13 views13 pages

Lec 2.1.2

The document outlines the Midpoint Subdivision Algorithm used for line clipping in computer graphics, detailing the steps involved in determining the visibility of line segments within specified window boundaries. It describes the process of assigning endpoint codes, checking visibility, and subdividing line segments until they are either fully visible or invisible. Additionally, it touches on polygon clipping and references key texts in computer graphics for further reading.

Uploaded by

alamtauhid2003
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/ 13

Department of Computer Science and Engineering (CSE)

University Institute of Engineering


DEPARTMENT OF COMPUTER SCIENCE
& ENGINEERING
Bachelor of Engineering (Computer Science & Engineering)
Subject Name: Computer Graphics with lab
Subject Code: 22CSH-352/22ITH-352
Prepared by:
Er. Puneet Kaur(E6913)

DISCOVER . LEARN . EMPOWER


Midpoint Subdivision algorithm

1
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)

Contents

• Midpoint subdivision Algorithm

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Mid Point Subdivision Algorithm

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

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Mid Point Subdivision Algorithm

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

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Mid Point Subdivision Algorithm

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.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Mid Point Subdivision Algorithm

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Mid Point Subdivision Algorithm

1. The mid point subdivision algorithm requires repeated subdivision of line


segments and hence many times it is slower than using direct calculation of
the intersection of the line with the clipping window edge.
2. It can be implemented efficiently using parallel architecture since it
involves parallel operations.
3. Mid Point algorithm uses integer function which works like floor functions.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Mid Point Subdivision Line Clipping


• A clipping window ABCD is specified as A(0,0),B(40,0),C(40,40),D(0,40).Using Mid
point subdivision algorithm find the visible portion if any, of the line segment joining
the points P(-10,20) and Q(50,10)

1000
D(0,40) C(40,40)
Mid Point

0001 P’ 0000 0010


P
(0,17)
(-10,20) Pm Q’
(20,15) (40,11) Q(50,10)

A(0,0) B(40,0)

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Mid Point Subdivision


• End point codes are • PQ P(-10,20) 0001
Q(50,10) 0010
Logical AND 0000
Indeterminate (Partially Visible)
• Mid Point is
x x  x
m
2 1

2
y y
y 
2 1
m
2
50  ( 10) 10  20
xm  ym 
2 2
xm 20 ym 15

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Mid Point Subdivision

P Q Mid Point Remarks


(-10,20) (50,10) 20,15 Save Mid Point & Continue

(-10,20) (20,15) 5,17 Continue with Mid Point as it is partially visible.

(-10,20) (5,17) -3,18 Discard a portion, it is invisible i.e.(-10,20) to Mid Point(-3,18)

(-3,18) (5,17) 1,17 Continue with Mid Point as it is visible

(-3,18) (1,17) -1,17 Discard a portion, it is invisible i.e.(-3,18) to Mid Point(-1,17)

(-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

(35,12) (50,10) 42,11 Discard a portion, it is invisible i.e.(50,10) to Mid Point(42,11)

(35,12) (42,11) 38,11 Continue with Mid Point as it is visible

(38,11) (42,11) 40,11 Success. It is the intersection point of the line with Right
window edge.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Polygon Clipping

• Polygon is a surface enclosed by several lines.


• Thus, Line clipping algorithm can be used directly for polygon clipping. But,
it would produce a set of unconnected line segments as the polygon is
exploded.
• Herein lies the need to use a different clipping algorithm to output truncated
but yet bounded regions from a polygon input.
• Polygon clipping done by line clipping algorithm

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

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

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Thanks…..

University Institute of Engineering (UIE)

You might also like