7
0000 0010 0001 1001 0101 0100 1000 1010 0110 y max y min Cohen-sutherland line clipping Every line end point in a picture is assigned a four-digit binary code, called a region code.

Cohen and Sutherland Algorithm for 7-8 marks

Embed Size (px)

Citation preview

Page 1: Cohen and Sutherland Algorithm for 7-8 marks

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.

Page 2: Cohen and Sutherland Algorithm for 7-8 marks

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.

Page 3: Cohen and Sutherland Algorithm for 7-8 marks

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.

Page 4: Cohen and Sutherland Algorithm for 7-8 marks

So the algorithm checks the line end points against window boundaries like left, right,

bottom , top.

Page 5: Cohen and Sutherland Algorithm for 7-8 marks

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)

Page 6: Cohen and Sutherland Algorithm for 7-8 marks

• Similarly, the intersection point with a horizontal boundary, can be calculated as

x=x1+ (y2-y1)

m

Where y=ymin or ymax

Page 7: Cohen and Sutherland Algorithm for 7-8 marks

• Similarly, the intersection point with a horizontal boundary, can be calculated as

x=x1+ (y2-y1)

m

Where y=ymin or ymax