Line Clipping :The concept of line clipping is the same as point clipping. In line clipping we will cut the portion of line which is outside the window and keep only the portion that is inside the window.
Cohen's- Sutherland Line clipping is one of the oldest line clipping procedures.
In this method we divide the whole space in to nine region and assign 4 bit code to each endpoint of line depending on the position where the endpoint is located.
Cohen's- Sutherland Line clipping is one of the oldest line clipping procedures.
In this method we divide the whole space in to nine region and assign 4 bit code to each endpoint of line depending on the position where the endpoint is located.
These 4 bits represent the top, bottom, right and left respectively as shown in the figure.
- If the end point is top the top bit is set to 1 else set it to zero(first bit).
- if the end point is to the bottom set the bottom bit to 1 else set it to zero(second bit).
- If the end point is to the right set the right bit to 1 else set it to zero (third bit).
- If the end point is to the left set the left bit to 1 else set it to zero (fourth bit).
Algorithm
Step 1 − Assign a region code for each endpoints.
Step 2 − If logical OR of 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 .
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.
To calculate intersection points on boundary we make use of line equation "y=mx+b"
where m=(y2-y2)(x2-x1).
For left and right boundaries, x coordinates are constant, for left x=xwmin and for right x=xwmax.
where xwmin and xwmax are the minimum and the maximum x values of the window.
We calculate the y coordiante of intersection for this boundary by putting the values of x as follow:
y=y1+m(x-x1).
Similarly for top and bottom boundaries y coordinate is constant, for bottom y=ywmin and for y=ywmax.
we calculate the x coordinate of intersection for this boundary by putting the value of y as follow:
x=x1+(y-y1)/m.
Advantages of Cohen-sutherland line clipping:
- it calculates end-points very quickly , and rejects and accepts lines quickly.
- It can clip pictures much larger than the screen size.
arigato gozaimasu sensei ^_^
ReplyDelete