Algorithm WPS Office
Algorithm WPS Office
1) First, define a window or View plane. Get coordinates from the user of a line.
2) Initialize the region code for initial and end coordinates of a line to 0000.
3) Check whether the line lies within, partially or outside the window.
Now, Assign the region code for both the initial and end coordinates.
After Assigning, If both the endpoints give 0000, then the line is completely within the window.
Else perform AND operation, if the result is not 0000, then the line is not inside the window and that line
would not be considered for clipping.
4) After confirming the line is partially inside the window, the next step is to find the intersection point
at the window boundary. By using the following formula:
x=x+(W_ymax-y)/slope ;
y=W_ymax;
x=x+(W_ymin-y)/slope ;
y=W_ymin;
y=y+(W_xmin-x)*slope,
x1=W_xmin;
y1=y1+(W_xmax-x1)*slope ,
x1=W_xmax
5) Now, overwrite the endpoint with a new one and update it.
6) Repeat 4th step till your line doesn’t get clipped completely.