Understanding Graphics Output Primitives and Coordinate Reference Frames

Slide Note
Embed
Share

Graphics output primitives and coordinate reference frames play a crucial role in describing scenes and drawing basic geometric structures in 2D space. These concepts involve defining points, drawing lines, and understanding pixel coordinates within a coordinate system. Absolute and relative coordinate specifications are also explored, providing insights into location relationships and plotting layouts. The use of Cartesian coordinates, screen coordinates, and OpenGL's gluOrtho2D function further enhances the understanding of world coordinate systems.


Uploaded on Oct 09, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Graphics Output Primitives Graphics Output Primitives 1

  2. Output Primitives Output Primitives Graphic SW and HW provide subroutines to describe a scene in terms of basic geometric structures called output primitives Output primitives are combined to form complex structures Simplest primitives Point (pixel) Line segment 2

  3. Coordinate Reference Frames Coordinate Reference Frames 2D image Use Cartesian coordinates We label the two axes as X (horizontal) Y (vertical) Origin is in the lower left We call this space the world coordinate system +Y Y Axis (0,0) +X X Axis 3

  4. Coordinate Reference Frames Coordinate Reference Frames +Y 1) Define a set of points (vertices) in 2D space. (2,7) (9,7) 2) Given a set of vertices, draw lines between consecutive vertices. (2,1) (9,1) +X Screen Coordinates references to frame buffer locations 4

  5. Coordinate Reference Frames Coordinate Reference Frames Screen coordinates Location of object on a monitor Start from upper left corner (origin (0,0)) Pixel coordinates Scan line number (y) Column number (x) Pixel coordinate references the center of the pixel setPixel (x, y) getPixel (x, y, color) depth value is 0 in 2D 5

  6. Coordinate Reference Frames Coordinate Reference Frames 6

  7. Absolute and Relative Coordinate Absolute and Relative Coordinate Specifications Specifications +Y Absolute coordinates location specified as a relationship to the origin Relative coordinates location specified as a relationship to other points Good for pen/plotters Publishing/layout For this course we always use absolute coordinates (0,6) (7,0) (2,1) (0,-6) 7

  8. Specifying a World Coordinate System in Specifying a World Coordinate System in OpenGL OpenGL +Y +X gluOrtho2D (xmin, xmax, ymin, ymax) The display window will then refrenced by coordinates (xmin,ymin) at the lower left corner and by coordinates (xmax, ymax) at the upper left corner (Equivalent to the size of the framebuffer) 8

  9. Specifying a World Coordinate Specifying a World Coordinate System in OpenGL System in OpenGL gluOrtho2D (xMin, xMax, yMin, yMax) References display window as a rectangle with the minimum and maximum values listed Absolute coordinates within these ranges will be displayed gluOrtho2D(0.0, 200.0, 0.0, 150.0); // set coordinate values // with vertices (0,0) for lower left corner // and (200, 150) for upper right corner 9

  10. What is a What is a pixel pixel ? ? From a geometry point of view, a pixel is a point. 3 2 1 1 2 3 4 5 0 10

  11. But when we think about images, a pixel is a rectangle. 2 1 0 0 1 2 3 4 11

  12. Basic Basic OpenGL Point Structure OpenGL Point Structure In OpenGL, to specify a point: glVertex*(); In OpenGL, some functions require both a dimensionality and a data type glVertex2i(80,100), glVertex2f(58.9, 90.3) glVertex3i(20,20,-5), glVertex3f(-2.2,20.9,20) Must put within a glBegin/glEnd pair glBegin(GL_POINTS); glVertex2i(50,50); glVertex2i(60,60); glVertex2i(60,50); glEnd(); 12

  13. Line Functions Line Functions Line: Defined by two endpoint coordinates (one line segment) glBegin( GL_LINES ); glVertex2i( 180, 15 ); glVertex2i( 10, 145 ); glEnd(); If several vertices, a line is drawn between the first and second, then a separate one between the third and the fourth, etc. 13

  14. Draw a line from Draw a line from 0,0 0,0 to to 4,2 4,2 (4,2) 2 1 (0,0) 0 0 1 2 3 4 14

  15. The Ideal Line The Ideal Line What do we want? Straight lines should appear as a straight line Uniform thickness and brightness primitives should start and end accurately Pixels near the ideal line are on Lines should be drawn rapidly (17,8) (2,2) Discretization - converting a continuous signal into discrete elements. Scan Conversion - converting vertex/edges information into pixel data for display 15

  16. Line Drawing Algorithms Line Drawing Algorithms Line drawn as pixels Graphics system Projects the endpoints to their pixel locations in the frame buffer (screen coordinates as integers) Finds a path of pixels between the two Loads the color Plots the line on the monitor from frame buffer (video controller) Rounding causes all lines except horizontal or vertical to be displayed with low resolution 16

  17. Line Drawing Algorithms ( Line Drawing Algorithms (slope intercept method) method) slope intercept Line equation Slope-intercept form y = m . x + b slope m Y-intercept b Slope y - y y end 0 m = = x - x end 0 x Y-intercept b = y - mx 0 0 17

  18. Line Drawing Algorithms Line Drawing Algorithms DDA (Digital Differential Analyzer) Scan conversion line algorithm Line sampled at regular intervals of x, then corresponding y is calculated From left to right if m 1, y = y + m ( = 1 ) k + 1 k x 1 if m > 1.0, x = x + ( = 1 ) k + 1 k y m 18

  19. Line Drawing Algorithms Line Drawing Algorithms Advantage Does not calculate coordinates based on the complete equation (uses offset method) Disadvantage Round-off errors are accumulated, thus line diverges more and more from straight line Round-off operations take time Perform integer arithmetic by storing float as integers in numerator and denominator and performing integer arithmetic. 19

  20. Bresenham Bresenham s s Line Algorithm Line Algorithm Bresenham s line drawing Efficient line drawing algorithm using only incremental integer calculations Can be adapted to draw circles and other curves Principle Vertical axes show scan line positions Horizontal axes show pixel columns At each step, determine the best next pixel based on the sign of an integer parameter whose value is proportional to the difference between the vertical separations of the two pixel positions from the actual line. 20

  21. Bresenhams Line Algorithm Bresenham s line drawing algorithm (positive slope less than 1) 1. Input the two line end points and store the left point as (?0,?0) 2. Set the color of the frame buffer position (?0,?0), i.e. plot the first point 3. Calculate the constants ?, ?, and obtain the starting value of the decision parameter as ?0= 2 ? ? 4. At each ??along the line perform the following test if ??< 0 the next point to be plot is (??+ 1,?) and ??+1= ??+ 2 ? , otherwise the next point to be plot is (??+ 1,??+ 1) and ??+1= ??+ 2 ? 2 ? 5. Perform step 4 ?-1 times 21

  22. Example Example 3 3- -1 1 page page 97 97 Suppose the line with endpoints (20,10) and (30,18) The line has a slope of 0.8 (m< 1), with: x = 10, y = 8 The initial decision parameter has the value: P0 = 2 y - x = 6 22

  23. Example Example 3 3- -1 1 page page 97 97 Since p0is positive Next point (21,11) P1= 6 + 2*8 2*10 = 2 Since P1is positive Next point (22,12) P2= 2 + 2*8 -2*10 = -2 Since P2is negative Next point (23,12) P3= -2 + 2*8 = 14 23

  24. Example Example 3 3- -1 1 page page 97 97 Since p3is positive Next point (24,13) P4= 14 + 2*8 2*10 = 10 Since P4is positive Next point (25,14) P5 = 10 + 2*8 -2*10 = 6 Since P5is positive Next point (26,15) P6= 6 + 2*8 -2*10 = 2 24

  25. Example Example 3 3- -1 1 page page 97 97 Since p7is positive Next point (27,16) P8= 2 + 2*8 2*10 = -2 Since P8is negative Next point (28,16) P9= -2 + 2*8 = 14 Since P9is positive Next point (29,17) P10= 14 + 2*8 -2*10 = 10 Since P10is positive Next point (30,18) 25

  26. Example Example 3 3- -1 1 page page 97 97 K Pk Yk+1,xk+1 (21,11) 0 6 1 2 (22,12) 2 -2 (23,12) 3 14 (24,13) 4 10 (25,14) 5 6 (26,15) 6 2 (27,16) 7 -2 (28,16) 8 14 (29,17) 9 10 (30,18) 26

  27. Example Example 3 3- -1 1 page page 97 97 The generated line: 27

  28. Curve Functions Curve Functions Primitive functions to display circles and ellipses are not provided in OpenGL core library (GL). GLU has primitives cylinders, GLUT has some of these primitives too. Circles and ellipses can also be generated by approximating them using a polyline. Can also be generated by writing own circle or ellipsis display algorithm. to display spheres, 28

  29. Circle Algorithms Circle Algorithms Properties of circles: 2 2 2 (x x - ) + (y y - ) = r c from c steps x - r to x + r c c 2 2 y = y r - (x - x ) c c 29

  30. Circle Algorithms Circle Algorithms 30

  31. Circle Midpoint Algorithm Circle Midpoint Algorithm x+ (0,R) y+ x=y draw pixels in this octant (draw others using symmetry) (-R,0) (R,0) (0,-R) 31

  32. Mid Mid- -point circle algorithm point circle algorithm For a given radius r and screen center position (xc, yc), we can first set up our algorithm to calculate pixel positions around a circle path centered at the coordinate origin ( 0, 0 ) Then each calculated position (x, y) is moved to its proper screen position by adding xcto x and ycto y 32

  33. Mid Mid- -point circle algorithm point circle algorithm Along the circle section from x = 0 to x = y in the first quadrant, the slope of the curve varies from 0 to 1. Therefore, we can take unit steps in the positive x direction over this octant and use a decision parameter to determine which of the two possible y positions is closer to the circle path at each step. 33

  34. Mid Mid- -point circle algorithm point circle algorithm The first octant of the circle can be drawn through the following steps: 1. Input the radius ? and the center point (??,??), then set the first point of the circumference of the circle (?0,?0) to be (0,?) 2. Calculate the initial value of the decision as ?0=5 3. At each ??, perform the following test if ??< 0 the next point to be plot is (??+ 1,?) and ??+1= ??+ 2??+1+ 1 otherwise the next point to be plot is (??+ 1,?? 1) and ??+1= ??+ 2??+1+ 1 2??+1 4. Determine symmetry points in the other seven octants 5. Move each calculated pixel position (?,?) onto the circular path centered at (??,??) and plot the coordinate values: ? = ? + ??,? = ? + ?? 6. Repeat steps 3 through 5 until x >= y. 4 ? 34

  35. Mid Mid- -point point circle Example ( circle Example (page page 107 107) ) Given a Circle radius r=10 centered at (0,0) x=0 ; y=10 ; r=10 ?0=1 10= 9 ?1= 9+2+1= 6 ?2= 6+4+1=-1 ?3=-1+6+1=6 ?4=6+8+1-18=-3 ?5=-3+10+1=8 ?6=8+12+1-16=5 plot (7,7) plot (0,10) plot (1,10) plot (2,10) plot (3,10) plot (4,9) plot (5,9) plot (6,8) 35

Related