Line Clipping w A line clipping procedure involves

  • Slides: 21
Download presentation
Line Clipping w A line clipping procedure involves several parts. If the given line

Line Clipping w A line clipping procedure involves several parts. If the given line segment lies 1 - completely inside the clipping window - Save 2 - completely outside the window - Discard. 3 - Partially (inside and outside) – find the intersection points. 1

The Cases w Case 1: both endpoints of line segment inside all four lines

The Cases w Case 1: both endpoints of line segment inside all four lines – Draw (accept) line segment as is y = ymax x = xmin x = xmax y = ymin w Case 2: both endpoints outside all lines and on same side of a line – Discard (reject) the line segment 2

The Cases w Case 3: One endpoint inside, one outside – Must do at

The Cases w Case 3: One endpoint inside, one outside – Must do at least one intersection w Case 4: Both outside – May have part inside – Must do at least one intersection y = ymax x = xmin x = xmax 3

Line Clipping w Possible relationships between line positions and a standard rectangular clipping region

Line Clipping w Possible relationships between line positions and a standard rectangular clipping region 2 1 3 3 Before clipping after clipping 4

Line Clipping w Parametric representation of a line x = x 1 + u(x

Line Clipping w Parametric representation of a line x = x 1 + u(x 2 - x 1) y = y 1 + u(y 2 - y 1) w The value of u for an intersection with a rectangle boundary edge – Outside the range 0 to 1 – line does not enter the interior of the window. – Within the range from 0 to 1 – cross the clipping area. 5

Line Clipping w 3 line clipping algorithms : w 1. Cohen-Sutherland Line Clipping w

Line Clipping w 3 line clipping algorithms : w 1. Cohen-Sutherland Line Clipping w 2. Liang – Barsky line Clipping w 3. Nicholl-Lee-Nicholl Line clipping 6

Cohen-Sutherland Line Clipping w Region code – A four-digit binary code assigned to every

Cohen-Sutherland Line Clipping w Region code – A four-digit binary code assigned to every line endpoint in a picture. BIT 4 BIT 3 BIT 2 BIT 1 4 3 2 above below right 1 left Region Code Legend 7

Cohen-Sutherland Line Clipping w Check for visibility of line P 1 P 2 -

Cohen-Sutherland Line Clipping w Check for visibility of line P 1 P 2 - If region codes for both endpoints P 1 and P 2 are zero then the line is completely visible. Hence draw the line. - If region codes for endpoints are not zero and the logical Anding of them is also nonzero then the line is completely invisible, so reject the line. - If region codes for two end point do not satisfy the above conditions the line is 8 partially visible.

Cohen-Sutherland Line Clipping w The possible relationships: • Completely contained within the window •

Cohen-Sutherland Line Clipping w The possible relationships: • Completely contained within the window • 0000 for both endpoints. • Completely outside the window • Logical and the region codes of both endpoints, its result is not 0000. • Partially 9

Cohen-Sutherland Line Clipping w Intersection points for a line with endpoint coordinates (x 1,

Cohen-Sutherland Line Clipping w Intersection points for a line with endpoint coordinates (x 1, y 1) and (x 2, y 2) is given as y =y 1 +m (x-x 1) w slope of line is calculated as m = (y 2 - y 1) / (x 2 - x 1) w the intersection of the x coordinate can be calculated as x= x 1 +( y- y 1) / m 10

Liang-Barsky Line Clipping w Consider the parametric definition of a line: x = x

Liang-Barsky Line Clipping w Consider the parametric definition of a line: x = x 1 + u∆x y = y 1 + u∆y ∆x = (x 2 - x 1), ∆y = (y 2 - y 1),

Liang-Barsky Line Clipping w The parameters p & q are defined as w p

Liang-Barsky Line Clipping w The parameters p & q are defined as w p 1 = -∆x w p 2 = ∆x w P 3= -∆y w P 4= ∆y q 1= x 1 - xwmin q 2= xwmax - x 1 q 3= y 1 - ywmin q 4= ywmax - y 1

Liang-Barsky Line Clipping w Cases: 1. pk = 0 • Line is parallel to

Liang-Barsky Line Clipping w Cases: 1. pk = 0 • Line is parallel to boundaries – If for the same k, qk < 0, reject – Else, accept 2. pk < 0 • Line starts outside this boundary • rk = qk / pk • u 1 = max(0, rk, u 1)

Liang-Barsky Line Clipping w Cases: 3. pk > 0 • Line starts outside this

Liang-Barsky Line Clipping w Cases: 3. pk > 0 • Line starts outside this boundary • rk = qk / pk • u 2 = min(1, rk, u 2) 4. If u 1 > u 2, the line is completely outside and it can be rejected.

Liang-Barsky Line Clipping 5. If u 1 < u 2, calculate the end points

Liang-Barsky Line Clipping 5. If u 1 < u 2, calculate the end points as x x 1 = x 1 + u 1 ∆x y y 1 = y 1 + u 1 ∆y And x x 2 = x 1 + u 2 ∆x y y 2 = y 1 + u 2 ∆y

Nicholl-Lee-Nicholl Line Clipping 16

Nicholl-Lee-Nicholl Line Clipping 16

Nicholl-Lee-Nicholl Line Clipping Partition the region based on the first point (p 1): –

Nicholl-Lee-Nicholl Line Clipping Partition the region based on the first point (p 1): – Case 1: p 1 inside region – Case 2: p 1 across edge – Case 3: p 1 across corner

Nicholl-Lee-Nicholl Line Clipping Case 1 Case 2 T LT L p 1 R L

Nicholl-Lee-Nicholl Line Clipping Case 1 Case 2 T LT L p 1 R L L LR LB B p 1 Case 3 L T LB T TB TR 18

Nicholl-Lee-Nicholl Line Clipping 19

Nicholl-Lee-Nicholl Line Clipping 19

Nicholl-Lee-Nicholl Line Clipping 20

Nicholl-Lee-Nicholl Line Clipping 20

Nicholl-Lee-Nicholl Line Clipping 21

Nicholl-Lee-Nicholl Line Clipping 21