LIANG- BARSKY ALGORITHM, POLYGON CLIPPING &
PIPELINE CLIPPING OF POLYGONS
A G A L DANUSHKA
WHAT IS CLIPPING?
 The primary use of clipping in computer graphics is to remove objects, lines, or line
segments that are outside the viewing pane.
 The viewing transformation is insensitive to the position of points relative to the
viewing volume ( especially those points behind the viewer) and it is necessary to
remove these points before generating the view.
 There different types of clipping
 Point clipping
 Line clipping
 Polygon clipping
 Curve clipping
 Text clipping
LINE CLIPPING
 In computer graphics, line clipping is the process of removing lines or portions of lines
outside an area of interest. Typically, any line or part thereof which is outside of the viewing
area is removed.
 In the line clipping 4 different cases are possible
 Line intersect clipping window from one point
 Line intersect clipping window from two points
 Line completely outside the clipping window
 Line completely inside the clipping window
LINE CLIPPING
ALGORITHMS
 There are two common algorithms for line
clipping:
 Cohen–Sutherland clipping algorithm
 Liang–Barsky clipping algorithm
WHAT IS LIANG-BARSKY ALGORITHM?
 The Liang-Barsky algorithm is a line clipping algorithm.
 This algorithm is more efficient than Cohen–Sutherland line clipping algorithm and can be
extended to 3-Dimensional clipping.
 This algorithm is considered to be the faster parametric line-clipping algorithm.
 The following concepts are used in this clipping:
 The parametric equation of the line.
 The inequalities describing the range of the clipping window which is used to determine
the intersections between the line and the clip window.
PARAMETRIC DEFINITION OF THE LINE
 Liang – Barsky line clipping algorithm is faster line clipper algorithm based on analysis of the
parametric equation of a line segment.
 Parametric definition of a line;
 Where ,
INITIALIZATIONS AND CALCULATIONS
 Initializations;
 Set viewport points as xmin, xmax, ymin and ymax
 Set the line with 2 points A(x0,y0) and B (x1,y1)
 Set line intersection parameters tentry(t1) = 0.0
and tleaving(t2) =1.0
 Calculations:
 Find dx= x1-x0 and dy= y1-y0
 Update t1or t2depending upon dx or dy
xmin,ymin
xmax,ymax
B
A
ALGORITHM
1. Set tmin=0, tmax=1.
2. Calculate the values of t (t(left), t(right), t(top), t(bottom)),
(i) If t < tmin ignore that and move to the next edge.
(ii) else separate the t values as entering or exiting values using the inner product.
(iii) If t is entering value, set tmin = t; if t is existing value, set tmax = t.
3. If tmin < tmax, draw a line from (x1 + tmin(x2-x1), y1 + tmin(y2-y1)) to (x1 + tmax(x2-x1), y1 + tmax(y2-y1))
4. If the line crosses over the window, (x1 + tmin(x2-x1), y1 + tmin(y2-y1)) and (x1 + tmax(x2-x1), y1 +
tmax(y2-y1)) are the intersection point of line and edge.
ALGORITHM - STEP 01
 Accept Line end points A , B and
window coordinates Xwmin ,Ywmin,
Xwmax ,Ywmax as input.
 Set line intersection parameters
tentry(t1) = 0.0 and tleaving(t2) = 1.0
xmin,ymin
xmax,ymax
B
A
ALGORITHM - STEP 02
 Obtain pk and qk for k 1: 4
Edge &
K value
p q t
Left k=1 p1= -dx q1= x0-xmin t = q1/p1
Right k=2 p2= dx q2= xmax-x0 t = q2/p2
Bottom k=3 p3= -dy q3= y0-ymin t = q3/p3
Top k=4 p4= dy q4= ymax-y0 t = q4/p4
ALGORITHM - STEP 03
If pk=0,the line is parallel to the corresponding clipping boundary.
a)If pk=0 and qk<0, the line is completely outside the boundary.
b)If pk=0 and qk>=0, the line is inside the parallel clipping boundary.
ALGORITHM - STEP 04
Using pk and qk (k1:4), find if the line can be rejected or intersection parameters(t1andt2)must
be adjusted.
•if pk<0, update t1 as max[0,qk/pk] where k1:4
•if pk>0, update t2 as min[1,qk/pk] where k1:4
After the update,
•If t1>t2, reject the line
•If t1>0, calculate new values of x0,y0
•If t2<1, calculate new values of x1,y1
EXAMPLE
dx= P1x -P0x // Horizontal diff between P0and P1
dx= x1-x0= 280-30 = 250
dy= P1y -P0y // Vertical diff between P0 and P1
dy= y1-y0= 160-20 = 140
dx= 250 , dy= 140
Initially
tentry(t1) = 0.0
tleaving(t2) = 1.0
EXAMPLE CONT..
Left edge check:
p = -dx= -250
q = x0-xmin= 30-70 = -40
t = q/p = 0.16
If p< 0 // update tentry(t1) if t > t1 set t1 = t
-250 < 0 TRUE check if t > t1  0.16 > 0.0 TRUE
t1 = t
t1 = 0.16
t2 = 1.0
EXAMPLE CONT..
Right edge check:
p = dx= 250
q = xmax–x0= 230-30 = 200
t = q/p = 0.8
If p< 0 FALSE
If p > 0 // update tleaving(t2)
if t < t2 set t2 = t
250 > 0 TRUE
check if t < t2 ---> 0.8 < 1.0 TRUE
t2 = t = 0.8
t1 = 0.16 t2 = 0.8
EXAMPLE CONT..
Bottom edge check:
p = -dy= -140
q = y0-ymin= 20-60 = -40
t = q/p = 0.2857
If p< 0 // update tentry(t1)
if t > t1 set t1 = t
-140 < 0 TRUE
check if t > t10.2857 > 0.16 TRUE
t1 = tt1 = 0.2857 and t2 = 0.8
EXAMPLE CONT..
Top edge check:
p = dy= 140
q = ymax–y0= 150 -20 = 130
t = q/p = 0.928
If p< 0 FALSE
If p > 0 // update tleaving(t2)if t < t2 set t2 = t
140 > 0 TRUE
check if t < t2  0.928 < 0.8 FALSE
t1 = 0.2857 t2 = 0.8
EXAMPLE CONT..
t1 = 0.2857 t2 = 0.8
dx= 250dy= 140
if( tentry> 0.0 ) calculate new x0, y0 0.2857 > 0.0 TRUE
x0new= x0 + tentry *dx
x0new= 30 + 0.2857 * 250 = 101.425
y0new= y0 + tentry *dy
y0new= 20 + 0.2857 * 140 = 60.0
EXAMPLE CONT..
t1 = 0.2857 t2 = 0.8
dx= 250dy= 140
if( tleaving< 1.0 ) calculate new x1, y1 0.8 > 0.0 TRUE
x1new= x0 + tleaving*dx
x1new= 30 + 0.8 * 250 = 230
y1new= y0 + tleaving*dy
y1new= 20 + 0.8 * 140 = 132
Draw clipped line with the points A(x0new , y0new) and B(x1new , y1new)
WHAT IS POLYGON CLIPPING?
 A set of connected lines are considered
as polygon.
 To clip a polygon, we cannot directly
apply a line-clipping method to the
individual polygon edges because this
approach would produce a series of
unconnected line segments.
 polygons are clipped based on the
window and the portion which is inside
the window is kept as it is and the
outside portions are clipped.
 Polygon clipping is difficult compared
to line clipping
DIFFERENT CASE CATEGORIES
 The polygon clipping is required to deal different cases. Usually it clips the four
edges in the boundary of the clip rectangle. The clip boundary determines the visible
and invisible regions of polygon clipping and it is categorized as four.
 Visible region is wholly inside the clip window – saves endpoint
 Visible exits the clip window – Save the interaction
 Visible region is wholly outside the clip window – nothing to save
 Visible enters the clip window – save endpoint and intersection
POLYGON CLIPPING ALGORITHMS
 There several algorithms to polygon clipping;
 Greiner–Hormann clipping algorithm
 Sutherland–Hodgman algorithm
 Vatti clipping algorithm
 Weiler–Atherton clipping algorithm
SUTHERLAND-HODGMAN ALGORITHM
 For polygon clipping, we require an algorithm that will generate one or more closed areas
that are then scan converted for the area fill.
 The output of a polygon clipper should be a sequence of vertices that defines the clipped
polygon boundaries.
 Clip a polygon by processing the polygon boundary against each window edge. (Left, Top,
Bottom, Right).
 Apply four cases to process all polygon edges to produce sequence of vertices . This
sequence of vertices will make a bounded area.
 Beginning with the initial set of polygon vertices, we could first clip the polygon against the
left rectangle boundary to produce a new sequence of vertices.
 The new set of vertices could be successively passed to a right boundary clipper, a bottom
boundary clipper, and a top boundary clipper.
CLIPPING PROCESS
 At each step, a new sequence of output
vertices is generated and passed to the
next window boundary clipper.
 There are four possible cases when
processing vertices in sequence around
the perimeter of a polygon.
 As each pair of adjacent polygon
vertices is passed to a next window
boundary clipper, we make some tests:
CASE 1
 If the first vertex is outside the window boundary and the second vertex
is inside
 Then , both the intersection point of the polygon edge with the window
boundary and the second vertex are added to the output vertex list.
CASE 2
 If both input vertices are inside the window boundary.
 Then, only the second vertex is added to the output vertex list.
CASE 3
 If the first vertex is inside the window boundary and the second vertex is
outside.
 Then, only the edge intersection with the window boundary is added to the
output vertex list.
CASE 4
 If both input vertices are outside the window boundary.
 Then, nothing is added to the output vertex list.
EXAMPLE
 We illustrate this algorithm by processing the area in figure against
the left window boundary. Vertices 1 and 2 are outside of the
boundary.
 Vertex 3, which is inside, 1' and vertex 3 are saved.
 Vertex 4 and 5 are inside, and they also saved.
 Vertex 6 is outside, 5' is saved.
 Using the five saved points, we would repeat the process for the next
window boundary.
 The Sutherland-Hodgman algorithm correctly clips convex polygons,
but concave polygons may be displayed with extraneous lines as
demonstrated in figure.
 Since there is only one output vertex list, the last vertex in the list is
always joined to the first vertex.
IMPLEMENTATION
 There are two sub-problems that need to be discussed before implementing the algorithm
 To decide if a point is inside or outside the clipper polygon
 If the vertices of the clipper polygon are given in clockwise order then all the points lying on
the right side of the clipper edges are inside that polygon. This can be calculated using :
 Formula-for-position-of-point
IMPLEMENTATION CONT
 To find the point of intersection of an edge with the clip boundary
 If two points of each line(1,2 & 3,4) are known, then their point of intersection can be
calculated using the formula
COMPLEXITY
 Complexity Of this algorithm will increase if number of edges of polygon
increase. Algorithm has to calculate more number of intersection points over
window boundary.
Thank You
Questions?

More Related Content

PPT
Liang barsky Line Clipping Algorithm
PPTX
Clipping in Computer Graphics
PPTX
Clipping
PPTX
Bresenham's line algorithm
PPTX
3D transformation in computer graphics
PPTX
3 d viewing projection
PPTX
Weiler atherton
PPTX
Liang barsky Line Clipping Algorithm
Clipping in Computer Graphics
Clipping
Bresenham's line algorithm
3D transformation in computer graphics
3 d viewing projection
Weiler atherton

What's hot (20)

PPT
Visible surface detection in computer graphic
PPT
Clipping
PPTX
Anti aliasing Computer Graphics
PDF
Computer graphics curves and surfaces (1)
PPTX
Projection In Computer Graphics
PPTX
Computer graphics
PPTX
DDA-line-drawing-algorithm.pptx
PPT
Polygon filling
PPT
Circle drawing algo.
PPTX
Computer graphics - bresenham line drawing algorithm
PPTX
2 d viewing computer graphics
PPT
2D transformation (Computer Graphics)
PPTX
Attributes of output primitive(line attributes)
PPT
Unit-2 PPT.ppt
PPT
Ellipses drawing algo.
PPTX
Projection In Computer Graphics
PPTX
Window to viewport transformation&amp;matrix representation of homogeneous co...
PPTX
Scaling and shearing
PPT
Composite transformations
PPTX
Raster animation
Visible surface detection in computer graphic
Clipping
Anti aliasing Computer Graphics
Computer graphics curves and surfaces (1)
Projection In Computer Graphics
Computer graphics
DDA-line-drawing-algorithm.pptx
Polygon filling
Circle drawing algo.
Computer graphics - bresenham line drawing algorithm
2 d viewing computer graphics
2D transformation (Computer Graphics)
Attributes of output primitive(line attributes)
Unit-2 PPT.ppt
Ellipses drawing algo.
Projection In Computer Graphics
Window to viewport transformation&amp;matrix representation of homogeneous co...
Scaling and shearing
Composite transformations
Raster animation
Ad

Similar to Liang- Barsky Algorithm, Polygon clipping & pipeline clipping of polygons (20)

PPTX
Clipping computer graphics
PPTX
ibuib.pptx
PPTX
clippiNG COMPUTER GRAPHICS A NEW ERA.pptx
PPTX
kgv.pptx
PPTX
Clipping
PPT
99995327.ppt
PPTX
ohu.pptx
PPTX
Sutherland hodgman polygon clipping algorithm
PDF
Comparison of Various Line Clipping Algorithm for Improvement
PDF
Unit-IV Windowing and Clipping.pdf
PPTX
Unit2- line clipping.pptx
PPT
Polygon clipping
PDF
M.Sc_.-IV_ComputerGraphics_PolygonClipping_Bhupendra_K_Pandya.pdf
PPT
Cohen-sutherland & liang-basky line clipping algorithm
PPTX
Lect 5 2d clipping
PPTX
Clipping 22
PPTX
Clipping 22
PPTX
yutd65.pptx
Clipping computer graphics
ibuib.pptx
clippiNG COMPUTER GRAPHICS A NEW ERA.pptx
kgv.pptx
Clipping
99995327.ppt
ohu.pptx
Sutherland hodgman polygon clipping algorithm
Comparison of Various Line Clipping Algorithm for Improvement
Unit-IV Windowing and Clipping.pdf
Unit2- line clipping.pptx
Polygon clipping
M.Sc_.-IV_ComputerGraphics_PolygonClipping_Bhupendra_K_Pandya.pdf
Cohen-sutherland & liang-basky line clipping algorithm
Lect 5 2d clipping
Clipping 22
Clipping 22
yutd65.pptx
Ad

More from Lahiru Danushka (7)

PPTX
Virtual Machines - Virtual Box
PPTX
Human Computer Interaction (HCI)
PPTX
Formalization Machines and Sastes
PPTX
Dining Philosopher Problem and Solution
PPTX
My Sql Work Bench
PPTX
Election in Wireless Environment
PPTX
Shuffle exchange networks
Virtual Machines - Virtual Box
Human Computer Interaction (HCI)
Formalization Machines and Sastes
Dining Philosopher Problem and Solution
My Sql Work Bench
Election in Wireless Environment
Shuffle exchange networks

Recently uploaded (20)

PPT
LEC Synthetic Biology and its application.ppt
PPT
THE CELL THEORY AND ITS FUNDAMENTALS AND USE
PPTX
diabetes and its complications nephropathy neuropathy
PDF
7.Physics_8_WBS_Electricity.pdfXFGXFDHFHG
PPTX
Understanding the Circulatory System……..
PPTX
Introduction to Immunology (Unit-1).pptx
PDF
Communicating Health Policies to Diverse Populations (www.kiu.ac.ug)
PPT
1. INTRODUCTION TO EPIDEMIOLOGY.pptx for community medicine
PDF
Integrative Oncology: Merging Conventional and Alternative Approaches (www.k...
PPTX
2currentelectricity1-201006102815 (1).pptx
PPTX
AP CHEM 1.2 Mass spectroscopy of elements
PDF
Science Form five needed shit SCIENEce so
PPTX
endocrine - management of adrenal incidentaloma.pptx
PPTX
limit test definition and all limit tests
PDF
Is Earendel a Star Cluster?: Metal-poor Globular Cluster Progenitors at z ∼ 6
PPTX
TORCH INFECTIONS in pregnancy with toxoplasma
PPT
Mutation in dna of bacteria and repairss
PPTX
ELISA(Enzyme linked immunosorbent assay)
PDF
Unit 5 Preparations, Reactions, Properties and Isomersim of Organic Compounds...
PDF
CuO Nps photocatalysts 15156456551564161
LEC Synthetic Biology and its application.ppt
THE CELL THEORY AND ITS FUNDAMENTALS AND USE
diabetes and its complications nephropathy neuropathy
7.Physics_8_WBS_Electricity.pdfXFGXFDHFHG
Understanding the Circulatory System……..
Introduction to Immunology (Unit-1).pptx
Communicating Health Policies to Diverse Populations (www.kiu.ac.ug)
1. INTRODUCTION TO EPIDEMIOLOGY.pptx for community medicine
Integrative Oncology: Merging Conventional and Alternative Approaches (www.k...
2currentelectricity1-201006102815 (1).pptx
AP CHEM 1.2 Mass spectroscopy of elements
Science Form five needed shit SCIENEce so
endocrine - management of adrenal incidentaloma.pptx
limit test definition and all limit tests
Is Earendel a Star Cluster?: Metal-poor Globular Cluster Progenitors at z ∼ 6
TORCH INFECTIONS in pregnancy with toxoplasma
Mutation in dna of bacteria and repairss
ELISA(Enzyme linked immunosorbent assay)
Unit 5 Preparations, Reactions, Properties and Isomersim of Organic Compounds...
CuO Nps photocatalysts 15156456551564161

Liang- Barsky Algorithm, Polygon clipping & pipeline clipping of polygons

  • 1. LIANG- BARSKY ALGORITHM, POLYGON CLIPPING & PIPELINE CLIPPING OF POLYGONS A G A L DANUSHKA
  • 2. WHAT IS CLIPPING?  The primary use of clipping in computer graphics is to remove objects, lines, or line segments that are outside the viewing pane.  The viewing transformation is insensitive to the position of points relative to the viewing volume ( especially those points behind the viewer) and it is necessary to remove these points before generating the view.  There different types of clipping  Point clipping  Line clipping  Polygon clipping  Curve clipping  Text clipping
  • 3. LINE CLIPPING  In computer graphics, line clipping is the process of removing lines or portions of lines outside an area of interest. Typically, any line or part thereof which is outside of the viewing area is removed.  In the line clipping 4 different cases are possible  Line intersect clipping window from one point  Line intersect clipping window from two points  Line completely outside the clipping window  Line completely inside the clipping window
  • 4. LINE CLIPPING ALGORITHMS  There are two common algorithms for line clipping:  Cohen–Sutherland clipping algorithm  Liang–Barsky clipping algorithm
  • 5. WHAT IS LIANG-BARSKY ALGORITHM?  The Liang-Barsky algorithm is a line clipping algorithm.  This algorithm is more efficient than Cohen–Sutherland line clipping algorithm and can be extended to 3-Dimensional clipping.  This algorithm is considered to be the faster parametric line-clipping algorithm.  The following concepts are used in this clipping:  The parametric equation of the line.  The inequalities describing the range of the clipping window which is used to determine the intersections between the line and the clip window.
  • 6. PARAMETRIC DEFINITION OF THE LINE  Liang – Barsky line clipping algorithm is faster line clipper algorithm based on analysis of the parametric equation of a line segment.  Parametric definition of a line;  Where ,
  • 7. INITIALIZATIONS AND CALCULATIONS  Initializations;  Set viewport points as xmin, xmax, ymin and ymax  Set the line with 2 points A(x0,y0) and B (x1,y1)  Set line intersection parameters tentry(t1) = 0.0 and tleaving(t2) =1.0  Calculations:  Find dx= x1-x0 and dy= y1-y0  Update t1or t2depending upon dx or dy xmin,ymin xmax,ymax B A
  • 8. ALGORITHM 1. Set tmin=0, tmax=1. 2. Calculate the values of t (t(left), t(right), t(top), t(bottom)), (i) If t < tmin ignore that and move to the next edge. (ii) else separate the t values as entering or exiting values using the inner product. (iii) If t is entering value, set tmin = t; if t is existing value, set tmax = t. 3. If tmin < tmax, draw a line from (x1 + tmin(x2-x1), y1 + tmin(y2-y1)) to (x1 + tmax(x2-x1), y1 + tmax(y2-y1)) 4. If the line crosses over the window, (x1 + tmin(x2-x1), y1 + tmin(y2-y1)) and (x1 + tmax(x2-x1), y1 + tmax(y2-y1)) are the intersection point of line and edge.
  • 9. ALGORITHM - STEP 01  Accept Line end points A , B and window coordinates Xwmin ,Ywmin, Xwmax ,Ywmax as input.  Set line intersection parameters tentry(t1) = 0.0 and tleaving(t2) = 1.0 xmin,ymin xmax,ymax B A
  • 10. ALGORITHM - STEP 02  Obtain pk and qk for k 1: 4 Edge & K value p q t Left k=1 p1= -dx q1= x0-xmin t = q1/p1 Right k=2 p2= dx q2= xmax-x0 t = q2/p2 Bottom k=3 p3= -dy q3= y0-ymin t = q3/p3 Top k=4 p4= dy q4= ymax-y0 t = q4/p4
  • 11. ALGORITHM - STEP 03 If pk=0,the line is parallel to the corresponding clipping boundary. a)If pk=0 and qk<0, the line is completely outside the boundary. b)If pk=0 and qk>=0, the line is inside the parallel clipping boundary.
  • 12. ALGORITHM - STEP 04 Using pk and qk (k1:4), find if the line can be rejected or intersection parameters(t1andt2)must be adjusted. •if pk<0, update t1 as max[0,qk/pk] where k1:4 •if pk>0, update t2 as min[1,qk/pk] where k1:4 After the update, •If t1>t2, reject the line •If t1>0, calculate new values of x0,y0 •If t2<1, calculate new values of x1,y1
  • 13. EXAMPLE dx= P1x -P0x // Horizontal diff between P0and P1 dx= x1-x0= 280-30 = 250 dy= P1y -P0y // Vertical diff between P0 and P1 dy= y1-y0= 160-20 = 140 dx= 250 , dy= 140 Initially tentry(t1) = 0.0 tleaving(t2) = 1.0
  • 14. EXAMPLE CONT.. Left edge check: p = -dx= -250 q = x0-xmin= 30-70 = -40 t = q/p = 0.16 If p< 0 // update tentry(t1) if t > t1 set t1 = t -250 < 0 TRUE check if t > t1  0.16 > 0.0 TRUE t1 = t t1 = 0.16 t2 = 1.0
  • 15. EXAMPLE CONT.. Right edge check: p = dx= 250 q = xmax–x0= 230-30 = 200 t = q/p = 0.8 If p< 0 FALSE If p > 0 // update tleaving(t2) if t < t2 set t2 = t 250 > 0 TRUE check if t < t2 ---> 0.8 < 1.0 TRUE t2 = t = 0.8 t1 = 0.16 t2 = 0.8
  • 16. EXAMPLE CONT.. Bottom edge check: p = -dy= -140 q = y0-ymin= 20-60 = -40 t = q/p = 0.2857 If p< 0 // update tentry(t1) if t > t1 set t1 = t -140 < 0 TRUE check if t > t10.2857 > 0.16 TRUE t1 = tt1 = 0.2857 and t2 = 0.8
  • 17. EXAMPLE CONT.. Top edge check: p = dy= 140 q = ymax–y0= 150 -20 = 130 t = q/p = 0.928 If p< 0 FALSE If p > 0 // update tleaving(t2)if t < t2 set t2 = t 140 > 0 TRUE check if t < t2  0.928 < 0.8 FALSE t1 = 0.2857 t2 = 0.8
  • 18. EXAMPLE CONT.. t1 = 0.2857 t2 = 0.8 dx= 250dy= 140 if( tentry> 0.0 ) calculate new x0, y0 0.2857 > 0.0 TRUE x0new= x0 + tentry *dx x0new= 30 + 0.2857 * 250 = 101.425 y0new= y0 + tentry *dy y0new= 20 + 0.2857 * 140 = 60.0
  • 19. EXAMPLE CONT.. t1 = 0.2857 t2 = 0.8 dx= 250dy= 140 if( tleaving< 1.0 ) calculate new x1, y1 0.8 > 0.0 TRUE x1new= x0 + tleaving*dx x1new= 30 + 0.8 * 250 = 230 y1new= y0 + tleaving*dy y1new= 20 + 0.8 * 140 = 132 Draw clipped line with the points A(x0new , y0new) and B(x1new , y1new)
  • 20. WHAT IS POLYGON CLIPPING?  A set of connected lines are considered as polygon.  To clip a polygon, we cannot directly apply a line-clipping method to the individual polygon edges because this approach would produce a series of unconnected line segments.  polygons are clipped based on the window and the portion which is inside the window is kept as it is and the outside portions are clipped.  Polygon clipping is difficult compared to line clipping
  • 21. DIFFERENT CASE CATEGORIES  The polygon clipping is required to deal different cases. Usually it clips the four edges in the boundary of the clip rectangle. The clip boundary determines the visible and invisible regions of polygon clipping and it is categorized as four.  Visible region is wholly inside the clip window – saves endpoint  Visible exits the clip window – Save the interaction  Visible region is wholly outside the clip window – nothing to save  Visible enters the clip window – save endpoint and intersection
  • 22. POLYGON CLIPPING ALGORITHMS  There several algorithms to polygon clipping;  Greiner–Hormann clipping algorithm  Sutherland–Hodgman algorithm  Vatti clipping algorithm  Weiler–Atherton clipping algorithm
  • 23. SUTHERLAND-HODGMAN ALGORITHM  For polygon clipping, we require an algorithm that will generate one or more closed areas that are then scan converted for the area fill.  The output of a polygon clipper should be a sequence of vertices that defines the clipped polygon boundaries.  Clip a polygon by processing the polygon boundary against each window edge. (Left, Top, Bottom, Right).  Apply four cases to process all polygon edges to produce sequence of vertices . This sequence of vertices will make a bounded area.  Beginning with the initial set of polygon vertices, we could first clip the polygon against the left rectangle boundary to produce a new sequence of vertices.  The new set of vertices could be successively passed to a right boundary clipper, a bottom boundary clipper, and a top boundary clipper.
  • 24. CLIPPING PROCESS  At each step, a new sequence of output vertices is generated and passed to the next window boundary clipper.  There are four possible cases when processing vertices in sequence around the perimeter of a polygon.  As each pair of adjacent polygon vertices is passed to a next window boundary clipper, we make some tests:
  • 25. CASE 1  If the first vertex is outside the window boundary and the second vertex is inside  Then , both the intersection point of the polygon edge with the window boundary and the second vertex are added to the output vertex list.
  • 26. CASE 2  If both input vertices are inside the window boundary.  Then, only the second vertex is added to the output vertex list.
  • 27. CASE 3  If the first vertex is inside the window boundary and the second vertex is outside.  Then, only the edge intersection with the window boundary is added to the output vertex list.
  • 28. CASE 4  If both input vertices are outside the window boundary.  Then, nothing is added to the output vertex list.
  • 29. EXAMPLE  We illustrate this algorithm by processing the area in figure against the left window boundary. Vertices 1 and 2 are outside of the boundary.  Vertex 3, which is inside, 1' and vertex 3 are saved.  Vertex 4 and 5 are inside, and they also saved.  Vertex 6 is outside, 5' is saved.  Using the five saved points, we would repeat the process for the next window boundary.  The Sutherland-Hodgman algorithm correctly clips convex polygons, but concave polygons may be displayed with extraneous lines as demonstrated in figure.  Since there is only one output vertex list, the last vertex in the list is always joined to the first vertex.
  • 30. IMPLEMENTATION  There are two sub-problems that need to be discussed before implementing the algorithm  To decide if a point is inside or outside the clipper polygon  If the vertices of the clipper polygon are given in clockwise order then all the points lying on the right side of the clipper edges are inside that polygon. This can be calculated using :  Formula-for-position-of-point
  • 31. IMPLEMENTATION CONT  To find the point of intersection of an edge with the clip boundary  If two points of each line(1,2 & 3,4) are known, then their point of intersection can be calculated using the formula
  • 32. COMPLEXITY  Complexity Of this algorithm will increase if number of edges of polygon increase. Algorithm has to calculate more number of intersection points over window boundary.