S.Rajapriya
Assistant Professor, Dept. of IT
V.V.Vanniaperumal College for Women
Clipping
• Clipping
Clipping is a procedure that identifies those portions
of a picture that are either inside or outside of a specified
region of space.
• Clip Window
A region against which a object is to be clipped.
• It may be a polygon or a curved boundaries. But
rectangular clip window is preferred.
• In clipping, picture parts within window area are
displayed. Everything outside the window area are
discarded.
Types of Clipping
Based on different output primitives :-
Point Clipping
Line Clipping
Polygon Clipping
Curve Clipping
Text Clipping
Exterior Clipping
Line Clipping
Cohen-Sutherland Line Clipping
Liang-Barsky Line Clipping
NLN(Nicholl-Lee-Nicholl) Line Clipping
Line Clipping Using Nonrectangular Clip Windows
Splitting Concave Polygons
Line Clipping Procedure
A line clipping procedure involves several parts:
1.Test a given line segment to determine whether it lies
completely inside the clipping window.
2.Determine whether it lies completely outside the
clipping window
3.If not 1 & 2, perform intersection calculations with one
or more clipping boundaries.
•A line with both endpoints inside all clipping boundaries
is saved.
•A line with both endpoints outside any one of the clipping
boundaries is discarded.
•Other lines cross one or more clipping boundaries &
require calculation of multiple intersection points.
Example
Before Clipping After Clipping
• Line P1P2 is visible because both
endpoints lies inside the boundary.
• Line P5P6 is invisible because both
endpoints are completely outside the
window.
• Line P3P4 &P7P8 are partially visible.
P2
P5
P6
P3
P4
P7
P8
P1
P2
P1
P7
P8
P3
P4
Cohen-Sutherland Line
Clipping
 This is one of the oldest and most popular line clipping
algorithm.
 It reduces the number of intersections that must be
calculated by performing initial tests & speeds up
processing.
 Every line endpoint in a picture is assigned a 4-digit
binary code called region code.
 Region code identifies the location of the point relative to
the boundaries of the clipping rectangle.
Cohen-Sutherland Line
Clipping
Top EdgeLeft Edge
Bottom Edge Right Edge
1st bit (left most) => is set to 1 if end point
is above the top edge of the window
 2nd bit => is set to 1 if end point is below
the bottom edge of the window
 3rd bit => is set to 1 if end point is right of
the right edge of the window
 4th bit => is set to 1 if end point is left of
the left edge of the window
Cohen-Sutherland Example
Consider the line P9 to P10 below
 Start at P10
 From the region codes of the two
end-points we know the line doesn’t
cross the left or right boundary
 Calculate the intersection of the line
with the bottom boundary to generate
point P10’
 The line P9 to P10’ is completely inside the window so is retained
wymax
wymin
wxmin wxmax
Window
P10 [0100]
P9 [0000]
P10’ [0000]
P9 [0000]
Cohen-Sutherland Example
Consider the line P7 to P8 below
 Start at P7
 From the two region codes of the two
end-points we know the line crosses the
left boundary so calculate the intersection
point to generate P7’
Consider the line P7’ to P8
 Start at P8
 Calculate the intersection with the right
boundary to generate P8’
 P7’ to P8’ is inside the window so is retained
wymax
wymin
wxmin wxmax
Window
P7’ [0000]
P7 [0001] P8 [0010]
P8’ [0000]
Calculating Line Intersections
Intersection points with the window boundaries are calculated using the line-
equation parameters
Consider a line with the end-points (x1, y1) and (x2, y2)
 The y-coordinate of an intersection with a vertical window boundary can
be calculated using:
y = y1 + m (xboundary - x1)
where xboundary can be set to either wxmin or wxmax
 The x-coordinate of an intersection with a horizontal window boundary
can be calculated using:
x = x1 + (yboundary - y1) / m
where yboundary can be set to either wymin or wymax
 m is the slope of the line in question and can be calculated as
m = (y2 - y1) / (x2 - x1)
Clipping

Clipping

  • 1.
    S.Rajapriya Assistant Professor, Dept.of IT V.V.Vanniaperumal College for Women
  • 2.
    Clipping • Clipping Clipping isa procedure that identifies those portions of a picture that are either inside or outside of a specified region of space. • Clip Window A region against which a object is to be clipped. • It may be a polygon or a curved boundaries. But rectangular clip window is preferred. • In clipping, picture parts within window area are displayed. Everything outside the window area are discarded.
  • 3.
    Types of Clipping Basedon different output primitives :- Point Clipping Line Clipping Polygon Clipping Curve Clipping Text Clipping Exterior Clipping
  • 4.
    Line Clipping Cohen-Sutherland LineClipping Liang-Barsky Line Clipping NLN(Nicholl-Lee-Nicholl) Line Clipping Line Clipping Using Nonrectangular Clip Windows Splitting Concave Polygons
  • 5.
    Line Clipping Procedure Aline clipping procedure involves several parts: 1.Test a given line segment to determine whether it lies completely inside the clipping window. 2.Determine whether it lies completely outside the clipping window 3.If not 1 & 2, perform intersection calculations with one or more clipping boundaries. •A line with both endpoints inside all clipping boundaries is saved. •A line with both endpoints outside any one of the clipping boundaries is discarded. •Other lines cross one or more clipping boundaries & require calculation of multiple intersection points.
  • 6.
    Example Before Clipping AfterClipping • Line P1P2 is visible because both endpoints lies inside the boundary. • Line P5P6 is invisible because both endpoints are completely outside the window. • Line P3P4 &P7P8 are partially visible. P2 P5 P6 P3 P4 P7 P8 P1 P2 P1 P7 P8 P3 P4
  • 7.
    Cohen-Sutherland Line Clipping  Thisis one of the oldest and most popular line clipping algorithm.  It reduces the number of intersections that must be calculated by performing initial tests & speeds up processing.  Every line endpoint in a picture is assigned a 4-digit binary code called region code.  Region code identifies the location of the point relative to the boundaries of the clipping rectangle.
  • 8.
    Cohen-Sutherland Line Clipping Top EdgeLeftEdge Bottom Edge Right Edge 1st bit (left most) => is set to 1 if end point is above the top edge of the window  2nd bit => is set to 1 if end point is below the bottom edge of the window  3rd bit => is set to 1 if end point is right of the right edge of the window  4th bit => is set to 1 if end point is left of the left edge of the window
  • 9.
    Cohen-Sutherland Example Consider theline P9 to P10 below  Start at P10  From the region codes of the two end-points we know the line doesn’t cross the left or right boundary  Calculate the intersection of the line with the bottom boundary to generate point P10’  The line P9 to P10’ is completely inside the window so is retained wymax wymin wxmin wxmax Window P10 [0100] P9 [0000] P10’ [0000] P9 [0000]
  • 10.
    Cohen-Sutherland Example Consider theline P7 to P8 below  Start at P7  From the two region codes of the two end-points we know the line crosses the left boundary so calculate the intersection point to generate P7’ Consider the line P7’ to P8  Start at P8  Calculate the intersection with the right boundary to generate P8’  P7’ to P8’ is inside the window so is retained wymax wymin wxmin wxmax Window P7’ [0000] P7 [0001] P8 [0010] P8’ [0000]
  • 11.
    Calculating Line Intersections Intersectionpoints with the window boundaries are calculated using the line- equation parameters Consider a line with the end-points (x1, y1) and (x2, y2)  The y-coordinate of an intersection with a vertical window boundary can be calculated using: y = y1 + m (xboundary - x1) where xboundary can be set to either wxmin or wxmax  The x-coordinate of an intersection with a horizontal window boundary can be calculated using: x = x1 + (yboundary - y1) / m where yboundary can be set to either wymin or wymax  m is the slope of the line in question and can be calculated as m = (y2 - y1) / (x2 - x1)