UNIT 2
POINT AND LINE CLIPPING
WINDOWING AND CLIPPING
 The world coordinate system is used to define the
position of objects in the natural world.
 This system does not depend on the screen
coordinate system, so the interval of number can be
anything (positive, negative or decimal).
 Sometimes the complete picture of object in the
world coordinate system is too large and complicate
to clearly show on the screen, and we need to show
only some part of the object.
 The capability that show some part of object in a
specified window is called windowing and a
rectangular region in a world coordinate system is
called window.
 A Window is a rectangular region in the world
coordinate system.
 This is the coordinate system used to locate an
object in the natural world.
 A Viewport is the section of the screen where the
images encompassed by the window on the world
coordinate system will be drawn.
 A coordinate transformation is required to display
the image, encompassed by the window, in the
viewport.
 The viewport uses the screen coordinate system so
this transformation is from the world coordinate
system to the screen coordinate system.
 When a window is "placed" on the world, only
certain objects and parts of objects can be seen.
 Points and lines which are outside the window are
"cut off" from view.
 This process of "cutting off" parts of the image of
the world is called Clipping.
 In clipping, we examine each line to determine
whether or not it is completely inside the window,
completely outside the window, or crosses a
window boundary.
 If inside the window, the line is displayed. If outside
the window, the lines and points are not displayed.
 If a line crosses the boundary, we must determine
the point of intersection and display only the part
which lies inside the window.
POINT CLIPPING
 Suppose (x,y) is a point coordinate and (Xmin,
Xmax, Ymin, Ymax) are the coordinates for window.
 If (x,y) lies inside the window
then Xmin <= x <= Xmax
Ymin<=y<=Ymax must be true.
LINE CLIPPING
COHEN SUTHERLAND LINE CLIPPING
ALGORITHM (BASED ON REGION CODES)
BIT NUMBER 1 0
 First Step: Determine the bit values of the two end-
points of the line to be clipped.
 To determine the bit value of any point,
use: b1= sign(Ymax -Y);
b2= sign(Y -Ymin);
b3= sign(Xmax -X);
b4= sign(X -Xmin);
 Use these end-point codes to locate the line.
 Various possibilities:
 If both endpoint codes are [0000], the line lies
completely inside the box, no need to clip. This is
the simplest case (e.g. L1).
 Any line has 1 in the same bit positions of both the
endpoints, it is guaranteed to lie outside the box
(e.g. L2 and L3).
 Neither completely reject nor inside the box: Lines:
L4 and L5 –needs more processing.
 What about Line L6?
 Processing of lines, neither completely IN or OUT;
e.g. Lines: L4, L5 and L6.
 Basic idea: Clip parts of the line in any order
(consider from top or bottom)
 Algorithm Steps: Compute outcodes of both
endpoints to check for trivial acceptance or
rejection
 If not so, obtain an endpoint that lies outside the
box (atleast one will?)
 Using the outcode, obtain the edge that is crossed
first.
OBTAIN CORRESPONDING INTERSECTION
POINTS
 CLIP (replace the endpoint by the intersection
point) w.r.t. the edge.
 Compute the outcode for the updated end point and
repeat the iteration, till it is 0000.
 Repeat the above steps, if the other endpoint is
also outside the area.
 e.g. Take Line L5 (endpoints-E and I): E has
outcode 0100 (to be clipped w.r.t. bottom edge);
 So EI is clipped to FI; Outcode of F is 0000; But
outcode of I is 1010;
 Clip(w.r.t.top edge) to get FH.
 Outcode of H is 0010; Clip(w.r.t.right edge) to get
FG;
 Since outcode of G is 0000, display the final result
as FG
FORMULAS FOR CLIPPING W.R.T. EDGE, IN
CASES OF:
ALGORITHM
 Step 1: Given a line segment with endpoint P1=(x1,y1)
and P2= (x2,y2)
 Step 2: Compute the 4-bit codes for each endpoint.
If both codes are 0000,(bitwise OR of the codes
yields 0000 ) line lies completely inside the window: pass
the endpoints to the draw routine.
If both codes have a 1 in the same bit position
(bitwise AND of the codes is not 0000), the line lies outside
the window. It can be trivially rejected.
 Step 3: If a line cannot be trivially accepted or rejected,
at least one of the two endpoints must lie outside the
window and the line segment crosses a window edge.
This line must be clipped at the window edge before
being passed to the drawing routine.
 Step 4: Examine one of the endpoints, say
P1=(x1,y1). Read P1's 4-bit code in order: Left-to-
Right.
 Step 5: When a set bit (1) is found, compute the
intersection I of the corresponding window edge
with the line from P1 to P2. Replace with I and
repeat the algorithm.
QUESTIONS
1) Use the Cohen Sutherland algorithm to clip line
P1(10,20) , P2(100,10) against a window. Lower left
corner (50,10) & upper right hand corner (80,40).
2) Consider a window bounded by a lines Xmin=0,
Ymin=0, Xmax=5, Ymax=3. At what points a line
segment joining (-1,0) and (4,5) will connect the
window. (Apply Cohen Sutherland algorithm)
QUESTIONS
LIANG BARSKY LINE CLIPPING ALGORITHM (BASED
ON PARAMETRIC EQUATIONS)
 Consider parametric equation of a line segment:
 A point is considered to be within a rectangle, iff
 Each of these four inequalities, can be expressed
as:
 where, the parameters are defined as:
 Based on these four inequalities, we can find the
following conditions of line clipping:
 If pk = 0, the line is parallel to the corresponding
clipping boundary:
 K =1 -> Left
 K =2 -> Right
 K =3 -> Bottom
 K =4 -> Top
 If for any k, for which pk= 0:
 qk < 0, the line is completely outside the boundary
 qk >=0, the line is on or inside the parallel clipping
boundary.
 If pk < 0, the line proceeds from the outside to the
inside of the particular clipping boundary
 If pk > 0, the line proceeds from the inside to the
outside of the particular clipping boundary
 In both these cases, the intersection parameter is
calculated as:
ALGORITHM
ALGORITHM
 Compute new intersection points:
X1’=X1+u1(X2 – X1) Y1’=Y1+u1(Y2 – Y1)
X2’=X1+u2(X2 – X1) Y2’=Y1+u2(Y2 – Y1)
QUESTION
 Clip the lines using Cohen Sutherland and liang
barsky line clipping algorithm, line AB having vertex
coordinate A(25,5) and B(45,35) and line CD having
vertex coordinate C(0,10) and D(9,20) with respect
to clipping window(Xmin
=10,Ymin=10,Xmax=30,Ymax=30) .

Unit2- line clipping.pptx

  • 1.
    UNIT 2 POINT ANDLINE CLIPPING
  • 2.
    WINDOWING AND CLIPPING The world coordinate system is used to define the position of objects in the natural world.  This system does not depend on the screen coordinate system, so the interval of number can be anything (positive, negative or decimal).  Sometimes the complete picture of object in the world coordinate system is too large and complicate to clearly show on the screen, and we need to show only some part of the object.  The capability that show some part of object in a specified window is called windowing and a rectangular region in a world coordinate system is called window.
  • 3.
     A Windowis a rectangular region in the world coordinate system.  This is the coordinate system used to locate an object in the natural world.  A Viewport is the section of the screen where the images encompassed by the window on the world coordinate system will be drawn.  A coordinate transformation is required to display the image, encompassed by the window, in the viewport.
  • 4.
     The viewportuses the screen coordinate system so this transformation is from the world coordinate system to the screen coordinate system.  When a window is "placed" on the world, only certain objects and parts of objects can be seen.  Points and lines which are outside the window are "cut off" from view.  This process of "cutting off" parts of the image of the world is called Clipping.
  • 5.
     In clipping,we examine each line to determine whether or not it is completely inside the window, completely outside the window, or crosses a window boundary.  If inside the window, the line is displayed. If outside the window, the lines and points are not displayed.  If a line crosses the boundary, we must determine the point of intersection and display only the part which lies inside the window.
  • 8.
    POINT CLIPPING  Suppose(x,y) is a point coordinate and (Xmin, Xmax, Ymin, Ymax) are the coordinates for window.  If (x,y) lies inside the window then Xmin <= x <= Xmax Ymin<=y<=Ymax must be true.
  • 9.
  • 10.
    COHEN SUTHERLAND LINECLIPPING ALGORITHM (BASED ON REGION CODES)
  • 11.
  • 12.
     First Step:Determine the bit values of the two end- points of the line to be clipped.  To determine the bit value of any point, use: b1= sign(Ymax -Y); b2= sign(Y -Ymin); b3= sign(Xmax -X); b4= sign(X -Xmin);  Use these end-point codes to locate the line.
  • 13.
     Various possibilities: If both endpoint codes are [0000], the line lies completely inside the box, no need to clip. This is the simplest case (e.g. L1).  Any line has 1 in the same bit positions of both the endpoints, it is guaranteed to lie outside the box (e.g. L2 and L3).
  • 14.
     Neither completelyreject nor inside the box: Lines: L4 and L5 –needs more processing.  What about Line L6?  Processing of lines, neither completely IN or OUT; e.g. Lines: L4, L5 and L6.  Basic idea: Clip parts of the line in any order (consider from top or bottom)  Algorithm Steps: Compute outcodes of both endpoints to check for trivial acceptance or rejection
  • 15.
     If notso, obtain an endpoint that lies outside the box (atleast one will?)  Using the outcode, obtain the edge that is crossed first.
  • 16.
    OBTAIN CORRESPONDING INTERSECTION POINTS CLIP (replace the endpoint by the intersection point) w.r.t. the edge.  Compute the outcode for the updated end point and repeat the iteration, till it is 0000.  Repeat the above steps, if the other endpoint is also outside the area.  e.g. Take Line L5 (endpoints-E and I): E has outcode 0100 (to be clipped w.r.t. bottom edge);  So EI is clipped to FI; Outcode of F is 0000; But outcode of I is 1010;
  • 17.
     Clip(w.r.t.top edge)to get FH.  Outcode of H is 0010; Clip(w.r.t.right edge) to get FG;  Since outcode of G is 0000, display the final result as FG
  • 18.
    FORMULAS FOR CLIPPINGW.R.T. EDGE, IN CASES OF:
  • 19.
    ALGORITHM  Step 1:Given a line segment with endpoint P1=(x1,y1) and P2= (x2,y2)  Step 2: Compute the 4-bit codes for each endpoint. If both codes are 0000,(bitwise OR of the codes yields 0000 ) line lies completely inside the window: pass the endpoints to the draw routine. If both codes have a 1 in the same bit position (bitwise AND of the codes is not 0000), the line lies outside the window. It can be trivially rejected.  Step 3: If a line cannot be trivially accepted or rejected, at least one of the two endpoints must lie outside the window and the line segment crosses a window edge. This line must be clipped at the window edge before being passed to the drawing routine.
  • 20.
     Step 4:Examine one of the endpoints, say P1=(x1,y1). Read P1's 4-bit code in order: Left-to- Right.  Step 5: When a set bit (1) is found, compute the intersection I of the corresponding window edge with the line from P1 to P2. Replace with I and repeat the algorithm.
  • 21.
    QUESTIONS 1) Use theCohen Sutherland algorithm to clip line P1(10,20) , P2(100,10) against a window. Lower left corner (50,10) & upper right hand corner (80,40). 2) Consider a window bounded by a lines Xmin=0, Ymin=0, Xmax=5, Ymax=3. At what points a line segment joining (-1,0) and (4,5) will connect the window. (Apply Cohen Sutherland algorithm)
  • 23.
  • 24.
    LIANG BARSKY LINECLIPPING ALGORITHM (BASED ON PARAMETRIC EQUATIONS)  Consider parametric equation of a line segment:
  • 25.
     A pointis considered to be within a rectangle, iff
  • 27.
     Each ofthese four inequalities, can be expressed as:  where, the parameters are defined as:
  • 28.
     Based onthese four inequalities, we can find the following conditions of line clipping:  If pk = 0, the line is parallel to the corresponding clipping boundary:  K =1 -> Left  K =2 -> Right  K =3 -> Bottom  K =4 -> Top  If for any k, for which pk= 0:  qk < 0, the line is completely outside the boundary  qk >=0, the line is on or inside the parallel clipping boundary.
  • 29.
     If pk< 0, the line proceeds from the outside to the inside of the particular clipping boundary  If pk > 0, the line proceeds from the inside to the outside of the particular clipping boundary  In both these cases, the intersection parameter is calculated as:
  • 30.
  • 31.
    ALGORITHM  Compute newintersection points: X1’=X1+u1(X2 – X1) Y1’=Y1+u1(Y2 – Y1) X2’=X1+u2(X2 – X1) Y2’=Y1+u2(Y2 – Y1)
  • 32.
    QUESTION  Clip thelines using Cohen Sutherland and liang barsky line clipping algorithm, line AB having vertex coordinate A(25,5) and B(45,35) and line CD having vertex coordinate C(0,10) and D(9,20) with respect to clipping window(Xmin =10,Ymin=10,Xmax=30,Ymax=30) .