In: Computer Science
Use Cohen Sutherland algorithm to clip line P1(70,20) and p2(100, 10) against a window lower left corner(50,10) and upper right hand corner(80,40)
Here the given line is P1(70,20) to P2(100,10)
window lower left corner = (50,10)
window upper right corner = (80,40)
So the window is...
Now we assign 4-bit binary outcode
As point P1 is inside the window so outcode of P1 = (0000) and outcode of P2 = (0010) as P2 is right to window
Doing AND operation on P1 & P2 0 0 0 0 0 0 1 0 -------------- 0 0 0 0 the result of AND operation is zero, so line is partially visible...
slope of line P1P2 is m = (y2 - y1) / (x2 - x1) = (20 - 10) / (100 - 70) = - 1 / 3
We have to find intersection of the line P1P2 with right edge of the window i.e point P2
Let the intersection point be (x , y) and here x=80 here P2(x2 , y2) = P2(100 , 10)
m = (y - y2) / (x - x2)
from above we got m = - 1 / 3
So... - 1 / 3 = (y - 10) / (80 - 100)
- 1 / 3 = (y - 10) / ( - 20 )
y = (20/3) + 10 = 16.66
The intersection point P3 ( 80 , 16.66 )
So after clipping the line P1P2 against window, new line is P1P3 with coordinates P1(70 , 20) and P3(80 , 16.66)