Cohen-Sutherland
Encyclopedia
In computer graphics
, the Cohen–Sutherland algorithm (named after Michael F. Cohen and Ivan Sutherland
) is a line clipping
algorithm. The algorithm divides a 2D space into 9 regions, of which only the middle part (viewport) is visible.
In 1967, flight simulation work by Danny Cohen
led to the development of the Cohen–Sutherland computer graphics two and three dimensional line clipping
algorithms, created with Ivan Sutherland
..
The numbers in the figure below are called outcodes. An outcode is computed for each of the two points in the line. The first bit is set to 1 if the point is above the viewport. The bits in the 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.
Computer graphics
Computer graphics are graphics created using computers and, more generally, the representation and manipulation of image data by a computer with help from specialized software and hardware....
, the Cohen–Sutherland algorithm (named after Michael F. Cohen and Ivan Sutherland
Ivan Sutherland
Ivan Edward Sutherland is an American computer scientist and Internet pioneer. He received the Turing Award from the Association for Computing Machinery in 1988 for the invention of Sketchpad, an early predecessor to the sort of graphical user interface that has become ubiquitous in personal...
) is a line clipping
Line clipping
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....
algorithm. The algorithm divides a 2D space into 9 regions, of which only the middle part (viewport) is visible.
In 1967, flight simulation work by Danny Cohen
Danny Cohen (engineer)
Danny Cohen is a member of the National Academy of Engineering and anIEEE Fellow . In 1993 Cohen received a USAF Meritorious Civilian Service Award....
led to the development of the Cohen–Sutherland computer graphics two and three dimensional line clipping
Line clipping
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....
algorithms, created with Ivan Sutherland
Ivan Sutherland
Ivan Edward Sutherland is an American computer scientist and Internet pioneer. He received the Turing Award from the Association for Computing Machinery in 1988 for the invention of Sketchpad, an early predecessor to the sort of graphical user interface that has become ubiquitous in personal...
..
The algorithm
The algorithm 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 are on the same non-visible region (bitwise AND of endpoints != 0): trivial reject.
- Both endpoints are in different regions: In case of this non trivial 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. An outcode is computed for each of the two points in the line. The first bit is set to 1 if the point is above the viewport. The bits in the 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.
1001 | 1000 | 1010 |
0001 | 0000 | 0010 |
0101 | 0100 | 0110 |
Example C/C++ implementation
See also
Algorithms used for the same purpose:- Liang–Barsky
- Cyrus–Beck
- Nicholl–Lee–Nicholl
- Fast-clipping