Graphics Reference
In-Depth Information
if denom < 0
then
begin { line from outside to inside }
r := num/denom;
if r > t1
then more := false
else if r > t0 then t0 := r;
end
else if denom > 0
then
{ line from inside to outside }
begin
r := num/denom;
if r < t0
then more := false
else if r < t1 then t1 := r;
end
else if num < 0 { line parallel to boundary }
then more := false ;
end ; { Findt }
Algorithm 3.2.3.2. Continued
Figure 3.6.
Liang-Barsky line-clipping example.
3.2.3.2 Example. Consider the segment [ P 1 , P 2 ] in Figure 3.7. In this example, c 1 ,
c 3 < 0 and c 2 , c 4 > 0, so that t 1 and t 3 are entry values and t 2 and t 4 are exit values.
Furthermore, t 1 < 0 < t 3 < 1 < t 2 < t 4 . This time we cannot reject the segment and must
compute t0 = max (0, c 1 , c 3 ) = c 3 and t1 = min (1, c 2 , c 4 ) = 1. The algorithm tells us
that we must clip the segment at the P 1 end to get Q but do not need to clip at the P 2
end. Again this is clearly what had to be done.
In conclusion, the advantage of the Liang-Barsky algorithm over the Cohen-
Sutherland algorithm is that it involves less arithmetic and is therefore faster. It needs
only two subtractions to get q k and c k and then one division.
Search WWH ::




Custom Search