Upload
rehan-khan
View
77
Download
0
Embed Size (px)
Citation preview
0000 00100001
1001
0101 0100
1000 1010
0110
ymax
ymin
Cohen-sutherland line clipping
Every line end point in a picture is assigned a four-digit binary code, called a region code.
Divide the plane into regions defined by viewport (an area on the display device
where the window is mapped) edges• Assign each region a 4bit code.• Set the bits with simple tests likeX>XmaxY<YminAssign a code to each vertex of line.Once the region codes for all the line
endpoints are known, we can determine which lines are completely inside the clip window or completely outside.
The lines which are completely inside the window boundaries, they have a region code of 0000 for both the endpoints. Hence we accept these lines.
• Any line that has 1 in the same bit position in the region code for each end point and are completely outside the clipping rectangle, we reject the lines.
• Lines are tested for total clipping by performing the logical AND operation with both region codes.
• If the result is 0000, the line is neither outside nor inside.
So the algorithm checks the line end points against window boundaries like left, right,
bottom , top.
Intersection points are calculated using equation parameters.
• The y co-ordinate of the intersection point with a vertical boundary can be calculated as :
• Y=y1+m(x-x1)
• Where x=xmin or xmax
• And the slope of the line is
• M= (y2-y1)
(x2-x1)
• Similarly, the intersection point with a horizontal boundary, can be calculated as
x=x1+ (y2-y1)
m
Where y=ymin or ymax
• Similarly, the intersection point with a horizontal boundary, can be calculated as
x=x1+ (y2-y1)
m
Where y=ymin or ymax