Professional Documents
Culture Documents
SUBMISSION BY:-
COMPUTER GRAPHICS
Note:- This pdf contain class notes By Pinaki mitra sir ON CLIPPING followed by examples of Clipping
2-DIMENSIONAL VIEWING
WORLD CO-ODINATE SYSTEM: Any convenient co-ordinate system WINDOW: A world co-ordinate area selected for clipping is called window. VIEW PORT: An area on the display to which the window is mapped.
We want
(Xv - Xv min) / (Xv max - Xv min) = (Xw Xwmin) / (Xw max Xw min) (Yv - Yv min) / (Yv max - Yv min) = (Yw Ywmin) / (Yw max Yw min) Xv = Xv min + (Xw Xw min) . Sx Yv = Yv min + (Yw Yw min) . Sy Sx = (Xv max - Xv min) / (Xw max Xw min) Sy = (Yv max - Yv min) / (Yw max Yw min)
1) We perform the following sequence of operations: Perform a scaling transformation using a fixed point position (Xw min, Yw min) that scales the window area to the size of viewport. 2) Translate the scaled windows area to the position of the viewport. Clipping operation Point clipping Line clipping Polygon clipping/area clipping
Point clipping:
Region code:
Bit-1 : is the sign bit of : X- Xw min Bit-2 : is the sign bit of : Xw max - X Bit-3 : is the sign bit of : Y - Yw min Bit-4 : is the sign bit of : Yw max -Y If the some bit positions of two end points have 1, then this line is reflected because both are outside the clipping window and in the same region outside the window. codes corresponding to P1 and P2. we perform the logical AND of the region if the result0000.
INTERSECTION COMPUTATION: Line segment Vertical boundary: Y = Y1+M(X- X1) Where X = Xw min or X = Xw max M = Y 2- Y 1 / X 2 - X 1 Horizontal boundary: X = X1 + (Y - Y1 /M) Where Y = Yw min or Y = Yw max where P1 =(X1,Y1) & P2=(X2,Y2)
CYRUS-BECK & LIANG-BARSKY LINE CLIPPING: Parametric representation of the line for the line P(t) = P0 +( P1 P0).t .
Vector : P(t)- PEi For t =0 P(0) PEi = P0 - PEi P(1) PEi = P1 - PEi So Ni . (P(t) PEi ) = 0 Ni . [P0+( P1 P0).t - PEi ] = 0 Ni . [P0 - PEi ] + Ni [P1 P0].t = 0 t = Ni . [P0 - PEi ]/ Ni .[P0 P1].
T can be computed if 1) Ni 2) D 3) Ni : D D So d h
(h h f (0 or multiple intersection) h do o h
|| o
( . )
If moving from P0 to P1 , causes us to cross a particular edge to enter the edges inside half plane, the intersection is PE(potentially entering), If it causes to leave the edges inside half plane it is PL(potentially leaving)
Te : the largest value of t corresponding to PE. T1 : the smallest value of t corresponding to PL. If TE > T1 discard the entire segment, otherwise (TE .. TL) determines the clipped portion of the line segment. Nicholl-lee Nicholl Line Clipping (only 2-D)
Line
Case 1:
L,T,R,B
Case2:
if P2 lies boundaries.
Case3:
OR
So
1 TR
So
1 2
<
So
1 TL
(YT - Y1)/ (XR - X1) < (Y2 - Y1)/ ( X2 - X1) < (YT - Y1)/ (XL - X1) Trivially if
(YT - Y1) ( X2 - X1) < (XL - X1).(Y2 - Y1) From parametric equation: X = X1 + ( X2 - X1) .u Y = Y1 + ( Y2 - Y1) .u
x- Intersection position on the left window boundary is x=xL with u= (xL-x1/ x2-x1) & y intersection position is Y = Y1 + ( Y2 - Y1)/ ( X2 - X1) . (XL - X1)
And intersection position with the top boundary with y=yT and u= (xT - y1/ y2y1) with X = X1 + ( X2 - X1)/ ( Y2 - Y1) . (YT - Y1)
POLYGON CLIPPING:
Using line clipping applied to polygonal boundary we obtain a series of unconnected line segments. We want the output of polygon clipper of be a sequence of vertices that defines the clipped polygon boundaries.
V1
V1
V2 V1
V
2
V2
V1
V1
V1
inin save v2
V2
inout Save v1 S
{ , 3 } , { , 3 , 4 } , { , 3 , 4 , 5 }, { ,3 ,4 , 5 , 5}
6 5 V3 V2 5
V3 V2
V1
IN SUTHERLAND-HODGEMAN algorithm, there is only one output vertex list , the lost vertex is always joined with the 1st vertex.
WEILER ATHERTON POLYGON CLIPPING: For clockwise processing of polygon vertices we use the following:
For an outside-to-inside pair of vertices follow polygonal boundary. For an inside-to-outside pair of vertices follow the window boundary in a clockwise direction.
{ v2, 2 , v3 , v4 } {
5, 5 ,
v6 }
Examples:Q1:- Find Region code for given line and clip by Sutherland cohen Algorithm ?
Ans:- According to Sutherland cohen Algorithm Coordinate of point will be 0101 As it belongs to Left-Below region. And point B will be 1010 As it lies in Right-Above region.
:-
Logical AND of A & B is 0000 and none of both is 0000 So it will be partially visible. As point A & C will be 0001 i.e. nonzero so we can remove it from line segment and now we have only BC as line segment. Again B & C = 0000 thats why it also will be partially visible. By 0-bit = 1 in C we can say that it has left crossed the window. So we remove CD(left) part from Line. Now line segment is BD. Similarly we can also remove BE and FE segment of line as every point has coordinate in which 1-bit = 1. I.e. it has crossed the right part of clipping window that why will be invisible. And finally we get a Line DF where D & F = 0000 with both are equal to 0000.
So we can say that Line segment DF will be completely visible as we dont have any bit equal to 1.
Example 2 :Clip below Polygon according to Sutherland-Hodgman algorithm ?? Ans:According to Sutherland-Hodgman algorithm we know that 1. Out -> In case:- For V1 -> V2 where V1 is the intersection point, then we save V1, V2 (I.) 2 .In -> Out case:- For V1 -> V2 where V1 is the intersection point, then we save V1. 3 .In -> In case :- we save V2.
4 .Out -> Out case:- We save nothing. And then we clip by Left -> Top -> Right -> Below. In given below example As Line segments from V6 Intersects Window at two points and we get to points by L1 and L2 from Case (1) and case 2 respectively. -When we clip form Left we get new Vertex list as V2 -> V3 -> V4 -> V5 -> L1 -> L1 -> V1 . Vertex set after Top Clip :- T2 -> V3 -> V4 -> V5 -> L1 -> L1 -> T1 Vertex set after Right Clip :- R1 -> R2 -> V4 -> V5 -> L1 -> L2 -> T1 -> T2 . Vertex set after Below Clip :- -> R2 -> B1 -> B2 -> V4 -> V5 -> L1 -> L2 -> T1 -> T2 > R1
Example 3 :- Weiler-Atherton Algorithm Find Clipped Polygon for Given Non-convex Polygon and clipping window?? Ans:Rules:For an outside to inside pair of vertices follow polygonal boundary. For an inside to Outside pair of vertices follow the window boundary in a clockwise direction. In given Below Polygon and window as 0-1 is inside to outside thats why we include window boundary in Clockwise direction and we get clipped part o-i-j-9. From 8-9 and 3-4 I.e. outside to inside pair of vertices we get polygonal boundary. Similarly by Inside to outside clipping of 5-6 We get 5-k-j-4 part. And we get new Clipped Polygon.
Example 4: - POINT CLIPPING Prove that given point will not be visible after clipping??? Ans:By condition of Point clipping we know that a point will be inside a clipping window If Xmin < = X <= Xmax Ymin < = Y <= Ymax For given point we have 10 < 65 but 60 < 65 is not true. Thats why this point will not be visible.