The Cohen-Sutherland algorithm is an algorithm for clipping a line to fit a viewport (the area displayed onscreen). Drawing parts of a line would be wasteful of system resources.

Therefore, the Cohen-Sutherland Clipping Algorithm determines which parts of a line are onscreen, and so should be drawn.

The virtual canvas is divided into five portions; the viewport, above the viewport, below the viewport, to the left of it and to the right.

If the beginning coordinate and ending coordinate both fall inside the viewport then the line is automatically drawn in its entirity. If both fall in the same region outside the viewport, it is disregarded and not drawn.

If a line's coordinates fall in different regions, the line is divided into two, with a new coordinate in the middle. The algorithm is repeated for each section; one will be drawn completely, and the other will need to be divided again, until the line is only one pixel.

This algorithm is the most popular clipping algorithm, despite not being the most efficient. It is good if a large percentage of the data lies entirely inside or outside the viewport, and so it doesn't have to do a lot of line division.

Log in or register to write something here or to contact authors.