Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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.
(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.
For the Second intersection point, we consider another half of the given line.:
(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
Hence the visible portion of the given line is AB, where A=(20,21) and B=(57,50).