Geometrical examine Types of Line Clipping
Geometrical examine of the above kinds of clipping (it assists to get point of intersection of line PQ along with any edge).
Assume (x_{1}, y_{1}) and (x_{2}, y_{2}) be the coordinates of P and Q respectively.
1) Top case/above
If y1 > yw_{max} then 1st bit of bit code = 1 (suggesting above) else bit code = 0
2) Bottom case/below case
If y_{1} < yw_{min} then 2^{nd} bit = 1 (that is below) else bit = 0
3) Left case: if x_{1} < xw_{min} then 3rd bit = 1 (that is left) else 0
4) Right case: if x_{1} > xw_{max} then 4th bit = 1 (that is right) else 0
Likewise, the bit codes of the point Q will also be allocated.
1) Top/above case:
Equation of top edge is: y = yw_{max}. The equation of line PQ is y - y_{1} = m (x - x_{1});
Here, m = (y_{2} - y_{1})/ (x_{2} - x_{1}). The coordinates of the point of intersection will be (x, yw_{max}) ∴equation of line among point P and intersection point is (yw_{max} - y_{1}) = m ( x - x_{1}) rearrange we find x = x + 1
(yw_{max} - y_{1} ) = m (x - x_{1})
Now arrange then we find
x = x_{1} + (1/m) (yw_{max} - y_{1} ) ------------------ (A)
Thus, we acquire coordinates (x, yw_{max}) that is coordinates of the intersection.
2) Bottom/below edge begin along with y = yw_{min} and proceed as for above mentioned case.
∴equation of line among intersection point (x', yw_{min}) and point Q that is (x_{2}, y_{2}) Is (yw_{min} - y_{2}) = m (x′ - x_{2}) rearranging that we determine,
x′ = x_{2} + (1/m)( yw_{min} - y_{2})------------------------(B)
The coordinates of the point of intersection of PQ along with the bottom edge will be
x_{2} + (1/m)( yw_{min} - y_{2}),yw_{min})
3) Left edge: the equation of left edge is x = xw_{min}.
Here, the point of intersection is (xw_{min}, y).
By using 2 point from the equation of the line we contain:
(y - y_{1}) = m (xw_{min} - x_{1})
So now again arranging that, we find, y = y_{1} + m (xw_{min} - x_{1}). -------------------- (C)
Consequently, we find value of xw_{min} and y both that are the coordinates of intersection point is identified via ( xw_{min} , y_{1} + m( xw_{min} - x_{1} )) .
4) Right edge: proceed as in left edge case although start along with x-xw_{max}.
Here point of intersection is (xw_{max}, y′).
By using 2 point form, the equation of the line is (y′ - y_{2}) = m (xw_{max} - x_{2})
y' = y_{2} + (m(xw_{max} - x_{2}))-------------------(D)
The coordinates of the intersection of PQ along with the right edge will be
( xw_{max} , y_{2} + m( xw_{max} - x_{2} )).