Рет қаралды 18,838
Lets learn Cohen Sutherland Line Clipping Algorithm with solved example.
THIS VIDEO IS UPDATED VERSION OF MY PREVIOUS COHEN SUTHERLAND LINE CLIPPING ALGORITHM.
BASIC CONCEPT:
This is one of the oldest and most popular line clipping algorithm.
Generally the method speeds up the processing of line segments by performing the initial tests that reduce the number of intersections that must be calculated.
Every line end point in the picture is assigned a 4 digit binary code, called a region code, that identifies the location of the point relative to the boundaries of clipping rectangle.
HOW TO ASSIGN THE REGION CODE??
T B R L
TOP BOTTOM RIGHT LEFT
IF the line end point is in the top-left position from clipping window then we assign ‘1’ to top and left. And for bottom and right we assign 0 as the line end point is NOT IN bottom & right position of clipping window.
SO the code for Top-left will be 1001
Similarly we assign code to all other positions.
Once we determine region codes of each endpoint of a line we can find out whether:
The line completely lies outside the clipping window
OR the line completely lies inside the clipping window.
OR the line partially lies inside the clipping window.
To find the above information we perform Logical AND operation on the area codes of 2 end points of the line &
IF Both end points lie outside clipping window and the logical AND is not 0000 then the line completely lies outside the clipping window.
IF BOTH endpoints lie inside clipping window the line lies inside the clipping window.
IF BOTH endpoints lie outside the clipping window and LOGICAL AND operation is 0000 then the line is partially inside the clipping window.
IF one of the endpoint is inside the window and one lies outside the window and LOGICAL AND operation is 0000 then the line is partially inside the clipping window.
if you have any suggestion for my Cohen Sutherland line clipping algorithm video, please post them in the comments section below.
IF YOU ENJOYED MY Cohen Sutherland line clipping algorithm VIDEO THEN HIT THE LIKE BUTTON.FOR MORE VIDEOS DO SUBSCRIBE AND LIKE AND SHARE. THANKS A LOT!!!!!!!!!!