11.11.2014 Views

Clipping and Hidden Surfaces Clipping Basic Line Clipping Cohen ...

Clipping and Hidden Surfaces Clipping Basic Line Clipping Cohen ...

Clipping and Hidden Surfaces Clipping Basic Line Clipping Cohen ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Cohen</strong>-Sutherl<strong>and</strong> <strong>Line</strong> Clip<br />

• Out codes<br />

1 2<br />

0010<br />

3<br />

4<br />

0101<br />

Liang-Barsky <strong>Clipping</strong><br />

• Parametric clipping - view line in parametric<br />

form <strong>and</strong> reason about the parameter values<br />

• More efficient, as not computing the coordinate<br />

values at irrelevant vertices<br />

• Works for rectilinear clip regions in 2D or 3D<br />

• <strong>Clipping</strong> conditions on parameter: <strong>Line</strong> is inside<br />

clip region for values of t such that (for 2D):<br />

x<br />

y<br />

min<br />

min<br />

≤x1<br />

+ t∆x<br />

≤x<br />

≤ y + t∆y<br />

≤ y<br />

1<br />

max<br />

max<br />

∆x<br />

= x2<br />

−x1<br />

∆y<br />

= y −y<br />

2<br />

1<br />

7<br />

8<br />

Liang-Barsky <strong>Clipping</strong><br />

Liang-Barsky <strong>Clipping</strong><br />

• Infinite line intersects clip region edges at:<br />

qk<br />

t<br />

k<br />

=<br />

p<br />

k<br />

where<br />

p 1<br />

= −∆x<br />

q 1<br />

= x 1<br />

− x min<br />

p 2 = ∆x q 2 = x max − x 1<br />

p 3<br />

= −∆y q 3<br />

= y 1<br />

− y min<br />

p 4 = ∆y q 4 = y max − y 1<br />

• When p k 0, line goes from inside to outside – leaving<br />

• When p k =0, line is parallel to an edge (clipping is easy)<br />

• If there is a segment of the line inside the clip region,<br />

sequence of infinite line intersections must go: enter,<br />

enter, leave, leave<br />

Note: Left edge is 1, right edge is 2, top edge is 3, bottom is 4<br />

9<br />

10<br />

Liang-Barsky <strong>Clipping</strong><br />

Liang-Barsky <strong>Clipping</strong><br />

• Compute entering t values, which are q k /p k for each p k 0<br />

• Parameter value for small t end of line is:t small = max(0, entering<br />

t’s)<br />

• parameter value for large t end of line is: t large =min(1, leaving t’s)<br />

Enter<br />

• if t small

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!