computer graphics clipping cohen sutherland algorithm (line) cyrus-back algorithm (line)...
TRANSCRIPT
Computer Graphics
Clipping• Cohen Sutherland Algorithm (Line)• Cyrus-Back Algorithm (Line)• Sutherland-Hodgeman Algorithm (Polygon)• Cohen Sutherland Algorithm (3d)
Clipping-When we want to study the picture but not whole picture, study some part, enlarge the part make study(X-ray) Selecting and enlarging the part known-Windowing, We select the portion of image and making visible and invisible-Clipping(cutting of the line which is outside View port)Image in object spaceImage in View spaceTransformation is required(Translate and scale) Translate the origin and Scale the object and translate it back to original
maxmin
maxmin
yyy
xxx
For a point For a point ((x,yx,y) ) to be inside the clip rectangleto be inside the clip rectangle::
(xmin , ymin )
(xmax , ymax )
x = xmin x = xmax
y = ymin
y = ymax
cliprectangle
Point Clipping
(xmin , ymin )
(xmax , ymax )
x = xmin x = xmax
y = ymin
y = ymax
(x1, y1)
cliprectangle
maxmin
maxmin
yyy
xxx
For a point For a point ((x,yx,y) ) to be inside the clip rectangleto be inside the clip rectangle::
Point Clipping
(Wx-Wxmin)/(Wxmax-Wxmin)=(Vx-Vxmin)/(Vxmax-Vxmin)
(Wy-Wymin)/(Wymax-Wymin)=(Vy-Vymin)/(Vymax-Vymin)
Viewing Transformation (N)V=N * WWhere N=Tv * S * T-vAspect ratioAw=(Wxmax-Wxmin)/(Wymax-Wymin)Av=(Vxmax-Vxmin)/(Vymax-Vymin)
Cases for clipping linesCases for clipping lines
D
E
F
A
BC
D'
G
H
G'
H'A
BC
D'
G'
H'
cliprectangle
Line Clipping
Cases for clipping linesCases for clipping lines
D
E
F
A
BC
D'
G
H
G'
H'
I
J
I'
J'
A
BC
D'
G'
H'
cliprectangle
Line Clipping
Line Clipping-Midpoint subdivision - Cohen Sutherland Algo
Midpoint- Check the lineIf it is entirely insideIt is entirely outside (discard)It is partially inside and partially outside
then Find mid point of two endpoints then divide line into two line segement and check both segments and continue
Algo for Midpoint1- Check line Completely outside the window
• Completely inside the window• Partially inside window (Line intersect
boundary, divide it from mid point)2-check again for both segemnts3- Repeat step-1 until whole part of line inside
the window
Clipping Lines by Solving Simultaneous EquationsClipping Lines by Solving Simultaneous Equations
cliprectangle
(xa, ya)(xb , yb)
(xc, yc) (xd , yd)
(x0, y0)
(x1, y1)
(x , y )
cliprectangle
(xa, ya)(xb , yb)
(xc, yc) (xd , yd)
(x0, y0)
(x1, y1)
(x , y )
abedgeaabedgea
lineline
yytyyxxtxx
yytyyxxtxx
,
, 010010
Line Clipping
The Cohen-Sutherland Line-Clipping Algorithm performs initial tests on a line to determine whether intersection calculations can be avoided.1. First, end-point pairs are checked for Trivial
Acceptance.2. If the line cannot be trivially accepted, region
checks are done for Trivial Rejection.3. If the line segment can be neither trivially
accepted or rejected, it is divided into two segments at a clip edge, so that one segment can be trivially rejected.These three steps are performed iteratively until what remains can be trivially accepted or rejected.
Cohen-Sutherland Algorithm
0000
1000
0100
1001 1010
0001 0010
0101 0110clip
rectangle
Region outcodesRegion outcodes
min
max
yy
yy
:1bit
: 0bit
min
max
xx
xx
:3bit
: 2bit
Cohen-Sutherland Algorithm
1. A line segment can be trivially accepted if the outcodes of both the endpoints are zero.
2. A line segment can be trivially rejected if the logical AND of the outcodes of the endpoints is not zero.
3. A key property of the outcode is that bits that are set in nonzero outcode correspond to edges crossed.
Cohen-Sutherland Algorithm
Algo1-Compute the codes for the Two end points2-Enter in loop, check if both outcodes are zero(0000 and 0000) put line in display file for display and exit loop, return3-if both outcodes are not zero then take logical AND of both codes, check result for nonzero if so reject line exit loop, return4-if result is zero then subdivide the line from intersection point of line and clipping boundary and repeat step 2,3,4
Clipping of the polygon -Clip Left --Clip right --Clip bottom ---
Clip top --- View transformationConsider Any Edge (P1P2)1.If both p1,p2 are left to edge, p2 is placed
vertex output list of clipped poly2. If p1,p2 are right to edge discard3. If p1,p2 cross edge and find intersection
point (I) if p1 is left to edge then I will be in
output list of vertex of clipped poly if p1 is right then both p1 and I in
output list
Determination of point if is left right to lineAB is line segement(x1,y1 and x2,y2) determine
point p (x,y)is left or right to ABFind cross product of vectors AB and AP then resulted vector has direction vector k then
point p is left to ABIf –k the point p is right to ABAP=(x-x1) *I +(y-y1) * JAB=(x2-x1) *I +(y2-y1) * JAB X AP=[(x2-x1) *(y-y1)-(y2-y1)*(y-y1)]*kd=(x2-x1) *(y-y1)-(y2-y1)*(y-y1)If d=+ then p is left to ABIf d=-Ve then p is right to AB
Case 1Case 1
Inside Outside
Polygonbeingclipped
Clipboundary
s
p:output
4 Cases of Polygon Clipping
Case 2Case 2
Inside Outside
s
p
i:output
Case 3Case 3
Inside Outside
s
p
(no output)
Case 4Case 4
Inside Outside
s
i:first output
p:second output
Algorithm Input vertex P
First Point YesNo
F=P
Does SP intersectE?
No
Yes
ComputeIntersection Point
I
Outputvertex I
S=P
Is S on leftside of E?
Exit
NO
Yes
Outputvertex S
Close Polygon entry
Does SFintersect E?
ComputeIntersection I
Yes
Outputvertex I
Exit
No
3D Clipping• Both the Cohen-Sutherland and Cyrus-Beck clipping algorithm
readily extend to 3D.• For Cohen-Sutherland algorithm use two extra-bit in outcode for
incorporating z < zmin and z > zmax regions