### Cohen Sutherland Example

### 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( X_{min} – x_{1}) + y_{1 } //for left

If we have to find intersection point in right ,then we will use X_{max} ,

Y = m( X_{max} – x_{1}) + y_{1 // for right}

- For above or below intersection points, equation is

Similarly , for above we have Y_{max} and below we have Y_{min} ,and we will find x

_{ }X = m( Y_{min} – y_{1}) + x_{1 } // for Below

X = m( Y_{Max} – y_{1}) + x_{1} // For above

Note :- The value of X_{min} , X_{min} , Y_{min} , Y_{Max } 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).

Solution:-

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 = (y_{2}-y_{1})/(x_{2}-x_{1})

= -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 , X_{Max} will be 50.

So , x1 and y1 will be Point p(25,40)

Putting the values

Y = m( X_{max} – x_{1}) + y_{1}

=-3/7 (50-25) + 40

= 29.2

So , the clipped points are R(29.2, 50)

CommentsNo comment yet.