



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Computer Graphics involves technology to accept, process, transform and present information in a visual form that also concerns with producing images and animations using a computer. This course teach how to make your own design in computer using OpenGl. This lecture includes: Clipping, Rectangle, Point, Line, Solve, Simultaneous, Equations, Interior
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Concept
It is desirable to restrict the effect of graphics primitives to a sub-region of the canvas, to protect other portions of the canvas. All primitives are clipped to the boundaries of this clipping rectangle ; that is, primitives lying outside the clip rectangle are not drawn.
The default clipping rectangle is the full canvas (the screen), and it is obvious that we cannot see any graphics primitives outside the screen.
A simple example of line clipping can illustrate this idea:
This is a simple example of line clipping: the display window is the canvas and also the default clipping rectangle, thus all line segments inside the canvas are drawn.
The red box is the clipping rectangle we will use later, and the dotted line is the extension of the four edges of the clipping rectangle.
Point Clipping Assuming a rectangular clip window, point clipping is easy. we save the point if:
x (^) min <= x <=x (^) max y (^) min <= y <= y (^) max
Line Clipping This section treats clipping of lines against rectangles. Although there are specialized algorithms for rectangle and polygon clipping, it is important to note that other graphic primitives can be clipped by repeated application of the line clipper.
Clipping Individual Points Before we discuss clipping lines, let's look at the simpler problem of clipping individual points. If the x coordinate boundaries of the clipping rectangle are Xmin and Xmax, and the y coordinate boundaries are Ymin and Ymax, then the following inequalities must be satisfied for a point at (X, Y) to be inside the clipping rectangle: Xmin < X < Xmax
and
Ymin < Y < Ymax
If any of the four inequalities does not hold, the point is outside the clipping rectangle. Trivial Accept - save a line with both endpoints inside all clipping boundaries. Trivial Reject - discard a line with both endpoints outside the clipping boundaries. For all other lines - compute intersections of line with clipping boundaries.
Parametric representation of a line:
x = x1 + u (x2 - x1) y = y1 + u (y2 - y1), and 0 <= u <= 1. If the value of u for an intersection with a clipping edge is outside the range 0 to 1, then the line does not enter the interior of the window at that boundary. If the value of u is within this range, then the line does enter the interior of the window at that boundary.
Solve Simultaneous Equations To clip a line, we need to consider only its endpoints, not its infinitely many interior points. If both endpoints of a line lie inside the clip rectangle (eg AB, refer to the first example ), the entire line lies inside the clip rectangle and can be trivially accepted. If one endpoint lies inside and one outside(eg CD), the line intersects the clip rectangle and we must compute the intersection point. If both endpoints are outside the clip rectaangle, the line may or may not intersect with the clip rectangle (EF, GH, and IJ), and we need to perform further calculations to determine whether there are any intersections. The brute-force approach to clipping a line that cannot be trivially accepted is to intersect that line with each of the four clip-rectangle edges to see whether any intersection points lie on those edges; if so, the line cuts the clip rectangle and is partially inside. For each line and clip-rectangle edge, we therefore take the two mathematically infinite lines that contain them and intersect them. Next, we test whether this intersection point is "interior" -- that is, whether it lies within both the clip rectangle edge and the line; if so, there is an intersection with the clip rectangle. In the first example, intersection points G' and H' are interior, but I' and J' are not.
u (^) * pk <= qk , for k = 1, 2, 3, 4
Where parameters p and q are defined as:
p 1 = -x, q 1 = x 1 - x (^) min p 2 = -x, q 2 = xmax - x (^1) p 3 = -y, q 3 = y 1 - y (^) min p 4 = -y, q 4 = y (^) max - y (^1)
Any line that is parallel to one of the clipping boundaries has p (^) k = 0 for the value of k corresponding to that boundary (k = 1, 2, 3, 4 correspond to the left, bottom, and top boundaries, respectively). If, for that value of k, we also find qk >= 0, the line is inside the parallel clipping boundary.
When pk < 0, the infinite extension of the line proceeds from the outside to the inside of the infitite extension of the particular clipping boundary. If p (^) k > 0, the line proceeds from the inside to the outside. For a nonzero value of p (^) k = 0, we can calculate the value of u that corresponds to the point where the infinitely extended line intersects the extension of boundary k as:
u = qk / pk
For each line, we can calculate values for parameters u 1 and u 2 that defines that part of the line that lies within the clip rectangle. The value of u 1 is determined by looking at the rectangle edges for which the line proceeds from the outer side to the inner side. (p < 0). For these edges we calculate r (^) k = q (^) k / pk.
The value of u 1 is taken as the largest of the set consisting of o and the various values of r. Conversely, the value of u 2 is determined by examining the boundaries for which the line proceeds from inside to outside (p > o). A value of rk is calculated for each of these boundaries and the value of u 2 is the minimum of the set consisting of 1 and the calculated r values. If u 1 > u 2 , the line is completely outside the clip window and it can be rejected. Otherwise, the end points of the clipped line are calculated from the two values of parameter u.
This algorithm is presented in the following procedure. Line intersection parameters are initialized to the values u 1 = 0 and u 2 = 1. For each clipping boundary, the appropriate values for p and q are calculated and used by the function clipTest to determine whether the line can be rejected or whether the intersection parameters are to be adjusted.
When p < 0, the parameter r is used to update u 1 ; when p < 0, the parameter r is used to update u 2.
If updating u 1 or u 2 results in u 1 > u 2 , we reject the line.
Otherwise, we update the appropriate u parameter only if the new value results in a shortening of the line.
When p = 0 and q < 0, we can discard the line since it is parallel to and outside of this boundary.
If the line has not been rejected after all four values of p and q have been tested, the endpoints of the clipped line are determined from values of u 1 and u 2.
Conclusion
In general, the Liang-Barsky algorithm is more efficient than the Cohen Sutherland algorithm, since intersection calculations are reduced. Each update of parameters u 1 and u 2 requires only one division; and window intersections of the line are computed only once, when the final values of u 1 and u 2 have computed. In contrast, the Cohen- Sutherland algorithm can repeatedly calculate intersections along a line path, even though the line may be completely outside the clip window, and, each intersection calculation requires both a division and a multiplication. Both the Cohen Sutherland and the Liang Barsky algorithms can be extended to three-dimensional clipping.