Keypoints to solve Cohen Sutherland questions
The two equations should be used to find the intersection points:-
- For left or right intersection points, equation is
Y = m( Xmin – x1) + y1 //for left
If we have to find intersection point in right ,then we will use Xmax ,
Y = m( Xmax – x1) + y1 // for right
- For above or below intersection points, equation is
Similarly , for above we have Ymax and below we have Ymin ,and we will find x
X = m( Ymin – y1) + x1 // for Below
X = m( YMax – y1) + x1 // For above
Note :- The value of Xmin , Xmin , Ymin , YMax will be minimum and maximum point of the window on X and Y axis.
Question: Use the Cohen Sutherland algorithm to clip line P1 (25,40) and p2(60,25) against a window lower left hand corner (10,10) and upper right hand corner (50,50).
Let Us say this Line AB With P(25,40) and q(60,25)
Now , as per the Algorithm we will check the endcode of the line.
Point Encode AND P 0000 0000 So ,the line cannot be trivally rejected. Q 0010
Also, Logical OR of both is not 0000, So the line is not trivally accepted.
Now , we will clip the line.
Slope of the given line = (y2-y1)/(x2-x1)
= -15/35 = -3/7
Now , the Point P lies inside the window and Point Q lies right and outside the window.
Making X and Y axis of window , XMax will be 50.
So , x1 and y1 will be Point p(25,40)
Putting the values
Y = m( Xmax – x1) + y1
=-3/7 (50-25) + 40
So , the clipped points are R(29.2, 50)