Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

2.3 Sutherland-Hodgman Polygon Clipping

Lesson 12 of 32 in the free Computer Graphics notes on Siksha Sarovar, written by Rohit Jangra.

From Lines to Polygons

Clipping a polygon is harder than clipping a line because the result must remain a closed polygon, possibly with new vertices on the clip boundary. Sutherland-Hodgman clips a (convex) polygon against one clip edge at a time, sequencing through all clip edges.

Per-Edge Rule

Process each subject polygon edge (V_i, V_(i+1)) against one clip edge. Four cases:

V_iV_(i+1)Output
InsideInsideV_(i+1)
InsideOutsideIntersection point I
OutsideOutsideNothing
OutsideInsideI, V_(i+1)

The output of edge k is the input to edge k+1.

Algorithm Pseudocode

For each clipEdge in clipPolygon, build a fresh output list. For each consecutive pair (S, E) of subject vertices: if E is inside, then if S is also inside add E, else add the intersection of S-E with clipEdge and then E; if E is outside but S is inside, add only the intersection. After processing all clip edges, the surviving polygon is the result.

Walk-Through

Triangle (-2, 4), (6, 8), (4, -2) clipped against window [0,5] x [0,5]:

  1. Left edge x=0: trim parts with x<0. Vertex 1 outside, vertex 2 inside, vertex 3 inside. Add intersections + insides.
  2. Right edge x=5: trim parts with x>5. Vertex 2 outside now, etc.
  3. Continue with bottom y=0 and top y=5. After all four edges, the result is the polygon clipped to the window.

Limitations

  • Subject polygon may be concave; clip polygon must be convex.
  • For concave subject vs convex clip windows the result is correct only if it remains a single polygon; otherwise spurious connecting edges appear ("dog-leg" artifact). Use Weiler-Atherton for arbitrary polygon-polygon clipping.

Why It Matters

This is the core of viewport clipping in classical software pipelines and the conceptual model behind GPU clipping against the homogeneous frustum.