Clipping
Clipping
Visible: If a line lies within the window, i.e., both endpoints of the line lies within the
window. A line is visible and will be displayed as it is.
Not Visible: If a line lies outside the window it will be invisible and rejected. Such lines
will not display. If any one of the following inequalities is satisfied then the line is
considered invisible.
Step3:If the OR operation gives 0000 then line is considered to be visible [Case of Trivial
Acceptance] else Perform AND operation on both endpoints.
Step4:If a line is clipped case, find an intersection with boundaries of the window
Intersection points with a clipping boundary can be calculated using the slope-intercept
form of the line equation.
For a line with endpoint coordinates (x1, y1) and (x2, y2), the y coordinate of the
intersection point with a vertical boundary can be obtained with the calculation
y = y1 + m(x-x1)
B x2,y2
[y-y1/x-x1 = y2-y1/x2-x1
x, y D
y-y1 = (x-x1)m
y = y1 + m(x-x1)] E
A C
x1,y1
where the x value is set either to or
x = x1 + (y-y1)/ m
[x-x1= y-y1/m
X = x1 + (y-y1)/m]
The point of intersection of the line segment with an extended window edge, each
of the four directions is tested in the order: left, right, top, bottom.
EXAMPLE
If the clipping window is XL = -4; XR = 4; YT = 4; YB = -4
Clip the lines: KL=(4,5)-(6,5) and AB=(1,1)-(1,3)
The solution :
For the line KL:
• code1 of (4,5) is 1000
• code2 of (6,5) is 1010
• code1 And code2 : 1000 And 1010 = 1000 ( not zero) then the line
KL is not visible, Trivial rejection
Sutherland-Hodgman
• The Sutherland-Hodgman polygon clipping algorithm clips a polygon against each edge
of the window, one at a time.
• Specifically for each window edge, it inputs a list of vertices and outputs a new list of
vertices which is submitted to the algorithm for clipping against the next window edge.
• The first window edge has as input the original set of vertices.
• After clipping against the last edge, the output list consists of the vertices describing the
clipped polygon
We can correctly clip a polygon by processing the polygon boundary as a whole against
each window edge.
This could be accomplished by processing all polygon vertices against each clip
rectangle boundary in turn.
Beginning with the initial set of polygon vertices, we could first clip the polygon
against the left rectangle boundary to produce a new sequence of vertices.
The new set of vertices could then successively passed to a right boundary clipper, a
bottom boundary clipper, and a top boundary clipper.
At each step, a new sequence of output vertices is generated and passed to the next
window boundary clipper.
Algorithm
For each window edge, we tack the input list of vertices for that edge, tests a pair of
consecutive vertices against a window edge to produce the output list of vertices. .
Approach
There are four possible cases of testing as illustrated in the below figure where testing is
performed against the left edge
4 CASES