• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
June 22, 2022 |8.3K Views
Sutherland–Hodgman Polygon Clipping Algorithm | Computer Graphics
  Share   Like
Description
Discussion

In this video, we have discussed what is Sutherland–Hodgman Polygon Clipping Algorithm in Computer Graphics with the help of an example.

Polygon clipping is a process, that considers the part that is present inside the window and removes or clips the part that is present outside the window. This algorithm is used for clipping polygons, It works with each line of convex clip polygon by selecting only vertices from the polygon that are visible side.

Consider each edge ‘e’ of the clipping Area, Clip given polygon against e.

How we clip against an edge of the clipping area: The edge is extended infinitely to create a boundary and all the vertices are clipped by using this boundary. and the new list of the vertices generated is then passed to the next edge and in the same way in the clockwise direction, we perform the action until all the edges have been used.

There are four possible cases for any given edge of a given polygon against the current clipping edge e. Both vertices are inside.
- The first vertex is outside while the second vertex is inside.
- The first vertex is inside while the second vertex is outside.
- Both vertices are outside.

Sutherland Hodgman Algorithm:

Step 1: Read coordinates of all vertices of the polygon
Step 2: Read coordinates of the clipping windows
Step 3: Consider the left edge of the window
Step 4: Compare the vertices of edge of the polygon, individually with the clipping plane
Step 5: According to four possible relationship between the edge and clipping boundary , Save the resulting intersection and vertices in the new list of vertices
Step 6: Repeat the step 4 and 5 for removing edges or the clipping windows. Each time the resultant list of vertices in successively passed to process the next edge of the clipping windows.
Step 7: Stop

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.

It can be calculated by using the formula:
P = (X2-X1)(Y-Y1) – (Y2-Y1)(X-X1)
Where (X1, Y1) are line start points
(Y1, Y2) are line endpoints

If P<0 the point is on the right side of line
If P=0 the point is on the line
If P>0 the point is on the left side of line

Sutherland–Hodgman Polygon Clipping Algorithm | Computer Graphics: https://www.geeksforgeeks.org/polygon-clipping-sutherland-hodgman-algorithm/

Read More