Given a Clipping Window P(20,20), Q(60,20), R(60,40) and S(20,40), Use Cohen Sutherland To Determine The Visible Portion of The Line A(40,80) and B(120,30)


Solution


Given a clipping window P(20,20), Q(60,20), R(60,40) and S(20,40), use Cohen Sutherland to determine the visible portion of the line A(40,80) and B(120,30)

Clipline (40, 80, 120, 30, 20, 60, 20, 40)

{

code1 = 0000 

done = 0

code2 = 0000

draw = 0

while (done == 0)

{

code1 = encode (x1, y1)

encode (40, 80)

{

if (x < xwmin) (40 < 20)

false

if (x > xwmax) (40 > 40)

false

if (y < ywmin) (80 < 20)

false

if (y > ywmax) (80 > 60) true

code = 1000

}

So, code1 = 1000

code2 = encode (120, 30)

encode (120, 30)

{

if (x < xwmin) (120 < 20)

false

if (x > xwmax) (120 > 40) true

code = 0010

if (y < ywmin) (30 < 20)

false

if (y > ywmax) (30 > 60) false

}

code2 = 0010

ans = accept (code1, code2)

accept (1000, 0010)

{

if (! (a ! b)) !(1000 ! 0010)

false

else

return 0

}

So, ans = 0

if (ans == 1)

{

false

}

else

{

ans = reject (code1, code2)

}

reject (1000, 0010)

{

if (a & b) (1000 & 0010)

false

else

return 0

}

So, ans = 0

if (ans == 1)

{

false

}

else

{

if (inside (code1))

false

if (x1 != x2)

m = (y2 - y1) / (x2 - x1)

                    = (30 -80) / (120 - 40)

        = (-50) / (80)

        = - 0.625

}

if (code1 & lb)

{

false

}

else if (code1 && b)

{

false

}

else if (code1 & bb)

{

false

}

else if (code1 & tb) true (1000 & 1000)

{

x1 = y1 + (ymax - y1) / m

y1 = ymax

}

}

while (done == 0)

{

code1 = 0010 = encode (112, 60)

code2 = 0010 = encode (120, 30)

ans = accept (code1, code2)

if (ans == 1)

{

flase

}

else

{

ans = 1 = reject (code1, code2)

if (ans == 1)

true

done = 1

}

}

while (draw == 1) true

dda (112, 60, 120, 30)

}

Double Buffering In Computer Graphics

2D Viewing Plane In Computer Graphics

Comment your views on this Article :)


Thank you for visiting my blog :)


No comments

Comment your views on this article

Powered by Blogger.