0% found this document useful (0 votes)
11 views

UNIT 2 Clipping Algorithm

Uploaded by

Shambhavi Mishra
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

UNIT 2 Clipping Algorithm

Uploaded by

Shambhavi Mishra
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

CLIPPING ALGORITHM

Shubhangi Krishna
CLIPPING
• The procedure that identifies the portion of a picture that are either inside or outside
of a specified region of space is referred as clipping.
• The region against which an object is clipped is called clip window or clipping
window.
• It is usually in rectangular shape.
CLIPPING

Hither and Yon: here and there


POINT CLIPPING
• Point clipping tells us whether the given point (X, Y) is within the given window
or not; and decides whether we will use the minimum and maximum coordinates
of the window.

• The X-coordinate of the given point is inside the window, if X lies in between Wx1
≤ X ≤ Wx2. Same way, Y coordinate of the given point is inside the window, if Y
lies in between Wy1 ≤ Y ≤ Wy2.

• The concept of line clipping is same as point clipping. In line clipping, we will cut
the portion of line which is outside of window and keep only the portion that is
inside the window.
POINT CLIPPING
LINE CLIPPING
• In computer graphics, line clipping is the process of removing lines or portions of
lines outside an area of interest. Typically, any line or part thereof which is outside of
the viewing area is removed.
• Given a set of lines and a rectangular area of interest, the task is to remove lines
which are outside the area of interest and clip the lines which are partially inside the
area.
LINE CLIPPING
• There are three possible cases for any given line.
• Case1:
• Completely inside the given rectangle : Bitwise OR of region of two end points of line is 0
(Both points are inside the rectangle)
• Case 2:
• Completely outside the given rectangle : Both endpoints share at least one outside region
which implies that the line does not cross the visible region. (bitwise AND of endpoints !=
0).
• Case 3:
• Partially inside the window, both endpoints are in different regions.
• In this case, the algorithm finds one of the two points that is outside the rectangular
region.
• The intersection of the line from outside point and rectangular window becomes new
corner point and the algorithm repeats
COHEN SUTHERLAND LINE CLIPPING
• In the algorithm, first of all, it is detected whether line lies inside the screen or it is
outside the screen.
• All lines come under any one of the following categories:
• Visible
• Not Visible
• Clipping Case
COHEN SUTHERLAND LINE CLIPPING
• Cohen-Sutherland algorithm divides a two-dimensional space into 9 regions and
then efficiently determines the lines and portions of lines that are inside the given
rectangular area.
• First of all, the category of a line is found based on nine regions given below. All nine
regions are assigned codes
• Each code is of 4 bits. If both endpoints of the line have end bits zero, then the line is
considered to be visible.
COHEN SUTHERLAND LINE CLIPPING
COHEN SUTHERLAND LINE CLIPPING
• We will use 4-bits to divide the entire region.
• These 4 bits represent the Top, Bottom, Right, and Left of the region as shown in the
following figure:
• Here, the TOP and LEFT bit is set to 1 because it is the TOP-LEFT corner.
ALGORITHM
• Step 1 − Assign a region code for each endpoints.
• Step 2 − If both endpoints have a region code 0000 then accept this line.
• Step 3 − Else, perform the logical AND operation for both region codes.
• Step 3.1 − If the result is not 0000, then reject the line.
• Step 3.2 − Else you need clipping.
• Step 3.2.1 − Choose an endpoint of the line that is outside the window.
• Step 3.2.2 − Find the intersection point at the window boundary (base
on region code).
• Step 3.2.3 − Replace endpoint with the intersection point and update
the region code.
• Step 3.2.4 − Repeat step 2 until we find a clipped line either trivially
accepted or trivially rejected.
• Step 4 − Repeat step 1 for other lines.
STEPS TO CALCULATE
• BL = (XMIN, YMIN) ; UR = (XMAX, YMAX)
• M= (Y2-Y1) / (X2-X1)
• NOTE: the point within that lies within the window should be taken as P1.
• CASE 1:
• LEFT:
• X’ = XMIN
• M = (Y’-Y1)/(X’-X1)
• Y’ = Y1 + M(X’ – X1)
• CASE 2:
• RIGHT:
• X’ = XMAX
• M = (Y’-Y1)/(X’-X1)
• Y’ = Y1 + M(X’ – X1)
STEPS TO CALCULATE
• BL = (XMIN, YMIN) ; UR = (XMAX, YMAX)
• M= (Y2-Y1) / (X2-X1)
• NOTE: the point within that lies within the window should be taken as P1.
• CASE 3:
• BOTTOM:
• Y’ = YMIN
• M = (Y’-Y1)/(X’-X1)
• X’ = X1 + (Y’ – Y1)/M
• CASE 4:
• BOTTOM:
• Y’ = YMAX
• M = (Y’-Y1)/(X’-X1)
• X’ = X1 + (Y’ – Y1)/M
MID POINT SUBDIVISION LINE CLIPPING
• It is used for clipping line where the line is divided in two parts.
• Mid points of line is obtained by dividing it in two short segments.
• Again division is done, by finding midpoint.
• This process is continued until line of visible and invisible category is obtained.
• Let (xm,ym) are midpoint, then
ALGORITHM
ALGORITHM
• Step1: Calculate the position of both endpoints of the line
• Step2: Perform AND operation on both of these endpoints
• Step3: If the AND operation gives 0000
then
Line is guaranteed to be visible
else
Perform AND operation on both endpoints.
If AND ≠ 0000
then the line is invisible
else
AND=0000
then the line is clipped case.
ALGORITHM
• Step4: For the line to be clipped. Find midpoint
Xm=(x1+x2)/2
Ym=(y1+y2)/2
Xmis midpoint of X coordinate.
Ymis midpoint of Y coordinate.
• Step5: Check each midpoint, whether it nearest to the boundary of a
window or not.
• Step6: If the line is totally visible or totally rejected not found then repeat
step 1 to 5.
• Step7: Stop algorithm.
Cyrus Beck Algorithm
• The Cyrus–Beck algorithm is a generalized line clipping algorithm.
• It was designed to be more efficient than the Cohen–Sutherland algorithm, which
uses repetitive clipping and which can be used only on a rectangular clipping area.
• Cyrus Beck is a line clipping algorithm that is made for convex polygons.
• It allows line clipping for non-rectangular windows, unlike Cohen Sutherland.
• It also removes the repeated clipping needed in Cohen Sutherland.
Cyrus Beck Algorithm
• Choose a point called P1 from the two points of the line (P0P1).
• Now for each edge of the polygon, calculate the normal pointing away from the
center of the polygon, namely N1, N2, etc.
• Now for each edge choose PEi (i -> ith edge) (choose any of the vertices of the
corresponding edge, eg.: For polygon ABCD, for side AB, PEi can be either point A or
point B) and calculate
P0 - PEi
P1 - P0

Cyrus Beck Algorithm


Cyrus Beck Algorithm
• Then club the ‘t’ values for which the Ni .
• (P1 – P0) came out to be negative and take the minimum of all of them and 1.
• Similarly club all the ‘t’ values for which the Ni .
• (P1 – P0) came out to be positive and take the maximum of all of the clubbed ‘t’
values and 0.
• Now the two ‘t’ values obtained from this algorithm are plugged into the parametric
form of the ‘to be clipped’ line and the resulting two points obtained are the clipped
points.
Cyrus Beck Algorithm
Cyrus Beck Algorithm

You might also like