next up previous
Next: Geometries Up: Clipping Previous: Clipping

Point and Line Clipping

Clipping:
Remove points outside a region of interest.

Point clipping:
Remove points outside window.
Line clipping:
Remove portion of line segment outside window.

Parametric representation of line:

or equivalently

Implicit representation of line:

\

Clipping a point to a halfspace:

Clipping a line segment to a halfspace:

There are three cases:
  1. The line segment is entirely inside:
    Keep it.
  2. The line segment is entirely outside:
    Discard it.
  3. The line segment is partially inside and partially outside:
    Generate new line to represent part inside.

\

Input Specification:

Do the easy stuff first:

We can devise easy (and fast!) tests for the first two cases: Need to decide: are boundary points inside or outside?
Trivial tests
are important in computer graphics:

Do the hard stuff only if we have to:

If line segment partially inside and partially outside, need to clip it:

Clipping a line segment to a window:

Just clip to each of four halfspaces in turn.
Pseudo-code:
	Given line segment (A,B), clip in-place:
	for each edge (P,n)
	    wecA = (A-P) . n
	    wecB = (B-P) . n
	    if ( wecA < 0 AND wecB < 0 ) then reject
	    if ( wecA > 0 AND wecB > 0 ) then next
	    t = wecA / (wecA - wecB)
	    if ( wecA < 0 ) then 
	        A = A + t*(B-A)
	    else
	        B = A + t*(B-A)
	    endif
	endfor

Note:
Question:  
Should we clip before or after window-to-viewport mapping?

Line-clip Algorithm generalizes to 3D:

Reading: Hearn and Baker, Sections 6-5 through 6-7, Red book: 3.9, White Book: 3.11, Blinn: 13.


next up previous
Next: Geometries Up: Clipping Previous: Clipping

CS488/688: Introduction to Interactive Computer Graphics
University of Waterloo
Computer Graphics Lab

cs488@cgl.uwaterloo.ca