Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm (3d) max min max min y y y x x x s s s s For a point (x,y) to be inside the clip rectangle: (x min , y min ) (x max , y max ) x = x min x = x max y = y min y = y max clip rectangle Point Clipping (x min , y min ) (x max , y max ) x = x min x = x max y = y min y = y max (x 1 , y 1 ) clip rectangle max min max min y y y x x x s s s s For a point (x,y) to be inside the clip rectangle: Point Clipping clip rectangle Cases for clipping lines Line Clipping Cases for clipping lines A B A B clip rectangle Line Clipping Cases for clipping lines D A B C D' A B C D' clip rectangle Line Clipping Cases for clipping lines D E F A B C D' A B C D' clip rectangle Line Clipping Cases for clipping lines D E F A B C D' G H G' H' A B C D' G' H' clip rectangle Line Clipping Cases for clipping lines D E F A B C D' G H G' H' I J I' J' A B C D' G' H' clip rectangle Line Clipping Clipping Lines by Solving Simultaneous Equations clip rectangle (x a , y a ) (x b , y b ) (x c , y c ) (x d , y d ) (x 0 , y 0 ) (x 1 , y 1 ) (x, y) clip rectangle (x a , y a ) (x b , y b ) (x c , y c ) (x d , y d ) (x 0 , y 0 ) (x 1 , y 1 ) (x, y) ( ) ( ) ( ) ( ) a b edge a a b edge a line line y y t y y x x t x x y y t y y x x t x x + = + = + = + = , , 0 1 0 0 1 0 Line Clipping The Cohen-Sutherland Line-Clipping Algorithm performs initial tests on a line to determine whether intersection calculations can be avoided. 1. First, end-point pairs are checked for Trivial Acceptance. 2. If the line cannot be trivially accepted, region checks are done for Trivial Rejection. 3. If the line segment can be neither trivially accepted or rejected, it is divided into two segments at a clip edge, so that one segment can be trivially rejected. These three steps are performed iteratively until what remains can be trivially accepted or rejected. Cohen-Sutherland Algorithm 0000 1000 0100 1001 1010 0001 0010 0101 0110 clip rectangle Region outcodes min max y y y y < > : 1 bit : 0 bit min max x x x x < > : 3 bit : 2 bit Cohen-Sutherland Algorithm 1. A line segment can be trivially accepted if the outcodes of both the endpoints are zero. 2. A line segment can be trivially rejected if the logical AND of the outcodes of the endpoints is not zero. 3. A key property of the outcode is that bits that are set in nonzero outcode correspond to edges crossed.
Cohen-Sutherland Algorithm clip rectangle A B C D E An Example Cohen-Sutherland Algorithm An Example clip rectangle B C D E Cohen-Sutherland Algorithm An Example clip rectangle B C D Cohen-Sutherland Algorithm An Example clip rectangle B C Cohen-Sutherland Algorithm (1) This fundamentally different (from Cohen- Sutherland algorithm) and generally more efficient algorithm was originally published by Cyrus and Beck. (2) Liang and Barsky later independently developed a more efficient algorithm that is especially fast in the special cases of upright 2D and 3D clipping regions.They also introduced more efficient trivial rejection tests for general clip regions. Parametric Line-Clipping Inside of clip rectangle Outside of clip region ( ) | | 0 > i E i P t P N ( ) | | 0 = i E i P t P N ( ) | | 0 < i E i P t P N ( ) i E i P t P i E P 0 P 1 P i N i E Edge ( ) ( )t P P P t P P P Line 0 1 0 1 0 : + = ( ) | | ( ) | | ( ) | | | | ( ) | | 1 0 0 1 0 0 0 1 0 0 1 0 , 0 0 0 P P D D N P P N t P P N P P N t P t P P P N P t P P P N P t P N i E i i E i E i E i E i i i i i i =
=
= = + = + = The Cyrus-Back Algorithm Inside of clip rectangle Outside of clip region ( ) | | 0 > i E i P t P N ( ) | | 0 = i E i P t P N ( ) | | 0 < i E i P t P N ( ) i E i P t P i E P 0 P 1 P i N i E Edge | | D N P P N t i E i i
= 0 ( ) ( ) ( ) 0 3 0 2 0 1 when exists 1 0 = = = = D N P P D N t i i The Cyrus-Back Algorithm PE PL P 0 P 1 t = 0 t = 1 PE PL P 1 t = 1 P 0 t = 0 PE PE PL PL P 0 t = 0 P 1 t = 1 Line 2 Line 1 Line 3 Clip rectangle > < 90 0 Angle PE D N i < > 90 0 Angle PL D N i PE = Potentially Entering PL = Potentially Leaving The Cyrus-Back Algorithm The Cyrus-Back Algorithm Precalculate N i and P Ei for each edge for (each line segment to be clipped) { if (P 1 == P 0 ) line is degenerated, so clip as a point; else { t E = 0; t L = 1; for (each candidate intersection with a clip edge) { if (N i D != 0) { /* Ignore edges parallel to line */ calculate t; use sign of N i D to categorize as PE or PL; if (PE) t E = max(t E , t); if (PL) t L = min(t L , t); } } if (t E > t L ) return NULL; else return P(t E ) and P(t L ) as true clip intersection;
} } Example Polygon Clipping Example Polygon Clipping Example Polygon Clipping Initial Condition Sutherland-Hodgeman Algo. Clip Against Right Clipping Boundary Clip Against Top Clipping Boundary The Clipped Polygon Clip Against Bottom Clipping Boundary Clip Against Left Clipping Boundary Case 1 Inside Outside Polygon being clipped Clip boundary s p:output 4 Cases of Polygon Clipping Case 2 Inside Outside s p i:output Case 3 Inside Outside s p (no output) Case 4 Inside Outside s i:first output p:second output Algorithm Input vertex P First Point Yes No F=P Does SPintersect E? No Yes Compute Intersection Point I Output vertex I S=P Is S on lef t side of E? Exit NO Yes Output vertex S Close Polygon entry Does SF intersect E? Compute Intersection I Yes Output vertex I Exit No 3D Clipping Both the Cohen-Sutherland and Cyrus-Beck clipping algorithm readily extend to 3D. For Cohen-Sutherland algorithm use two extra-bit in outcode for incorporating z < z min and z > z max regions Thank You
Ten-Decimal Tables of the Logarithms of Complex Numbers and for the Transformation from Cartesian to Polar Coordinates: Volume 33 in Mathematical Tables Series