Download presentation

Presentation is loading. Please wait.

Published byPenelope Harsha Modified about 1 year ago

1
CLIPPING

2
Clipping Clipping Types of Clipping Types of Clipping - Point Clipping - Line Clipping Line Clipping Algorithm Line Clipping Algorithm Cohen Sutherland line clipping algo Cohen Sutherland line clipping algo

3
Clipping is a process of dividing an object into visible and invisible positions and displaying the visible portion and discarding the invisible portion. Generally we have clipping algorithms for the following primitive types. ◦ Point clipping ◦ Line clipping ◦ Area clipping (Polygon) ◦ Curve clipping ◦ Text clipping BACK

4
If xleft, xright, ybottom, and ytop denote the boundaries of a rectangle clipping window into a point (x, y) lies inside the window including the boundary if xleft ≤ x ≤ xright ybottom ≤ y ≤ ytop.

5
The below figure shows a number of different attitudes that a straight line segment may take with respect to the screen. The visible segment of a straight line can be determined simply by computing its two endpoints. BACK

6
1. If a, b are the end points of the line, check if the line is totally visible by checking whether the endpoints are totally inside the boundary. 2. If both end points left, right are above and below the window then the line is trivially invisible and hence reject.

7
If one point is inside and one point is outside then a portion of a line is invisible and a portion of a line is visible. This can be achieved by finding intersection of the line with corresponding boundaries such that the line segment outside the window is discarded, and the line segment inside the boundary is displayed.

8
If the two points are outside such that the line is diagonally passing the window then the intersection with the two boundaries are calculated and the position of the line from one boundary to other is displayed and the remaining two portions of the line are discarded. BACK

9
This is one of the most popular line clipping algorithms. This was introduced by Dan Cohen and Ivan Sutherland. It was designed not only to find the endpoints very rapidly but also to reject even more rapidly any line that is clearly invisible. This makes it a very good algorithm. For clipping pictures that are much larger than the screen.

10
Assign a four bit code to all regions as shown in the figure. Every line end point in a picture is assigned a 4-bit binary code known as region code, that identifies the location of the point relative to the boundaries of the clipping rectangle. Each bit position in the region code is used to indicate one of the 4 rectangle coordinates positions of the point with respected to clipping window to the left, right, below and top.

11
◦ Bit 1 – left ◦ Bit 2 – right ◦ Bit 3 – below ◦ Bit 4 – top A value of 1 in any bit position indicates that the point is in the relative position otherwise the bit position is set to zero. If a point is within the clipping the region code is 0000.

12
If the code of both the endpoints are 0000 then the line is totally visible and hence draw the line. Bit values in the region codes are determined by comparing endpoint co-ordinate values (x, y) to the clip boundaries.

13
Bit 1 is set to 1 if x < wmin. The other three bit values can be determined using similar comparison or calculating differences between endpoint co-ordinates and clipping boundaries. Use the resultant sign of each differences calculation to set the corresponding value in the region code.

14
◦ Bit 1 is the sign bit of x-xwmin ◦ Bit 2 is the sign bit of xwmax-x ◦ Bit 3 is the sign bit of y-ywmin ◦ Bit 4 is the sign bit of ywmax-y If any line have 1 in the same bit position in the region codes for each endpoint are completely outside the clipping rectangle, so we discard the line

15
For a line with end points co-ordinates (x1, y1) and (x2, y2) then the y coordinate of the intersection point with a vertical boundary can be obtained with the calculation y=y1 + m(x-x1) (1), where the x value is set either to xleft or xright.

16
Similarly if we are looking for the intersection with a horizontal boundary, the x co-ordinate can be calculated as x = x1 + 1/m (y-y1) (2) where y set either ybottom or ytop.

17
So the points are given by left: (xleft, y=m(xleft-x1) + y1) right:(xright, y=m(xright-x1) +y1) top: (x=1/m (ytop-y1) + x1,ytop) bottom: (x=1/m (ybottom-y1) + x1,ybottom) where (x1, y1) and (x2, y2) are the points and xleft, xright, ytop and ybottom are the boundaries of the window and m is the slope which is given by m = y2-y1 / x2-x1 (3). BACK

18

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google