The Cohen–Sutherland algorithm
is a computer graphics algorithm used for line clipping. The algorithm divides a two-dimensional space into 9 regions and then efficiently determines the lines and portions of lines that are visible in the center region of interest (the viewport).We will use 4-bits to divide the entire region. These 4 bits represent the Top, Bottom, Right, and Left of the region as shown in the following figure. Here, the TOP and LEFT bit is set to 1 because it is the TOP-LEFT corner.
Viewport Image Credits: Tutorials Point |
There are 3 possibilities for the line to lie −
- Line can be completely inside the window (This line should be visible).
- Line can be completely outside the window (This line should be rejected).
- Line can be partially inside the window (We find intersection point and draw only that portion of the line which lies inside the region).
Code:
If you can't see the code, then Enable JavaScript in you browser
Output:
Vrebnasupp_pu-Peoria Keith Hunt https://wakelet.com/wake/yVxwAcgCECfB2r7wzW2qb
ReplyDeletepecmamava