1 / 25

Computer Graphics using OpenGL, 3 rd Edition F. S. Hill, Jr. and S. Kelley

Computer Graphics using OpenGL, 3 rd Edition F. S. Hill, Jr. and S. Kelley. Chapter 3 Additional Drawing Tools PART II. Clipping Lines. We want to draw only the parts of lines that are inside the world window.

conor
Download Presentation

Computer Graphics using OpenGL, 3 rd Edition F. S. Hill, Jr. and S. Kelley

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Graphics using OpenGL, 3rd EditionF. S. Hill, Jr. and S. Kelley Chapter 3 Additional Drawing Tools PART II

  2. Clipping Lines • We want to draw only the parts of lines that are inside the world window. • To do this, we need to replace line portions outside the window by lines along the window boundaries. The process is called clipping the lines.

  3. Clipping • The method we will use is called Cohen-Sutherland clipping. • There are 2 trivial cases: a line AB totally inside the window, which we draw all of, and a line CD totally outside the window, which we do not draw at all.

  4. Clipping • For all lines, we give each endpoint of the line a code specifying where it lies relative to the window W:

  5. Clipping • The diagram below shows Boolean codes for the 9 possible regions the endpoint lies in (left, above, below, right).

  6. Clipping • A line consists of 2 endpoints (vertices), P1 and P2. If we do not have a trivial case, we must alter the vertices to the points where the line intersects the window boundaries (replace P1 by A).

  7. Clipping • In the diagram, d/dely = e/delx (similar triangles). • Obviously, A.x = W.r. • Also, delx = p1.x – p2.x, dely = p1.y – p2.y and e = p1.x – W.r. • So A.y = p1.y – d.

  8. Clipping • New Point p1 (A) must be computed: its x-coordinate is clearly w.r, but y-coordinate requires adjusting p1.y by the amount d • e = p1.x – W.right • delx = p2.x – p1.x; • dely = p2.y – p1.y; • d = e/delx * dely; • p1.y += (W.right – p1.x) * dely/delx

  9. Clipping • Similar reasoning is used for clipping against the other three edges of the window.

  10. A Line Needing 4 Clips A situation that requires all four clips. • The first clip changes P1 to A; • The second alters P2 to B; • The third finds P1 still outside and below and so changes A to C; • The last changes P2 to D. • For any choice of ordering for the chopping tests, there will always be a situation in which all 4 clips are necessary.

  11. Clipping • These ideas are collected in the routine clipSegment(). The endpoints of the segment are passed by reference, since changes made to the endpoints by clipSegment() must be visible in the calling routine

  12. Cohen-Sutherland Clipping Algorithm

  13. Cohen-Sutherland Clipping Algorithm • Each time through the do loop the code for each endpoint is recomputed and tested. • When trivial acceptance and rejection fail, the algorithm tests whether p1 is outside, and so, it clips that end of the segment to a window boundary. If p1 is inside, then p2 must be outside, so p2 is clipped to a window boundary. • This version of the algorithm clips in the order left, then right, then bottom, and then top.

  14. Drawing Regular Polygons, Circles, and Arcs • A polygon is regular if it is simple, if all its sides have equal length, and if adjacent sides meet at equal interior angles. • A polygon is simple if no two of its edges cross each other. More precisely, only adjacent edges can touch and only at their shared endpoint. • We give the name n-gon to a regular polygon having n sides; familiar examples are the 4-gon (a square), an 8-gon (a regular octagon) and so on.

  15. Regular Polygons

  16. Drawing Circles and Arcs • Two methods: • The center is given, along with a point on the circle. • Here drawCircle( IntPoint center, int radius) can be used as soon as the radius is known. If c is the center and p is the given point on the circle, the radius is simply the distance from c to p, found using the usual Pythagorean Theorem.

  17. Drawing Circles and Arcs • Three points are given through which the circle must pass. • It is known that a unique circle passes through any three points that don't lie in a straight line. • Finding the center and radius of this circle is discussed in Chapter 4.

More Related