POLYGON CLIPPING PROGRAM IN C | SUTHERLAND - HODGEMAN ALGORITHM FOR POLYGON CLIPPING
In computer graphics, we have to study the Sutherland - Hodgeman polygon clipping algorithm. The algorithm according to the book by A. P. Godse is as follows:
Algorithm:-
Step 1- Read coordinates of all the vertices of polygon
Step 2- Read coordinates of the clipping window
Step 3- Consider the left edge of window
Step 4- Compare the vertices of each edge of the polygon , individually with clipping plane.
Step 5-Save the resulting intersections and vertices in the new list of vertices according to four possible relationships between the edge and the clipping boundary discussed earlier.
Step 6- Repeat the steps 4 and 5 for remaining edges of the clipping window. Each time the resultant list of the vertices of is successively passed to process the next edge of the clipping window.
Step 7- Stop
Now for implementing this algorithm is so complicated and lengthy, so I've done some trick to get the same output but with different logic. You'll get the polygon clipped in the output.
Here's the program in c,
Program:-
Output:-
After running this program, first you've to enter the number of vertices of polygon.
Output: Enter number of vertices |
After entering number of vertices you'll be asked to enter coordinates of vertices.
Output: Enter coordinates of vertices |
After entering vertices' coordinates just press a button a polygon will be drawn with white color. Now press a button to clip the polygon and you'll simply get the clipped polygon in the output.
Clipped Polygon |
So, this is the simplest program to clip a polygon. If you want to change the window coordinates you can change them according to you.
Tags
POLYGON CLIPPING
POLYGON CLIPPING PROGRAM IN C
SUTHERLAND HODGEMAN ALGORITHM
SUTHERLAND HODGEMAN C PROGRAM