AN FOR 2-D DEVELOPMENT - Computer Sciencedavid/Classes/Talks/... · FOR 2-D LINE CLIPPING ITS...
Transcript of AN FOR 2-D DEVELOPMENT - Computer Sciencedavid/Classes/Talks/... · FOR 2-D LINE CLIPPING ITS...
AN EFFICIENT NEW ALGORITHM FOR 2-D LINE CLIPPING ITS DEVELOPMENT AND ANALYSIS Authors: T. Nicholl, D. T. Lee, and R. Nicholl
Presentation by Marcus McCurdy
WHAT IS CLIPPING?
Basically finding the intersection of two geometric entities.
(x1,y1)
(x2,y2)
xLeft, yBottom
xRight, yTop
Intersection
OTHER ALGORITHMS
Cohen-Sutherland Cyrus Beck Liang-Barsky SPY
In all of these algorithms, intersection points not involved in the final output are calculated
CLIPPING INEFFICIENCIES
SPY and CS will calculate IL before rejecting LB will compute all 4
IB
IT IL
IR
MACHINE INDEPENDENT ANALYSIS
Evaluated efficiency by counting the number of executions of the following operations:
Comparisons Addition Subtraction Multiplication Division
9 REGIONS
Window
Top edge
Bottom edge
Left edge Right edge
Top right corner
Bottom right corner
Bottom left corner
Top left corner
ALGORITHM
Characterize P1’s location among the 9 regions (straightforward).
Based on P1 characterize P2 among appropriate subdivisions (not quite so straightforward).
Calculate intersection points according to the characterization.
Only the intersection points required for output are calculated.
POSITIONS OF P1 AND P2
P1 is located in the window, an edge region, or a corner region.
P2 may be at any point on the 2D Cartesian plane
Divide all possible positions of P2 into regions each of which corresponds to intersection points at the same boundaries (or none) to be output
The following 3 figures show the subdivisions. All other cases are the same as one of them up to a rotation of a multiple of 90º about the origin or a reflection about the line x = -y, or a combination of the two
(~) ~ Computer Graphics, Volume 21, Number 4, July 1987
X. CONCLUSIONS AND FUTURE WORK
We have developed a new 2-dimensional line clipping algo- rithm. Using a machine-independent analysis, we have shown that this algorithm is faster than both the Cohen-Sutherland algorithm and the Liang-Barsky algorithm. Using program transformation techniques we showed how geometric transfor- mations on the line to be clipped could be performed by modified program text without the overhead of actually exe- cuting statements to perform the transformation. Currently, we are investigating the possibility of extending it to polygons and to the 3-dimensional case.
Acknowledgements The authors would like to acknowledge the useful discussions with colleagues and students at the University of Western Ontario, especially Ti m Walsh. We are very grateful for the reviewers' suggestions, which we have incorporated, within the space allowed. Financial upport for this research was provided by the National Science and Engineering Research Council (NSERC) of Canada.
REFERENCES
[I] Newman, W. M. and R. F. Sproull. Principles of Interac- tive Computer Graphics, 2nd ed., McGraw-Hill, New York, 1979.
[2] Sproull, R. F. and I. E. Sutherland. A Clipping Divider, FICC 1968, Thompson Books, Washington, D.C., pp. 765-775.
[3] Cyrus, M. and I. Beck. Generalised Two- and Three - Dimensional Clipping, Computers and Graphics, Vol. 3, No. 1, 1978, pp. 23-28.
[4] Liang, Y.-D. and B. A. Barsky. A New Concept and Method for Line Clipping, ACM Transactions on Graph- ies, Vol. 3, No. 1, 1984, pp. 1-22.
[5] Sobkow, M. S., Pospisil, P. and Y.-II. Yang. A Fast Two- Dimensional Line Clipping Algorithm, University of Saskatchewan Technical Report, 86-2.
[6] Hoare, C. A. R. et al. Laws of Programming: a tutorial paper, Oxford University Programming Research Group PRG-45, 1985.
[7] Arsac, J. I. Syntactic Source to Source Transforms and Program Manipulation, Communications of the ACM, Vol. 22, No. 1, 1979, pp. 43-54.
I R ....-+
iT ~ "
Fig. I Intersection points computed b5 previous al,3orithms
top le?t corner region
le?t edge resion
bottom le?t c o rne r region
top edge
resion
window
bottom edge
resion
top right cornet- region
risht edse
resion
bottom right c o r n e r region
Fi 9. 2 Subdivision o? the plane into regions
• -l~-l~r]q i i | i i i 1 t 11 ITi ~ | I I I I I | I I I I I I I I I 1 1~ I 1 1 l-r~ l 1111111 ~ 71~Iq I I I I I I I I I I I I-1"I~ I I l i i i I I I i | I I l'l']'~Tl~lq I [ I I i I I J~'~R~ [~|'I IIIII tlll III I I~ tl II lllllll I III I I I I I~ I I III III I I I k~RRR~ ['FI~[TIq I I I L I I I I I FIt I I I I I I II II II Ill I II I |I I I I I I I I I I I~RRRRR~
~i i ii ii i ii i i iI II I~ II II |i III II III II Ill I~I II I I | ~(RRRRRR - 1~12'12~.L 1 . . . . . . . . . . . ~ . . . . . . . . 1 . . . . . . . . l t ,~ I t ,~RRRRRRRRRR~ ~LLLLLL[LE%.LI L £ t I t t~ I I I I I t L L t I L Z t t t A I I t I~ £ ~RRRRRRRRRRRRR~ ~LLLLLLLLLLLI~[~L~6.t L[i t I t t t L t t I t i t I i t t t ]71-I I~.RRRRRRRRRRRRRR| [LLLLLLLLLLLLLLLLL~ ............ .." I~F.RRRRRRRRRRRRRR| iLLLLLLLLLLLLLLLLL ......... -'"... rA ." RRRRRRRRRRRRRRRR| iLLLLLLLLLLLLLLLLL ..... ":~" RRRRRRRRRRRRRRRR ' L L L L L L L L L L L L L L L L ~ ........ \ RRRRRRRRRRRRRRRR I ~LLLLLLLLLLLLLLLLLI] ""'" \ RR.RRRRRRR RRRRRRR! ILLLLLLLLLLLLLLLLL d ........ \ RRRRRRRRRRRRRRRRI iLLLLLLLLLLLLLLLLL ...."'" ~ RRRRRRRRRRRRRRRR i [ lT l . . . . . . . . . . . . i ~ .... RRRRRRRRRRRRRRRR] LLLLLLLLLLLLLLi~i,: .~ BBBBB B BB B B BB BB BBf~ RR.R RRRRRRRRRRRR!
iLLLLLLLLLLLI~3~ B B~ B B B B B B B B B BBB BB BBB B pI~RRRRRR RRRR RRRR[ iLLLLLLLLL[.a:,'I~ BBB B B~BBB BB B BB BBBB BBBBB B ~ BI~RRRRRRRRRRRRR] ~LLLLLL~..~'I~'BBB B B B B B~BB B BB BBB BBB B B BBBB B ~ B B ~ R R RRRRRRRRRR .ILLLi,~'BBBBBBBBBBB~BBBBBBBBBBBBBBBBBB ~BBB~RRRRRRRRRRRR! -I~£~B BBBBBBBBBBBB~BBBBBBBBBBBBBBBBBB~BBBB~RRKRRRRRRRI LiBBBBBBBBBBBBBBBB~BBBBBBBBBBBBBBBBBB 3BBBBB~RRRRRRRRRR I iBBBBBBBBBBBBBBBB~BBBBBBBBBBBBBBBBBB 3BBBBBB~RRRRRRRRR LBBBB.BBBBBBBBBBBBJ~BBBBBBBBBBBp_BBBBBB ~BBBBBBBRRRRRRRRR|
Fig. 3 Subdivision of the plane when Pl is in the window
261
~ , ~ SIGGRAPH '87, Anaheim, July 27-31, 1987
[ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ~TL I I ' n_ ; I IXLTLTL 'n . .TL ' rLTL 'n . .T~ i /ll.TLTLTL1LTLTL'n.TLTUT.TLTLTi i ,mTLTLTL~TLTLTLTLTL~TL~T I i Z L ' n ' ~ TLT LT L 'n : n ' ~ ' n " m ' n ' ~ TLT I i .ZTLTL'II.TLTLTLI~TLTLTLTLTLTLIlTLTI i Z~LTLYLTLTLTLTLTLIITLTLTLrLrLTLYL~ i /~LTL'IIILTLTLTLTLI~TLIITLll;It 12-'~.9.~R] i . ~TLT~TLT~rcTLTL~TLTL~.~,rS.LRLRLR~ I :LTLTLTLTLTLTLTLTLTbllL.t~ . £ ~ R L R L R L R L R L~ . . . . . . . . . . . . . . . . . . . . . . i :." LLLLLLUJ/..LLI.J/ - RLELRLRLRLRLRLI~i.i~
! / LLLLE~I,~f~iLLLLLLLLI~ RLRLRLRLRLPJ-RLPJ- ~ / ..~-~-~u~u-uu~u-u~u~W~u~u~R u~-~
i P 1 -'-":- ......... ~LilJ ! r ! ! 7 ! ! LLLLLLLLI.IRLRLRLRLRLRLRLPd..RI i "~::7---.__ LU t t t t t u . .LLLLL RLRLRLRLRI.Pd..RLRLpj
~LB LB LBLB L B LBL B LB L~ L~ E~L~.L~LRL RL~ l "~BLBLBLBLBLBLBflBLBLB LBLBLB~
j "m~SLBLBLBLBLB~BLBLBLBLBLB LBLBLB] I | "%~BLBLBLBII~LBLB LBLBLBLBLBLHI
",d~LBLB[~BLBLBLBLBLBLBLBLB| ; "~Bb~LBLBLBLBLB LBLB LB
! I "N~BLBLBLBLBLBLBLBLB I ! [ "~'B'-LB LB L B LB LB L B LBI L .................... _/ ......................... Lm.__~__L. BLBLBLBLBLB~
Fi$. 4 Subdivision oF the plane when Pl is in an edse region
, i i , ' • • , i i ' • I I • I l i i Pl ! i i
! ::-. I ............. I i I • "..- ---.-- | - i . . . . . . . . . . . . . . . . . ~......- -- " - - - . . . . . . . . . . . . . . . . . . - - . I [ ~ $~J..l I I 1 I 1111 I 1 I I I I I 1 ~TI ' rT~. . .... I
i ~ [u.~;~.~ . . . . . . . . . . . hTRTRTRTRTR'm~ ! ~ LLLLLLU[~AI* l l t t i ~TRTRTR ' i~TR ' I~TRT~
i 5. I . L L L L D . U . J . I ~ [ i i ,. j., ~ t ,~RTRTRTRTRTRIRYRT~
! :[LLLLLLLLLLLLLt L l *, i%1 i~ I'RTRTRTRTR~__~I" ~ [ ................... ~LBLBLSLBLBLSLSm~IR~~ i | t B LB LB i B LB LB L B LB L~I~BTB'YCRTRTRTRTRTRT~ i ! ~B LB LB L B LB LB LB LB L B I~W~TB TB?r/~TRTRTRTRT~ ! I ~LBLBLBLBLBLBLB LBL~L~TBTB~RTRTRTRT~ I : ~LBLBLBLBLBLBLBLBL~LB~';BTBTB~TRTRTII i ! 'tBLBLBLBLBLBLBLBL~LBLBh~BTBTBT~RTt i i ~BLBLBLBLBLBLBLBLt~LBLBLI~EP~TBTBT~p~ [ i ~LBLBLBLBLBLBLBL~LBLBLBLB~TBTBT~ L . . . . . . . . . . . . . . . . . . . . . i _ _ %--.~--B--L.B. L--B.L- B--L.B-Ir-B.L B--~.~ LB 5 BLB LB L 6~BTBTI~
FiS. 5 Subdivision oF the plane when P! is in a corner resion
I CS LB NLN 25.5 20 8
I 1.5 2 1 4.5 6 4
l 1.5 2 2 1.5 4 1
COMPARISONS +
/
CS LB NLN 21 20 7.5 1 2 1 3 6 3 1 2 1 1 4 1
CS LB NLN P1 i0 20 8 0 0 0 0 6 0 0 0 0 0 4 0
J
FIG.6 Analysis of the three algorithms when P1 is in the window
L
CS LB NLN 9.5 10.5 3.5 0 0 0 0 4 0 0 0 0 0 2.5 0
COMPARISONS +
/
/ /
/
CS LB / NLN i0 10.5 3.5 0 01 0 0 4 0 0 ,0 0 0 /2.5 0
/ / /_ - n
CS NLN F ~ .75 " NLN LB CS LB ~. 5 21 i~.75 ~.5 0 14.75 1 1 0 3 I/3 55 i/ CS LB NLN 32 /20 8.5 2/ 4 2 6 6 4 /~ 4 2
4 2
CS LB NLN 21 20 8 1 2 1 3 6 3 1 2 1 1 4 l
1 3.5 0
CS LB NLN 3b.5 20 g.5 2.5 4 2 7.5 6 5 2.5 4 3 2.5 4 2
CS LB NLN 32 20 8 2 4 2 6 6 4 2 4 2 2 4 2
FIG.7 Analysis of the three algorithms when P1 is in an edge region
"Further subdivision is needed. Average shown is for the largest unbounded subregion."
CS LB NLN 9 6 2.5 0 0 0 0 2.5 0 0 0 0 0 1.5 0
1 [ CS LB NLN CS LB NLN 9.5 10.5 3.75 9 10.5 3.75
~ 0 0 0 0 '-" -° °- ! I o o,o I \ \ o ~ o o o o \ \ 2.5 . 0 2.5 0
i i TM , ~s ~ ~ c~ \ 25.5 20 1 .75 \ 1.5\ 2 1 \ 4.5 "6 4 4.5 05.5
1.5 2\ 2 1-5 ~ 1.5 4 \ 1 1.5 3.5 ~ 0
CS LB NLN ~ CS LB NLN COMPARISONS 36.5 20 36.5 20 8
+ 2.5 4 2.5 4 2 7.5 6 7.5 6 5
* 2.5 4 2.5 4 3 / 2.5\4 2.5 4 2
CS LB NLN 41 20 i0 3 4 2 9 6 6 3 4 4 3 4 2
CS LB NLN 25 14.5 8 1.5 0 0 4.5 5.5 5 1.5 0 3 1.5 3.5 0
FIG.8 Analysis of the three algorithms when P1 is in a corner region
262
~ , ~ SIGGRAPH '87, Anaheim, July 27-31, 1987
[ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ~TL I I ' n_ ; I IXLTLTL 'n . .TL ' rLTL 'n . .T~ i /ll.TLTLTL1LTLTL'n.TLTUT.TLTLTi i ,mTLTLTL~TLTLTLTLTL~TL~T I i Z L ' n ' ~ TLT LT L 'n : n ' ~ ' n " m ' n ' ~ TLT I i .ZTLTL'II.TLTLTLI~TLTLTLTLTLTLIlTLTI i Z~LTLYLTLTLTLTLTLIITLTLTLrLrLTLYL~ i /~LTL'IIILTLTLTLTLI~TLIITLll;It 12-'~.9.~R] i . ~TLT~TLT~rcTLTL~TLTL~.~,rS.LRLRLR~ I :LTLTLTLTLTLTLTLTLTbllL.t~ . £ ~ R L R L R L R L R L~ . . . . . . . . . . . . . . . . . . . . . . i :." LLLLLLUJ/..LLI.J/ - RLELRLRLRLRLRLI~i.i~
! / LLLLE~I,~f~iLLLLLLLLI~ RLRLRLRLRLPJ-RLPJ- ~ / ..~-~-~u~u-uu~u-u~u~W~u~u~R u~-~
i P 1 -'-":- ......... ~LilJ ! r ! ! 7 ! ! LLLLLLLLI.IRLRLRLRLRLRLRLPd..RI i "~::7---.__ LU t t t t t u . .LLLLL RLRLRLRLRI.Pd..RLRLpj
~LB LB LBLB L B LBL B LB L~ L~ E~L~.L~LRL RL~ l "~BLBLBLBLBLBLBflBLBLB LBLBLB~
j "m~SLBLBLBLBLB~BLBLBLBLBLB LBLBLB] I | "%~BLBLBLBII~LBLB LBLBLBLBLBLHI
",d~LBLB[~BLBLBLBLBLBLBLBLB| ; "~Bb~LBLBLBLBLB LBLB LB
! I "N~BLBLBLBLBLBLBLBLB I ! [ "~'B'-LB LB L B LB LB L B LBI L .................... _/ ......................... Lm.__~__L. BLBLBLBLBLB~
Fi$. 4 Subdivision oF the plane when Pl is in an edse region
, i i , ' • • , i i ' • I I • I l i i Pl ! i i
! ::-. I ............. I i I • "..- ---.-- | - i . . . . . . . . . . . . . . . . . ~......- -- " - - - . . . . . . . . . . . . . . . . . . - - . I [ ~ $~J..l I I 1 I 1111 I 1 I I I I I 1 ~TI ' rT~. . .... I
i ~ [u.~;~.~ . . . . . . . . . . . hTRTRTRTRTR'm~ ! ~ LLLLLLU[~AI* l l t t i ~TRTRTR ' i~TR ' I~TRT~
i 5. I . L L L L D . U . J . I ~ [ i i ,. j., ~ t ,~RTRTRTRTRTRIRYRT~
! :[LLLLLLLLLLLLLt L l *, i%1 i~ I'RTRTRTRTR~__~I" ~ [ ................... ~LBLBLSLBLBLSLSm~IR~~ i | t B LB LB i B LB LB L B LB L~I~BTB'YCRTRTRTRTRTRT~ i ! ~B LB LB L B LB LB LB LB L B I~W~TB TB?r/~TRTRTRTRT~ ! I ~LBLBLBLBLBLBLB LBL~L~TBTB~RTRTRTRT~ I : ~LBLBLBLBLBLBLBLBL~LB~';BTBTB~TRTRTII i ! 'tBLBLBLBLBLBLBLBL~LBLBh~BTBTBT~RTt i i ~BLBLBLBLBLBLBLBLt~LBLBLI~EP~TBTBT~p~ [ i ~LBLBLBLBLBLBLBL~LBLBLBLB~TBTBT~ L . . . . . . . . . . . . . . . . . . . . . i _ _ %--.~--B--L.B. L--B.L- B--L.B-Ir-B.L B--~.~ LB 5 BLB LB L 6~BTBTI~
FiS. 5 Subdivision oF the plane when P! is in a corner resion
I CS LB NLN 25.5 20 8
I 1.5 2 1 4.5 6 4
l 1.5 2 2 1.5 4 1
COMPARISONS +
/
CS LB NLN 21 20 7.5 1 2 1 3 6 3 1 2 1 1 4 1
CS LB NLN P1 i0 20 8 0 0 0 0 6 0 0 0 0 0 4 0
J
FIG.6 Analysis of the three algorithms when P1 is in the window
L
CS LB NLN 9.5 10.5 3.5 0 0 0 0 4 0 0 0 0 0 2.5 0
COMPARISONS +
/
/ /
/
CS LB / NLN i0 10.5 3.5 0 01 0 0 4 0 0 ,0 0 0 /2.5 0
/ / /_ - n
CS NLN F ~ .75 " NLN LB CS LB ~. 5 21 i~.75 ~.5 0 14.75 1 1 0 3 I/3 55 i/ CS LB NLN 32 /20 8.5 2/ 4 2 6 6 4 /~ 4 2
4 2
CS LB NLN 21 20 8 1 2 1 3 6 3 1 2 1 1 4 l
1 3.5 0
CS LB NLN 3b.5 20 g.5 2.5 4 2 7.5 6 5 2.5 4 3 2.5 4 2
CS LB NLN 32 20 8 2 4 2 6 6 4 2 4 2 2 4 2
FIG.7 Analysis of the three algorithms when P1 is in an edge region
"Further subdivision is needed. Average shown is for the largest unbounded subregion."
CS LB NLN 9 6 2.5 0 0 0 0 2.5 0 0 0 0 0 1.5 0
1 [ CS LB NLN CS LB NLN 9.5 10.5 3.75 9 10.5 3.75
~ 0 0 0 0 '-" -° °- ! I o o,o I \ \ o ~ o o o o \ \ 2.5 . 0 2.5 0
i i TM , ~s ~ ~ c~ \ 25.5 20 1 .75 \ 1.5\ 2 1 \ 4.5 "6 4 4.5 05.5
1.5 2\ 2 1-5 ~ 1.5 4 \ 1 1.5 3.5 ~ 0
CS LB NLN ~ CS LB NLN COMPARISONS 36.5 20 36.5 20 8
+ 2.5 4 2.5 4 2 7.5 6 7.5 6 5
* 2.5 4 2.5 4 3 / 2.5\4 2.5 4 2
CS LB NLN 41 20 i0 3 4 2 9 6 6 3 4 4 3 4 2
CS LB NLN 25 14.5 8 1.5 0 0 4.5 5.5 5 1.5 0 3 1.5 3.5 0
FIG.8 Analysis of the three algorithms when P1 is in a corner region
262
GEOMETRIC TRANSFORMATIONS
P1 may be in any one of 9 regions Different procedure could be written to handle
each case However, writing similar but not identical code
may be error-prone Exploit symmetry to prevent this
ALGORITHM
Find where P1 is in relation to the Left and Right boundaries.
May be beyond left, beyond right, or between the two.
Beyond left is symmetrical to beyond right up to a rotation of 180º about the origin and they can be handled together
P1 IS BEYOND LEFT BOUNDARY
If P2 is also beyond LB then line is invisible stop Now find if P1 is beyond top boundary, bottom
boundary, or between the two. Again, beyond top is symmetrical with beyond
bottom, reflection about the x-axis.
P1 IS IN TOP LEFT CORNER
If P2 is above top stop line is invisible Compare P2 against the line joining P1 and the
top-left corner The case where P2 is on one side of this line is
symmetrical to the case in which it is on the other side. Handle one of the two cases.
P1 TOP LEFT CORNER
P2 not beyond the left and to the right of vector from P1 to the top left corner
If P2 is above the bottom then no more oblique boundaries need to be computed
However, if P2 is below bottom 3 possibilities Boundary from line joining P1 to bottom left has
to be computed no matter which side of right boundary P2 happens to be on. Do this comparison first
If left no more oblique boundaries, else more comparison to decide which subdivision P2 is in
P1 IN LEFT EDGE
If P2 is beyond left then line is invisible P2 may be above top, below bottom, or between
top and bottom. Again above top is symmetric to below bottom
P1 IN LEFT EDGE & P2 BEYOND BOTTOM
Comparing boundary joining P1 to the bottom left corner cannot be avoided so do this one first.
P1 BTW LEFT AND RIGHT
If P1 above top or below bottom case is symmetrical to that of P1 in the left edge region so use the same procedure
P1 IN THE WINDOW
If P2 is in an edge region then the intersection point can be seen from figure 3
If P2 is in a corner region then comparison with one oblique boundary is necessary before appropriate intersection calculation is possible
Use symmetry to reduce different cases
(~) ~ Computer Graphics, Volume 21, Number 4, July 1987
X. CONCLUSIONS AND FUTURE WORK
We have developed a new 2-dimensional line clipping algo- rithm. Using a machine-independent analysis, we have shown that this algorithm is faster than both the Cohen-Sutherland algorithm and the Liang-Barsky algorithm. Using program transformation techniques we showed how geometric transfor- mations on the line to be clipped could be performed by modified program text without the overhead of actually exe- cuting statements to perform the transformation. Currently, we are investigating the possibility of extending it to polygons and to the 3-dimensional case.
Acknowledgements The authors would like to acknowledge the useful discussions with colleagues and students at the University of Western Ontario, especially Ti m Walsh. We are very grateful for the reviewers' suggestions, which we have incorporated, within the space allowed. Financial upport for this research was provided by the National Science and Engineering Research Council (NSERC) of Canada.
REFERENCES
[I] Newman, W. M. and R. F. Sproull. Principles of Interac- tive Computer Graphics, 2nd ed., McGraw-Hill, New York, 1979.
[2] Sproull, R. F. and I. E. Sutherland. A Clipping Divider, FICC 1968, Thompson Books, Washington, D.C., pp. 765-775.
[3] Cyrus, M. and I. Beck. Generalised Two- and Three - Dimensional Clipping, Computers and Graphics, Vol. 3, No. 1, 1978, pp. 23-28.
[4] Liang, Y.-D. and B. A. Barsky. A New Concept and Method for Line Clipping, ACM Transactions on Graph- ies, Vol. 3, No. 1, 1984, pp. 1-22.
[5] Sobkow, M. S., Pospisil, P. and Y.-II. Yang. A Fast Two- Dimensional Line Clipping Algorithm, University of Saskatchewan Technical Report, 86-2.
[6] Hoare, C. A. R. et al. Laws of Programming: a tutorial paper, Oxford University Programming Research Group PRG-45, 1985.
[7] Arsac, J. I. Syntactic Source to Source Transforms and Program Manipulation, Communications of the ACM, Vol. 22, No. 1, 1979, pp. 43-54.
I R ....-+
iT ~ "
Fig. I Intersection points computed b5 previous al,3orithms
top le?t corner region
le?t edge resion
bottom le?t c o rne r region
top edge
resion
window
bottom edge
resion
top right cornet- region
risht edse
resion
bottom right c o r n e r region
Fi 9. 2 Subdivision o? the plane into regions
• -l~-l~r]q i i | i i i 1 t 11 ITi ~ | I I I I I | I I I I I I I I I 1 1~ I 1 1 l-r~ l 1111111 ~ 71~Iq I I I I I I I I I I I I-1"I~ I I l i i i I I I i | I I l'l']'~Tl~lq I [ I I i I I J~'~R~ [~|'I IIIII tlll III I I~ tl II lllllll I III I I I I I~ I I III III I I I k~RRR~ ['FI~[TIq I I I L I I I I I FIt I I I I I I II II II Ill I II I |I I I I I I I I I I I~RRRRR~
~i i ii ii i ii i i iI II I~ II II |i III II III II Ill I~I II I I | ~(RRRRRR - 1~12'12~.L 1 . . . . . . . . . . . ~ . . . . . . . . 1 . . . . . . . . l t ,~ I t ,~RRRRRRRRRR~ ~LLLLLL[LE%.LI L £ t I t t~ I I I I I t L L t I L Z t t t A I I t I~ £ ~RRRRRRRRRRRRR~ ~LLLLLLLLLLLI~[~L~6.t L[i t I t t t L t t I t i t I i t t t ]71-I I~.RRRRRRRRRRRRRR| [LLLLLLLLLLLLLLLLL~ ............ .." I~F.RRRRRRRRRRRRRR| iLLLLLLLLLLLLLLLLL ......... -'"... rA ." RRRRRRRRRRRRRRRR| iLLLLLLLLLLLLLLLLL ..... ":~" RRRRRRRRRRRRRRRR ' L L L L L L L L L L L L L L L L ~ ........ \ RRRRRRRRRRRRRRRR I ~LLLLLLLLLLLLLLLLLI] ""'" \ RR.RRRRRRR RRRRRRR! ILLLLLLLLLLLLLLLLL d ........ \ RRRRRRRRRRRRRRRRI iLLLLLLLLLLLLLLLLL ...."'" ~ RRRRRRRRRRRRRRRR i [ lT l . . . . . . . . . . . . i ~ .... RRRRRRRRRRRRRRRR] LLLLLLLLLLLLLLi~i,: .~ BBBBB B BB B B BB BB BBf~ RR.R RRRRRRRRRRRR!
iLLLLLLLLLLLI~3~ B B~ B B B B B B B B B BBB BB BBB B pI~RRRRRR RRRR RRRR[ iLLLLLLLLL[.a:,'I~ BBB B B~BBB BB B BB BBBB BBBBB B ~ BI~RRRRRRRRRRRRR] ~LLLLLL~..~'I~'BBB B B B B B~BB B BB BBB BBB B B BBBB B ~ B B ~ R R RRRRRRRRRR .ILLLi,~'BBBBBBBBBBB~BBBBBBBBBBBBBBBBBB ~BBB~RRRRRRRRRRRR! -I~£~B BBBBBBBBBBBB~BBBBBBBBBBBBBBBBBB~BBBB~RRKRRRRRRRI LiBBBBBBBBBBBBBBBB~BBBBBBBBBBBBBBBBBB 3BBBBB~RRRRRRRRRR I iBBBBBBBBBBBBBBBB~BBBBBBBBBBBBBBBBBB 3BBBBBB~RRRRRRRRR LBBBB.BBBBBBBBBBBBJ~BBBBBBBBBBBp_BBBBBB ~BBBBBBBRRRRRRRRR|
Fig. 3 Subdivision of the plane when Pl is in the window
261
ANALYSIS
Fewest divisions among the algorithms. Equal to the number of intersection points for output.
Fewest comparisons. About 1/3 CS and about 1/2 LB.
CS requires largest number of comparison in most cases
With large window dominating case is when P2 is in window. CS does few set operations, and so LB is slowest
Small window dominating cases are the four corner regions. CS is slower in this case,
~ , ~ SIGGRAPH '87, Anaheim, July 27-31, 1987
[ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ~TL I I ' n_ ; I IXLTLTL 'n . .TL ' rLTL 'n . .T~ i /ll.TLTLTL1LTLTL'n.TLTUT.TLTLTi i ,mTLTLTL~TLTLTLTLTL~TL~T I i Z L ' n ' ~ TLT LT L 'n : n ' ~ ' n " m ' n ' ~ T LT I i .ZTLTL'II.TLTLTLI~TLTLTLTLTLTLIlTLTI i Z~LTLYLTLTLTLTLTLIITLTLTLrLrLTLYL~ i /~LTL'IIILTLTLTLTLI~TLIITLll;It 12-'~.9.~R] i . ~TLT~TLT~rcTLTL~TLTL~.~,rS.LRLRLR~ I :LTLTLTLTLTLTLTLTLTbllL.t~ . £ ~ R L R L R L R L R L~ . . . . . . . . . . . . . . . . . . . . . . i :." LLLLLLUJ/..LLI.J/ - RLELRLRLRLRLRLI~i.i~
! / LLLLE~I,~f~iLLLLLLLLI~ RLRLRLRLRLPJ-RLPJ- ~ / ..~-~-~u~u-uu~u-u~u~W~u~u~R u~-~
i P 1 -'-":- ......... ~LilJ ! r ! ! 7 ! ! LLLLLLLLI.IRLRLRLRLRLRLRLPd..RI i "~::7---.__ LU t t t t t u . .LLLLL RLRLRLRLRI.Pd..RLRLpj
~LB LB LBLB L B LBL B LB L~ L~ E~L~.L~LRL RL~ l "~BLBLBLBLBLBLBflBLBLB LBLBLB~
j "m~SLBLBLBLBLB~BLBLBLBLBLB LBLBLB] I | "%~BLBLBLBII~LBLB LBLBLBLBLBLHI
",d~LBLB[~BLBLBLBLBLBLBLBLB| ; "~Bb~LBLBLBLBLB LBLB LB
! I "N~BLBLBLBLBLBLBLBLB I ! [ "~'B'-LB LB L B LB LB L B LBI L .................... _/ ......................... Lm.__~__L. BLBLBLBLBLB~
Fi$. 4 Subdivision oF the plane when Pl is in an edse region
, i i , ' • • , i i ' • I I • I l i i Pl ! i i
! ::-. I ............. I i I • "..- ---.-- | - i . . . . . . . . . . . . . . . . . ~......- -- " - - - . . . . . . . . . . . . . . . . . . - - . I [ ~ $~J..l I I 1 I 1111 I 1 I I I I I 1 ~TI ' rT~. . .... I
i ~ [u.~;~.~ . . . . . . . . . . . hTRTRTRTRTR'm~ ! ~ LLLLLLU[~AI* l l t t i ~TRTRTR ' i~TR ' I~TRT~
i 5. I . L L L L D . U . J . I ~ [ i i ,. j., ~ t ,~RTRTRTRTRTRIRYRT~
! :[LLLLLLLLLLLLLt L l *, i%1 i~ I'RTRTRTRTR~__~I" ~ [ ................... ~LBLBLSLBLBLSLSm~IR~~ i | t B LB LB i B LB LB L B LB L~I~BTB'YCRTRTRTRTRTRT~ i ! ~B LB LB L B LB LB LB LB L B I~W~TB TB?r/~TRTRTRTRT~ ! I ~LBLBLBLBLBLBLB LBL~L~TBTB~RTRTRTRT~ I : ~LBLBLBLBLBLBLBLBL~LB~';BTBTB~TRTRTII i ! 'tBLBLBLBLBLBLBLBL~LBLBh~BTBTBT~RTt i i ~BLBLBLBLBLBLBLBLt~LBLBLI~EP~TBTBT~p~ [ i ~LBLBLBLBLBLBLBL~LBLBLBLB~TBTBT~ L . . . . . . . . . . . . . . . . . . . . . i _ _ %--.~--B--L.B. L--B.L- B--L.B-Ir-B.L B--~.~ LB 5 BLB LB L 6~BTBTI~
FiS. 5 Subdivision oF the plane when P! is in a corner resion
I CS LB NLN 25.5 20 8
I 1.5 2 1 4.5 6 4
l 1.5 2 2 1.5 4 1
COMPARISONS +
/
CS LB NLN 21 20 7.5 1 2 1 3 6 3 1 2 1 1 4 1
CS LB NLN P1 i0 20 8 0 0 0 0 6 0 0 0 0 0 4 0
J
FIG.6 Analysis of the three algorithms when P1 is in the window
L
CS LB NLN 9.5 10.5 3.5 0 0 0 0 4 0 0 0 0 0 2.5 0
COMPARISONS +
/
/ /
/
CS LB / NLN i0 10.5 3.5 0 01 0 0 4 0 0 ,0 0 0 /2.5 0
/ / /_ - n
CS NLN F ~ .75 " NLN LB CS LB ~. 5 21 i~.75 ~.5 0 14.75 1 1 0 3 I/3 55 i/ CS LB NLN 32 /20 8.5 2/ 4 2 6 6 4 /~ 4 2
4 2
CS LB NLN 21 20 8 1 2 1 3 6 3 1 2 1 1 4 l
1 3.5 0
CS LB NLN 3b.5 20 g.5 2.5 4 2 7.5 6 5 2.5 4 3 2.5 4 2
CS LB NLN 32 20 8 2 4 2 6 6 4 2 4 2 2 4 2
FIG.7 Analysis of the three algorithms when P1 is in an edge region
"Further subdivision is needed. Average shown is for the largest unbounded subregion."
CS LB NLN 9 6 2.5 0 0 0 0 2.5 0 0 0 0 0 1.5 0
1 [ CS LB NLN CS LB NLN 9.5 10.5 3.75 9 10.5 3.75
~ 0 0 0 0 '-" -° °- ! I o o,o I \ \ o ~ o o o o \ \ 2.5 . 0 2.5 0
i i TM , ~s ~ ~ c~ \ 25.5 20 1 .75 \ 1.5\ 2 1 \ 4.5 "6 4 4.5 05.5
1.5 2\ 2 1-5 ~ 1.5 4 \ 1 1.5 3.5 ~ 0
CS LB NLN ~ CS LB NLN COMPARISONS 36.5 20 36.5 20 8
+ 2.5 4 2.5 4 2 7.5 6 7.5 6 5
* 2.5 4 2.5 4 3 / 2.5\4 2.5 4 2
CS LB NLN 41 20 i0 3 4 2 9 6 6 3 4 4 3 4 2
CS LB NLN 25 14.5 8 1.5 0 0 4.5 5.5 5 1.5 0 3 1.5 3.5 0
FIG.8 Analysis of the three algorithms when P1 is in a corner region
262
~ , ~ SIGGRAPH '87, Anaheim, July 27-31, 1987
[ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ~TL I I ' n_ ; I IXLTLTL 'n . .TL ' rLTL 'n . .T~ i /ll.TLTLTL1LTLTL'n.TLTUT.TLTLTi i ,mTLTLTL~TLTLTLTLTL~TL~T I i Z L ' n ' ~ TLT LT L ' n : n ' ~ ' n " m ' n ' ~ T L T I i .ZTLTL'II.TLTLTLI~TLTLTLTLTLTLIlTLTI i Z~LTLYLTLTLTLTLTLIITLTLTLrLrLTLYL~ i /~LTL'IIILTLTLTLTLI~TLIITLll;It 12-'~.9.~R] i . ~TLT~TLT~rcTLTL~TLTL~.~,rS.LRLRLR~ I :LTLTLTLTLTLTLTLTLTbllL.t~ . £ ~ R L R L R L R L R L~ . . . . . . . . . . . . . . . . . . . . . . i :." LLLLLLUJ/..LLI.J/ - RLELRLRLRLRLRLI~i.i~
! / LLLLE~I,~f~iLLLLLLLLI~ RLRLRLRLRLPJ-RLPJ- ~ / ..~-~-~u~u-uu~u-u~u~W~u~u~R u~-~
i P 1 -'-":- ......... ~LilJ ! r ! ! 7 ! ! LLLLLLLLI.IRLRLRLRLRLRLRLPd..RI i "~::7---.__ LU t t t t t u . .LLLLL RLRLRLRLRI.Pd..RLRLpj
~LB LB LBLB L B LBL B LB L~ L~ E~L~.L~LRL RL~ l "~BLBLBLBLBLBLBflBLBLB LBLBLB~
j "m~SLBLBLBLBLB~BLBLBLBLBLB LBLBLB] I | "%~BLBLBLBII~LBLB LBLBLBLBLBLHI
",d~LBLB[~BLBLBLBLBLBLBLBLB| ; "~Bb~LBLBLBLBLB LBLB LB
! I "N~BLBLBLBLBLBLBLBLB I ! [ "~'B'-LB LB L B LB LB L B LBI L .................... _/ ......................... Lm.__~__L. BLBLBLBLBLB~
Fi$. 4 Subdivision oF the plane when Pl is in an edse region
, i i , ' • • , i i ' • I I • I l i i Pl ! i i
! ::-. I ............. I i I • "..- ---.-- | - i . . . . . . . . . . . . . . . . . ~......- -- " - - - . . . . . . . . . . . . . . . . . . - - . I [ ~ $~J..l I I 1 I 1111 I 1 I I I I I 1 ~TI ' rT~. . .... I
i ~ [u.~;~.~ . . . . . . . . . . . hTRTRTRTRTR'm~ ! ~ LLLLLLU[~AI* l l t t i ~TRTRTR ' i~TR ' I~TRT~
i 5. I . L L L L D . U . J . I ~ [ i i ,. j., ~ t ,~RTRTRTRTRTRIRYRT~
! :[LLLLLLLLLLLLLt L l *, i%1 i~ I'RTRTRTRTR~__~I" ~ [ ................... ~LBLBLSLBLBLSLSm~IR~~ i | t B LB LB i B LB LB L B LB L~I~BTB'YCRTRTRTRTRTRT~ i ! ~B LB LB L B LB LB LB LB L B I~W~TB TB?r/~TRTRTRTRT~ ! I ~LBLBLBLBLBLBLB LBL~L~TBTB~RTRTRTRT~ I : ~LBLBLBLBLBLBLBLBL~LB~';BTBTB~TRTRTII i ! 'tBLBLBLBLBLBLBLBL~LBLBh~BTBTBT~RTt i i ~BLBLBLBLBLBLBLBLt~LBLBLI~EP~TBTBT~p~ [ i ~LBLBLBLBLBLBLBL~LBLBLBLB~TBTBT~ L . . . . . . . . . . . . . . . . . . . . . i _ _ %--.~--B--L.B. L--B.L- B--L.B-Ir-B.L B--~.~ LB 5 BLB LB L 6~BTBTI~
FiS. 5 Subdivision oF the plane when P! is in a corner resion
I CS LB NLN 25.5 20 8
I 1.5 2 1 4.5 6 4
l 1.5 2 2 1.5 4 1
COMPARISONS +
/
CS LB NLN 21 20 7.5 1 2 1 3 6 3 1 2 1 1 4 1
CS LB NLN P1 i0 20 8 0 0 0 0 6 0 0 0 0 0 4 0
J
FIG.6 Analysis of the three algorithms when P1 is in the window
L
CS LB NLN 9.5 10.5 3.5 0 0 0 0 4 0 0 0 0 0 2.5 0
COMPARISONS +
/
/ /
/
CS LB / NLN i0 10.5 3.5 0 01 0 0 4 0 0 ,0 0 0 /2.5 0
/ / /_ - n
CS NLN F ~ .75 " NLN LB CS LB ~. 5 21 i~.75 ~.5 0 14.75 1 1 0 3 I/3 55 i/ CS LB NLN 32 /20 8.5 2/ 4 2 6 6 4 /~ 4 2
4 2
CS LB NLN 21 20 8 1 2 1 3 6 3 1 2 1 1 4 l
1 3.5 0
CS LB NLN 3b.5 20 g.5 2.5 4 2 7.5 6 5 2.5 4 3 2.5 4 2
CS LB NLN 32 20 8 2 4 2 6 6 4 2 4 2 2 4 2
FIG.7 Analysis of the three algorithms when P1 is in an edge region
"Further subdivision is needed. Average shown is for the largest unbounded subregion."
CS LB NLN 9 6 2.5 0 0 0 0 2.5 0 0 0 0 0 1.5 0
1 [ CS LB NLN CS LB NLN 9.5 10.5 3.75 9 10.5 3.75
~ 0 0 0 0 '-" -° °- ! I o o,o I \ \ o ~ o o o o \ \ 2.5 . 0 2.5 0
i i TM , ~s ~ ~ c~ \ 25.5 20 1 .75 \ 1.5\ 2 1 \ 4.5 "6 4 4.5 05.5
1.5 2\ 2 1-5 ~ 1.5 4 \ 1 1.5 3.5 ~ 0
CS LB NLN ~ CS LB NLN COMPARISONS 36.5 20 36.5 20 8
+ 2.5 4 2.5 4 2 7.5 6 7.5 6 5
* 2.5 4 2.5 4 3 / 2.5\4 2.5 4 2
CS LB NLN 41 20 i0 3 4 2 9 6 6 3 4 4 3 4 2
CS LB NLN 25 14.5 8 1.5 0 0 4.5 5.5 5 1.5 0 3 1.5 3.5 0
FIG.8 Analysis of the three algorithms when P1 is in a corner region
262
~ , ~ SIGGRAPH '87, Anaheim, July 27-31, 1987
[ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ~TL I I ' n_ ; I IXLTLTL 'n . .TL ' rLTL 'n . .T~ i /ll.TLTLTL1LTLTL'n.TLTUT.TLTLTi i ,mTLTLTL~TLTLTLTLTL~TL~T I i Z L ' n ' ~ TLT LT L 'n : n ' ~ ' n " m ' n ' ~ TLT I i .ZTLTL'II.TLTLTLI~TLTLTLTLTLTLIlTLTI i Z~LTLYLTLTLTLTLTLIITLTLTLrLrLTLYL~ i /~LTL'IIILTLTLTLTLI~TLIITLll;It 12-'~.9.~R] i . ~TLT~TLT~rcTLTL~TLTL~.~,rS.LRLRLR~ I :LTLTLTLTLTLTLTLTLTbllL.t~ . £ ~ R L R L R L R L R L~ . . . . . . . . . . . . . . . . . . . . . . i :." LLLLLLUJ/..LLI.J/ - RLELRLRLRLRLRLI~i.i~
! / LLLLE~I,~f~iLLLLLLLLI~ RLRLRLRLRLPJ-RLPJ- ~ / ..~-~-~u~u-uu~u-u~u~W~u~u~R u~-~
i P 1 -'-":- ......... ~LilJ ! r ! ! 7 ! ! LLLLLLLLI.IRLRLRLRLRLRLRLPd..RI i "~::7---.__ LU t t t t t u . .LLLLL RLRLRLRLRI.Pd..RLRLpj
~LB LB LBLB L B LBL B LB L~ L~ E~L~.L~LRL RL~ l "~BLBLBLBLBLBLBflBLBLB LBLBLB~
j "m~SLBLBLBLBLB~BLBLBLBLBLB LBLBLB] I | "%~BLBLBLBII~LBLB LBLBLBLBLBLHI
",d~LBLB[~BLBLBLBLBLBLBLBLB| ; "~Bb~LBLBLBLBLB LBLB LB
! I "N~BLBLBLBLBLBLBLBLB I ! [ "~'B'-LB LB L B LB LB L B LBI L .................... _/ ......................... Lm.__~__L. BLBLBLBLBLB~
Fi$. 4 Subdivision oF the plane when Pl is in an edse region
, i i , ' • • , i i ' • I I • I l i i Pl ! i i
! ::-. I ............. I i I • "..- ---.-- | - i . . . . . . . . . . . . . . . . . ~......- -- " - - - . . . . . . . . . . . . . . . . . . - - . I [ ~ $~J..l I I 1 I 1111 I 1 I I I I I 1 ~TI ' rT~. . .... I
i ~ [u.~;~.~ . . . . . . . . . . . hTRTRTRTRTR'm~ ! ~ LLLLLLU[~AI* l l t t i ~TRTRTR ' i~TR ' I~TRT~
i 5. I . L L L L D . U . J . I ~ [ i i ,. j., ~ t ,~RTRTRTRTRTRIRYRT~
! :[LLLLLLLLLLLLLt L l *, i%1 i~ I'RTRTRTRTR~__~I" ~ [ ................... ~LBLBLSLBLBLSLSm~IR~~ i | t B LB LB i B LB LB L B LB L~I~BTB'YCRTRTRTRTRTRT~ i ! ~B LB LB L B LB LB LB LB L B I~W~TB TB?r/~TRTRTRTRT~ ! I ~LBLBLBLBLBLBLB LBL~L~TBTB~RTRTRTRT~ I : ~LBLBLBLBLBLBLBLBL~LB~';BTBTB~TRTRTII i ! 'tBLBLBLBLBLBLBLBL~LBLBh~BTBTBT~RTt i i ~BLBLBLBLBLBLBLBLt~LBLBLI~EP~TBTBT~p~ [ i ~LBLBLBLBLBLBLBL~LBLBLBLB~TBTBT~ L . . . . . . . . . . . . . . . . . . . . . i _ _ %--.~--B--L.B. L--B.L- B--L.B-Ir-B.L B--~.~ LB 5 BLB LB L 6~BTBTI~
FiS. 5 Subdivision oF the plane when P! is in a corner resion
I CS LB NLN 25.5 20 8
I 1.5 2 1 4.5 6 4
l 1.5 2 2 1.5 4 1
COMPARISONS +
/
CS LB NLN 21 20 7.5 1 2 1 3 6 3 1 2 1 1 4 1
CS LB NLN P1 i0 20 8 0 0 0 0 6 0 0 0 0 0 4 0
J
FIG.6 Analysis of the three algorithms when P1 is in the window
L
CS LB NLN 9.5 10.5 3.5 0 0 0 0 4 0 0 0 0 0 2.5 0
COMPARISONS +
/
/ /
/
CS LB / NLN i0 10.5 3.5 0 01 0 0 4 0 0 ,0 0 0 /2.5 0
/ / /_ - n
CS NLN F ~ .75 " NLN LB CS LB ~. 5 21 i~.75 ~.5 0 14.75 1 1 0 3 I/3 55 i/ CS LB NLN 32 /20 8.5 2/ 4 2 6 6 4 /~ 4 2
4 2
CS LB NLN 21 20 8 1 2 1 3 6 3 1 2 1 1 4 l
1 3.5 0
CS LB NLN 3b.5 20 g.5 2.5 4 2 7.5 6 5 2.5 4 3 2.5 4 2
CS LB NLN 32 20 8 2 4 2 6 6 4 2 4 2 2 4 2
FIG.7 Analysis of the three algorithms when P1 is in an edge region
"Further subdivision is needed. Average shown is for the largest unbounded subregion."
CS LB NLN 9 6 2.5 0 0 0 0 2.5 0 0 0 0 0 1.5 0
1 [ CS LB NLN CS LB NLN 9.5 10.5 3.75 9 10.5 3.75
~ 0 0 0 0 '-" -° °- ! I o o,o I \ \ o ~ o o o o \ \ 2.5 . 0 2.5 0
i i TM , ~s ~ ~ c~ \ 25.5 20 1 .75 \ 1.5\ 2 1 \ 4.5 "6 4 4.5 05.5
1.5 2\ 2 1-5 ~ 1.5 4 \ 1 1.5 3.5 ~ 0
CS LB NLN ~ CS LB NLN COMPARISONS 36.5 20 36.5 20 8
+ 2.5 4 2.5 4 2 7.5 6 7.5 6 5
* 2.5 4 2.5 4 3 / 2.5\4 2.5 4 2
CS LB NLN 41 20 i0 3 4 2 9 6 6 3 4 4 3 4 2
CS LB NLN 25 14.5 8 1.5 0 0 4.5 5.5 5 1.5 0 3 1.5 3.5 0
FIG.8 Analysis of the three algorithms when P1 is in a corner region
262