This is one of the oldest and most popular line clipping algorithm. To speed up the process this algorithm performs initial tests that reduce number of intersections that must be calculated. It does so by using a 4 bit code called as region code or outcodes. These codes identify location of the end point of line. Each bit position indicates a direction, starting from the rightmost position of each bit indicates left, right, bottom, top respectively. Once we establish region codes for both the endpoints of a line we determine whether the endpoint is visible, partially visible or invisible with the help of ANDing of the region codes.
|Published (Last):||4 November 2012|
|PDF File Size:||8.60 Mb|
|ePub File Size:||1.69 Mb|
|Price:||Free* [*Free Regsitration Required]|
The algorithm divides a 2D space into 9 regions, of which only the middle part viewport is visible. In , 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.
Main article: Liang—Barsky algorithm The Liang—Barsky algorithm uses the parametric equation of a line and inequalities describing the range of the clipping box to determine the intersections between the line and the clipping box. With these intersections it knows which portion of the line should be drawn. This algorithm is significantly more efficient than Cohen—Sutherland, but Cohen—Sutherland does trivial accepts and rejects much faster, so it should be considered instead if most of the lines you need to clip would be completely in or out of the clip window.
The difference is that Liang—Barsky is a simplified Cyrus—Beck variation that was optimized for a rectangular clip window. The Cyrus—Beck algorithm is primarily intended for a clipping a line in the parametric form against a convex polygon in 2 dimensions or against a convex polyhedron in 3 dimensions.
The clipping window is divided into a number of different areas, depending on the position of the initial point of the line to be clipped. Fast clipping[ edit ] This algorithm has similarities with Cohen—Sutherland. The start and end positions are classified by which portion of the 9-area grid they occupy. A large switch statement jumps to a specialized handler for that case. In contrast, Cohen—Sutherland may have to iterate several times to handle the same case.
As the polygon is assumed to be convex and vertices are ordered clockwise or anti-clockwise, binary search can be applied and leads to a O lg N run-time complexity. The result of the classification determines the edges intersected by the line p. The algorithm is simple, easy to implement and extensible to a convex window as well.
Clipping Case: If the line is neither visible case nor invisible case. It is considered to be clipped case. First of all, the category of a line is found based on nine regions given below. All nine regions are assigned codes. Each code is of 4 bits.
Cohen Sutherland Line Clipping Algorithm in C and C++
Next Page The primary use of clipping in computer graphics is to remove objects, lines, or line segments that are outside the viewing pane. Point Clipping Clipping a point from a given window is very easy. Consider the following figure, where the rectangle indicates the window. Point clipping tells us whether the given point X, Y is within the given window or not; and decides whether we will use the minimum and maximum coordinates of the window. Line Clipping The concept of line clipping is same as point clipping.