100% found this document useful (1 vote)
483 views2 pages

Midpoint Subdivision Line Clipping Algorithm

The document describes the midpoint subdivision line clipping algorithm. It uses this algorithm to find the visible portion of the line P1P2 within a clipping window defined by points A, B, C, D. It calculates the region codes for the line endpoints and midpoint at each step. Through iterative subdivision and region code calculation, it identifies the two intersection points of the line with the clipping window edges as (20,21) and (57,50). Therefore, the visible portion of the line within the clipping window is the line segment between those two points.

Uploaded by

Ansuman Mahanty
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
100% found this document useful (1 vote)
483 views2 pages

Midpoint Subdivision Line Clipping Algorithm

The document describes the midpoint subdivision line clipping algorithm. It uses this algorithm to find the visible portion of the line P1P2 within a clipping window defined by points A, B, C, D. It calculates the region codes for the line endpoints and midpoint at each step. Through iterative subdivision and region code calculation, it identifies the two intersection points of the line with the clipping window edges as (20,21) and (57,50). Therefore, the visible portion of the line within the clipping window is the line segment between those two points.

Uploaded by

Ansuman Mahanty
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/ 2

Midpoint Subdivision Line Clipping Algorithm

Using Midpoint Subdivision Line clipping Algorithm find the visible portion of the line P1P2,
where P1(1,6), P2(90,75) with respect to a clipping window ABCD where A (20, 20), B (70,20),
C(70,50), D (20,50).

Ans: The endpoints of the given line P1P2 be P1(1,6) and P2(90,75)
Thus the region codes of the given endpoints are Code_P1 = 0101, Code_P2 = 1010

Code_P1 OR Code_P2 = 0101 OR 1010 <> 0000, thus the line P1P2 is not totally visible.
Code_P1 AND Code_P2 = 0101 AND 1010 = 0000, thus the line P1P2 is a clipping candidate.

Now we find out the midpoint Pm of the line P1P2 ,


Pm = ( P1 + P2 )/2 = ((1+6)/2 , ( 90+75)/2) = (46,41)
Code_Pm = 0000

P1 Code_P1 P2 Code_P2 Pm Code_Pm Comment

(1,6) 0101 (90,75) 1010 (46,41) 0000 Save PmP2, continue with P1Pm
Continue with P1Pm, as PmP2 is
(1,6) 0101 (46,41) 0000 (24,24) 0000
totally visible
Continue with PmP2, as P1Pm is
(1,6) 0101 (24,24) 0000 (13,15) 0101
totally invisible
Continue with PmP2, as P1Pm is
(13,15) 0101 (24,24) 0000 (19,20) 0001
totally invisible
Continue with P1Pm, as PmP2 is
(19,20) 0001 (24,24) 0000 (22,22) 0000
totally visible
Continue with P1Pm, as PmP2 is
(19,20) 0001 (22,22) 0000 (21,21) 0000
totally visible
Succeeds. This is the
(19,20) 0001 (21,21)) 0000 (20,21) 0000 intersection point of line with
the Left window edge.

Thus one of the intersection point has been found at (20,21).

For the Second intersection point, we consider another half of the given line.:

P1 Code_P1 P2 Code_P2 Pm Code_Pm Comment

(1,6) 0101 (90,75) 1010 (46,41) 0000 Continue with Saved PmP2
Continue with P1Pm, as PmP2 is
(46,41) 0000 (90,75) 0010 (68,58) 1000
totally invisible
Succeeds. This is the
(46,41) 0000 (68,58) 1000 (57,50) 0000 intersection point of line with
the Top window edge

Thus the second intersection point has been found at (57,50).

Hence the visible portion of the given line is AB, where A=(20,21) and B=(57,50).

You might also like