0% found this document useful (0 votes)
2 views

Assignment No 5

The document outlines the implementation of the Cohen-Sutherland polygon clipping method, which is used to remove lines or portions of lines outside a specified viewport in computer graphics. It explains the algorithm's functioning, including the use of outcodes to determine visibility and the handling of different cases when clipping polygons, particularly with the Sutherland-Hodgman method. The process involves iteratively testing polygon edges against the clipping region and generating a new polygon that is entirely visible.

Uploaded by

mayuri tambe
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment No 5

The document outlines the implementation of the Cohen-Sutherland polygon clipping method, which is used to remove lines or portions of lines outside a specified viewport in computer graphics. It explains the algorithm's functioning, including the use of outcodes to determine visibility and the handling of different cases when clipping polygons, particularly with the Sutherland-Hodgman method. The process involves iteratively testing polygon edges against the clipping region and generating a new polygon that is entirely visible.

Uploaded by

mayuri tambe
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment No.

Aim:
Implement Cohen Sutherland polygon clipping method to clip the polygon
with respect the view-port and window. Use mouse click, keyboard interface
Theory:
Line Clipping – Cohen Sutherland
In computer graphics, 'line clipping' is the process of removing lines or portions of
lines outside of an area of interest. Typically, any line or part thereof which is
outside of the viewing area is removed.
The Cohen–Sutherland algorithm is a computer graphics algorithm used for line
clipping. The algorithm divides a two-dimensional space into 9 regions (or a three-
dimensional space into 27 regions), and then efficiently determines the lines and
portions of lines that are visible in the center region of interest (the viewport).
The algorithm was developed in 1967 during flight simulator work by Danny
Cohen and Ivan Sutherland
The design stage includes, excludes or partially includes the line based on where:
 Both endpoints are in the viewport region (bitwise OR of endpoints == 0):
trivial accept.
 Both endpoints share at least one non-visible region which implies that the
line does not cross the visible region. (bitwise AND of endpoints != 0):
trivial reject.
 Both endpoints are in different regions: In case of this nontrivial situation
the algorithm finds one of the two points that is outside the viewport region
(there will be at least one point outside). The intersection of the outpoint and
extended viewport border is then calculated (i.e. with the parametric
equation for the line) and this new point replaces the outpoint. The algorithm
repeats until a trivial accept or reject occurs.
The numbers in the figure below are called outcodes. The outcode is computed for
each of the two points in the line. The outcode will have four bits for two-
dimensional clipping, or six bits in the three-dimensional case. The first bit is set to
1 if the point is above the viewport. The bits in the 2D outcode represent: Top,
Bottom, Right, Left. For example the outcode 1010 represents a point that is top-
right of the viewport. Note that the outcodes for endpoints must be recalculated on
each iteration after the clipping occurs.

Sutherland Hodgman Polygon Clipping

It is used for clipping polygons. It works by extending each line of the convex clip
polygon in turn and selecting only vertices from the subject polygon those are on
the visible side.

An algorithm that clips a polygon must deal with many different cases. The case is
particularly note worthy in that the concave polygon is clipped into two separate
polygons. All in all, the task of clipping seems rather complex. Each edge of the
polygon must be tested against each edge of the clip rectangle; new edges must be
added, and existing edges must be discarded, retained, or divided. The algorithm
begins with an input list of all vertices in the subject polygon. Next, one side of the
clip polygon is extended infinitely in both directions, and the path of the subject
polygon is traversed. Vertices from the input list are inserted into an output list if
they lie on the visible side of the extended clip polygon line, and new vertices are
added to the output list where the subject polygon path crosses the extended clip
polygon line.

This process is repeated iteratively for each clip polygon side, using the
output list from one stage as the input list for the next. Once all sides of the clip
polygon have been processed, the final generated list of vertices defines a new
single polygon that is entirely visible. Note that if the subject polygon was concave
at vertices outside the clipping polygon, the new polygon may have coincident (i.e.
overlapping) edges – this is acceptable for rendering, but not for other applications
such as computing shadows.

Clipping polygons would seem to be quite complex. A single polygon can actually
be split into multiple polygons .The Sutherland-Hodgman algorithm clips a
polygon against all edges of the clipping region in turn. The algorithm steps from
vertex to vertex, adding 0, 1, or 2 vertices to the output list at each step.
he Sutherland-Hodgeman Polygon-Clipping Algorithms clips a given polygon
successively against the edges of the given clip-rectangle. These clip edges are
denoted with e1, e2, e3, and e4, here. The closed polygon is represented by a list of
its verteces (v1 to vn; Since we got 15 verteces in the example shown above, vn =
v15.).

Clipping is computed successively for each edge. The output list of the previous
clipping run is used as the inputlist for the next clipping run. 1st run: Clip edge: e1;
inputlist = {v1, v2, ..., v14, v15}, the given polygon

You might also like