Download presentation
Presentation is loading. Please wait.
Published byLinda Weaver Modified over 9 years ago
2
Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm (3d)
3
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 space Image in View space Transformation is required (Translate and scale) Translate the origin and Scale the object and translate it back to original
4
For a point (x,y) to be inside the clip rectangle: Point Clipping
5
For a point (x,y) to be inside the clip rectangle: Point Clipping
6
(Wx-Wxmin)/(Wxmax-Wxmin) =(Vx-Vxmin)/(Vxmax-Vxmin) (Wy-Wymin)/(Wymax-Wymin) =(Vy-Vymin)/(Vymax-Vymin) Viewing Transformation (N) V=N * W Where N=Tv * S * T-v Aspect ratio Aw=(Wxmax-Wxmin)/(Wymax-Wymin) Av=(Vxmax-Vxmin)/(Vymax-Vymin)
7
Cases for clipping lines Line Clipping
8
Cases for clipping lines Line Clipping
9
Cases for clipping lines Line Clipping
10
Cases for clipping lines Line Clipping
11
Cases for clipping lines Line Clipping
12
Cases for clipping lines Line Clipping
13
Line Clipping-Midpoint subdivision - Cohen Sutherland Algo Midpoint- Check the line If it is entirely inside It 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
14
Algo for Midpoint 1- 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 segemnts 3- Repeat step-1 until whole part of line inside the window
15
Clipping Lines by Solving Simultaneous Equations Line Clipping
16
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
17
Region outcodes
18
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
19
Algo 1-Compute the codes for the Two end points 2-Enter in loop, check if both outcodes are zero(0000 and 0000) put line in display file for display and exit loop, return 3-if both outcodes are not zero then take logical AND of both codes, check result for nonzero if so reject line exit loop, return 4-if result is zero then subdivide the line from intersection point of line and clipping boundary and repeat step 2,3,4
20
An Example Cohen-Sutherland Algorithm
21
An Example Cohen-Sutherland Algorithm
22
An Example Cohen-Sutherland Algorithm
23
An Example Cohen-Sutherland Algorithm
24
Example Polygon Clipping
25
Example
26
Example
27
Sutherland-Hodgeman Algo. The Clipped Polygon
28
Clipping of the polygon - Clip Left -- Clip right -- Clip bottom --- Clip top --- View transformation Consider Any Edge (P1P2) 1.If both p1,p2 are left to edge, p2 is placed vertex output list of clipped poly 2. If p1,p2 are right to edge discard 3. 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
29
Determination of point if is left right to line AB is line segement(x1,y1 and x2,y2) determine point p (x,y)is left or right to AB Find cross product of vectors AB and AP then resulted vector has direction vector k then point p is left to AB If –k the point p is right to AB AP=(x-x1) *I +(y-y1) * J AB=(x2-x1) *I +(y2-y1) * J AB X AP=[(x2-x1) *(y-y1)-(y2-y1)*(y-y1)]*k d=(x2-x1) *(y-y1)-(y2-y1)*(y-y1) If d=+ then p is left to AB If d=-Ve then p is right to AB
30
Case 1 4 Cases of Polygon Clipping Case 2 Case 3 Case 4
31
Algorithm
32
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 z max regions
33
Thank You
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.