GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.

Slides:



Advertisements
Similar presentations
Graphics Primitives: line
Advertisements

CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
Section 3-1 to 3-2, 3-5 Drawing Lines Some of the material in these slides may have been adapted from university of Virginia, MIT, and Åbo Akademi University.
CS 376 Introduction to Computer Graphics 02 / 02 / 2007 Instructor: Michael Eckmann.
Computer Graphics 4: Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling By:Kanwarjeet Singh.
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphics Drawing Elementary Figures Dr. Eng. Farag Elnagahy.
CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
+ CPCS 391 Computer Graphics 1 Instructor: Dr. Sahar Shabanah Lecture 3.
Lecture 5 Rendering lines 1.Steps of line rendering 2.Scan-conversion for line segments 3.A1 tutorial CP411 Computer Graphics Fall 2007 Wilfrid Laurier.
Scan Conversion Algorithms
Scan conversion of Line , circle & ellipse
Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing.
Larry F. Hodges (modified by Amos Johnson) 1 Design of Line, Circle & Ellipse Algorithms.
30/9/2008Lecture 21 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD3107 University of Palestine.
The lines of this object appear continuous However, they are made of pixels 2April 13, 2015.
CS 376 Introduction to Computer Graphics 01 / 29 / 2007 Instructor: Michael Eckmann.
OUTPUT PRIMITIVES Screen vs. World coordinate systems ● Objects positions are specified in a Cartesian coordinate system called World Coordinate.
In the name of God Computer Graphics Bastanfard.
Raster conversion algorithms for line and circle
Output Primitives Computer Graphics.
Course Website: Computer Graphics 5: Line Drawing Algorithms.
Line Drawing by Algorithm. Line Drawing Algorithms Line drawn as pixels Graphics system –Projects the endpoints to their pixel locations in the frame.
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
Circle Drawing algo..
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
Dr. S.M. Malaek Assistant: M. Younesi
Graphics Primitives: line. Pixel Position
WHERE TO DRAW A LINE?? Line drawing is accomplished by calculating intermediate positions along the line path between specified end points. Precise definition.
Scan Conversion Line and Circle
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
CS 325 Introduction to Computer Graphics 02 / 01 / 2010 Instructor: Michael Eckmann.
Larry F. Hodges 1 Design of Line and Circle Algorithms.
Objectives Differentiate between raster scan display and random scan display.
Introduction Computer Graphics & Its application Types of computer graphics Graphic display : random Scan & Raster Scan display Frame buffer and video.
Graphics Output Primitives
CGMB214: Introduction to Computer Graphics
 A line segment in a scene is defined by the coordinate positions of the line end-points x y (2, 2) (7, 5)
Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization.
Graphics Output Primitives Hearn & Baker Chapter 3
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
1 CSCE 441 Lecture 2: Scan Conversion of Lines Jinxiang Chai.
In the name of God Computer Graphics. Today Introduction Sampling Graphic Output Primitives 1.Line 2.Circle 3.Curve 4.polygon.
Rendering.
Lecture 13: Raster Graphics and Scan Conversion
Bresenham’s Line Algorithm
OUTPUT PRIMITIVES A.Aruna/Faculty of Information technology/SNSCE13/19/2016.
Lecture 2: 19/4/1435 Graphical algorithms Lecturer/ Kawther Abas CS- 375 Graphics and Human Computer Interaction.
Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Write Bresenham’s algorithm for generation of line also indicate which raster locations would be chosen by Bresenham’s algorithm when scan converting.
Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
Computer Graphics Lecture 06 Circle Drawing Techniques Taqdees A. Siddiqi
Scan Conversion of Line Segments. What is Scan conversion? Final step of rasterization (the process of taking geometric shapes and converting them into.
Computer Graphics : output primitives.. 2 of 32 T1 – pp. 103–123, 137–145, 147–150, 164–171 Points and LinesPoints Line Drawing AlgorithmsLine Mid–Point.
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
Computer Graphics Lecture 05 Line Drawing Techniques Taqdees A. Siddiqi
Line Drawing Algorithms 1. A line in Computer graphics is a portion of straight line that extends indefinitely in opposite direction. 2. It is defined.
Objectives Understand Bresenhams line drawing algorithm. Apply the algorithm to plot a line with the end points specified.
Primitive graphic objects
Raster Graphics.
Lecture 9 Line Drawing Algorithms (Bresenham’s Line Algorithm)
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Lecture 8 Shear and Line Drawing Algorithms
Chapter Three Part I Output Primitives CS 380.
Scan Conversion (From geometry to pixels)
Chapter 3 Graphics Output Primitives
Primitive Drawing Algorithm
Primitive Drawing Algorithm
Line Drawing Algorithms
Presentation transcript:

GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2

Points and Lines  Point plotting is accomplished by  converting a single coordinate position furnished by an application program into appropriate operations for the output device in use.  With a CRT monitor, for example, the electron beam is turned on to illuminate the screen phosphor at the selected location.  How the electron beam is positioned depends on the display technology  Raster scan display or  Random scan display  Line drawing is accomplished by calculating intermediate positions along the line path between two specified endpoint positions.  An output device is then directed to fill in these positions between the endpoints.

Points and Lines (cont…)  Digital devices display a straight line segment by plotting discrete points between the two endpoints.  Discrete coordinate positions along the line path are calculated from the equation of the line.  For a raster video display, the line color (intensity) is then loaded into the frame buffer at the corresponding pixel coordinates.  Reading from the frame buffer, the video controller then "plots" the screen pixels.  Screen locations are referenced with integer values, so plotted positions may only approximate actual Line positions between two specified endpoints.  Computed line position of (10.48,20.51), for example, would be converted to pixel position (10,21).

Points and Lines(cont…)  This rounding of coordinate values to integers causes lines to be displayed with a stair step appearance ("the jaggies).  The characteristic stair step shape of raster lines is particularly noticeable on systems with low resolution, and we can improve their appearance somewhat by displaying them on high- resolution systems.  More effective techniques for smoothing raster lines are based on adjusting pixel intensities along the line paths.

Points and Lines(cont…)

Line Drawing Algorithm…  Basic of Line drawing  The Cartesian slope-intercept equation for a straight line is Y = mX + C ……….(1)  with m representing the slope of the line and C is constant.  Given that the two endpoints of a line segment are specified at positions (X1, Y1) and (X2, Y2), as shown in Fig. 3-3,  we can determine values for the slope m, m = (Y2 – Y1)/(X2 – X1)…………………(2) And C with the following calculations: C=Y1 - m*X1……………………………...(3)  Algorithms for displaying straight line are based on the line equation 1 and the calculations given in Eqs. 2 and 3.  For any given x interval ∆x along a line, we can compute the corresponding y interval using ∆Y = m * ∆X ……(4)  Similarly, we can obtain the x interval ∆x corresponding to a specified ∆y as ∆X = ∆Y / m……..(5)  These equations form the basis for determining deflection voltages in analog devices

 vices. For lines with slope magnitudes |m| < 1, ∆X can be set proportional to a small horizontal deflection voltage and  The corresponding vertical deflection is then set proportional to ∆Y as calculated from Eq. 4.  For lines whose slopes have magnitudes |m| > 1, ∆Y can be set proportional to a small vertical deflection voltage with the corresponding horizontal deflection voltage set proportional to ∆X, calculated from Eq. 5.  For lines with m = 1, ∆X = ∆Y and the horizontal and vertical deflections voltages are equal.  In each case, a smooth line with slope m is generated between the specified endpoints. Line Drawing Algorithm…

DDA for line drawing  Digital Differential Analyzer (DDA)  Its scan-conversion line algorithm based on calculating either ∆X or ∆Y using Eq. 4 or Eq. 5.  We sample the line at unit in one coordinate and determine corresponding integer values nearest the line path for the other coordinate.  A line with positive slope,  If the slope is less than or equal to 1,  we sample at unit x intervals (∆x = 1) and compute each successive y value as Y k+1 = Y k + m ……………………..(6)  Subscript k takes integer values starting from 1, for the first point, and increases by 1 until the final endpoint is reached. Since m can be any real number between 0 and 1, the calculated Y values must be rounded to the nearest integer.  For lines with a positive slope greater than 1, we reverse the roles of x and y.  That is, we sample at unit Y intervals (∆y = 1) and calculate each succeeding x value as X k+1 = X k + (1/m) …………………(7)  Equ. 6 and 7 are based on the assumption that lines are to be processed from the left endpoint to the right endpoint.  If this processing is reversed, so that the starting endpoint is at the right, then either we have ∆x = -1 and Y k+1 = Y k - m ……………………..(8)

 or (when the slope is greater than 1) we have ∆Y = -1 with X k+1 = X k - (1/m) …………………(9)  Eq. 6 through 9 can also be used to calculate pixel positions along a line with negative slope.  If the absolute value of the slope is less than I and the start endpoint is at the left, we set ∆X = 1 and calculate Y values with Eq. 6.  When the start endpoint is at the right (for the same slope), we set ∆X = -1 and obtain Y positions from Eq. 8.  Similarly, when the absolute value of a negative slope is greater than 1,we use ∆Y = -1 and Eq. 9 or we use ∆Y = 1 and Eq. 7. DDA for line drawing

DDA Line Drawing Algo… void lineDDA (int xa, int ya, int xb, int yb) { int dx = xb - xa, dy = yb - ya, steps, k; float xIncrement, yIncrement, x = xa, y = ya; if (abs(dx) > abs(dy) ) steps = abs(dx); else steps = abs(dy); xIncrement = dx / (float) steps; yIncrement = dy / (float) steps; setpixel (ROUND(x), ROUND(y)); for (k=O; k<steps; k++) { x += xIncrment; y += yIncrement; setpixel (ROUND(x), ROUND(y)); }}

Drawback of DDA  Round off error in successive additions of the floating-point increment, however, can cause the calculated pixel positions to drift away from the true line path for long line segments.  The rounding operations and floating point arithmetic in procedure lineDDA are still time- consuming

Bresenham's Line Algorithm  An accurate and efficient raster line-generating algorithm  Fig. display screen where straight line segments are to be drawn.  The vertical axes show-scan-line positions, and the horizontal axes identify pixel columns.  Sampling at unit x intervals in this example, we need to decide which of two possible pixel positions is closer to the line path at each step.  Starting from the left endpoint shown in Fig., we need to determine at the next sample position whether to plot the pixel at position (11, 11) or the one at (11, 12)

 Assuming we have determined that the pixel at (x k, y k ) is to be displayed, we next need to decide which pixel to plot in column x k+1.  Our choices are the pixels at positions (x k +1, y k ) and (x k +1, y k +1).  At sampling position x k +1, we label vertical pixel separations from the mathematical line path as d1 and d2.  The y coordinate on the mathematical line at pixel column position x k +1 is calculated as Bresenham's Line Algorithm

 Y = m * (x k +1) + b  Then  d1 = y – y k  = m * (x k +1) + b – y k  d2 = (y k + 1) - y = (y k + 1)- m * (x k +1) - b The distance between two separation is d1 – d2 = 2m * (x k +1)- 2y k + 2b – 1  A decision parameter p k for the k th step in the line algorithm can be obtained by rearranging above equation so that it involves only integer calculations.  We accomplish this by substituting m = ∆y/∆x, where ∆y and ∆x are the vertical and horizontal separations of the endpoint positions, and defining: p k = ∆x (d1 – d2) = ∆x *( 2 ∆y/∆x (x k +1)- 2y k + 2b – 1 ) = 2∆y x k + 2∆y - 2 ∆x y k + ∆x( 2b – 1 ) = 2∆y x k - 2∆x y k + c (1) Bresenham's Line Algorithm

 The sign of p k, is the same as the sign of dl – d2, since ∆x > 0 for our example. Parameter c is constant and has the value 2∆y + ∆x(2b - l), which is independent of pixel position and will be eliminated in the recursive calculations for p k.  If the pixel at y k is closer to the line path than the pixel at y k +l (that is, dl < d2), then decision parameter pk is negative.  In that case, we plot the lower pixel; otherwise, we plot the upper pixel.  Coordinate changes along the line occur in unit steps in either the x or y directions.  Therefore, we can obtain the values of successive decision parameters using incremental integer calculations.  At step k + 1, the decision parameter is evaluated from Eq. 1 as p k+1 = 2∆y x k+1 - 2∆x y k+1 + c (2) Now subtracting eq. 1 from 2 p k+1 - p k = 2∆y( x k+1 – x k ) - 2∆x (y k+1 – y k )+ c But x k+1 = x k + 1, so that p k+1 = p k + 2∆y - 2∆x (y k+1 – y k ) where the term y k+1 - y k is either 0 or 1, depending on the sign of parameter p k. Bresenham's Line Algorithm

 This recursive calculation of decision parameters is performed at each integer x position, starting at the left coordinate endpoint of the line.  The first parameter, p 0, is evaluated from Eq. 1 at the starting pixel position (x 0, y 0 ) and with m evaluated as ∆y/∆x p 0 = 2∆y - ∆x Bresenham's Line Algorithm

Bresenham's Line-Drawing Algorithm for I m | < 1 1. Input the two line endpoints and store the left endpoint in (x0, y0) 2. Load (x0, y0) into the frame buffer; that is, plot the first point. 3. Calculate constants ∆x, ∆y, 2∆y, and 2∆y - 2∆x, and obtain the starting value for the decision parameter as p 0 = 2∆y - ∆x 4. At each x k along the line, starting at k = 0, perform the following test: If P k < 0, the next point to plot is (x k + 1, y k ) and P k+I = P k + 2∆y Otherwise, the next point to plot is (x k + 1, y k + 1) and p k+1 = p k + 2∆y - 2∆x 5. Repeat step 4 ∆x times. Bresenham's Line Algorithm

void lineares (int xa, i:it ya, int xb, int yb) { int dx = abs (xa - xbl, dy = abs (ya - yb): int p = 2 * dy - dx; int twoDy = 2 ' dy, twoDyDx = 2 ' ldy - Ax); int x, y, xEnd: /* Determine which point to use as start, which as end */ if (xa > xb) { x = xb; y = yb; xEnd = xa;  } else {x = xa; y = ya; xEnd = xb; } Bresenham's Line Algorithm

setpixel (x, y); while (x < xEnd) { x++; if (p < 0) p += twoDy; else { y++; p += twoDyDx; } setpixel (x, y); } Bresenham's Line Algorithm