Clipping: Polygon

Sutherland-Hodgeman Polygon Clipping Algorithm

Pseudo Code of the Algorithm

Input: Vertices of the polygon, (xi, yi) for i = 1, 2, ..., n representing n vertices in the polygon, and the coordinates of the opposite corners of the clipped window.

Steps of the Algorithm:

  1. Initialization:

    • For each of the four boundaries of the clipped window, perform the following steps.
  2. Process Each Edge:

    • For each edge ei in the polygon, where Pi = (xi, yi) and Pi+1 = (xi+1, yi+1) represent the two vertices of edge ei, do the following:
  3. Check for Points Outside Clipping Area:

    • If both Pi and Pi+1 lie outside the clipping area, no point is written.
  4. Check for Points Inside Clipping Area:

    • If both Pi and Pi+1 lie inside the clipping area, Pi is written into the points of the clipped polygon.
  5. Check for One Point Inside and One Outside:

    • If Pi is inside and Pi+1 is outside, Pi is written into the points of the clipped polygon, and the intersection of ei with the concerned boundary is calculated. The point of intersection is then written into the points of the clipped polygon.
  6. Check for One Point Outside and One Inside:

    • If Pi+1 is inside and Pi is outside, Pi+1 is written into the points of the clipped polygon, and the intersection of ei with the concerned boundary is calculated. The point of intersection is then written into the points of the clipped polygon.

This algorithm systematically processes each edge of the polygon against the boundaries of the clipped window, determining whether a vertex or an intersection point should be included in the final clipped polygon. It efficiently eliminates portions of the polygon lying outside the specified window, optimizing the rendering process in computer graphics.