prev

next

out of 24

Published on

18-Oct-2015View

80Download

1

DESCRIPTION

Line and Circle Drawing Algorithms

Transcript

Line and Circle Drawing AlgorithmsTCSS458A Isabelle Bichindaritz Line Drawing AlgorithmsLine drawn as pixelsGraphics system Projects the endpoints to their pixel locations in the frame buffer (screen coordinates as integers)Finds a path of pixels between the twoLoads the colorPlots the line on the monitor from frame buffer (video controller)Rounding causes all lines except horizontal or vertical to be displayed as jigsaw appearance (low resolution)Improvement: high resolution, or adjust pixel intensities on the line path.TCSS458A Isabelle Bichindaritz Line Drawing AlgorithmsLine equationSlope-intercept form y = m . x + b slope m Y-intercept bSlopeY-interceptTCSS458A Isabelle Bichindaritz Line Drawing AlgorithmsDDA (Digital Differential Analyzer)Scan conversion line algorithmLine sampled at regular intervals of x, then corresponding y is calculatedFrom left to rightTCSS458A Isabelle Bichindaritz Line Drawing Algorithmsvoid lineDDA (int x0, int y0, int xEnd, int yEnd) { int dx = xEnd - x0, dy = yEnd - y0, steps, k; float xIncrement, yIncrement, x = x0, y = y0; if (fabs (dx) > fabs (dy)) steps = fabs (dx); else steps = fabs (dy); xIncrement = float (dx) / float (steps); yIncrement = float (dy) / float (steps); setPixel (round (x), round (y)); for (k = 0; k < steps; k++) { x += xIncrement; y += yIncrement; setPixel (round (x), round (y)); } }TCSS458A Isabelle Bichindaritz Line Drawing AlgorithmsAdvantageDoes not calculate coordinates based on the complete equation (uses offset method)DisadvantageRound-off errors are accumulated, thus line diverges more and more from straight lineRound-off operations take timePerform integer arithmetic by storing float as integers in numerator and denominator and performing integer artithmetic. TCSS458A Isabelle Bichindaritz Line Drawing AlgorithmsBresenhams line drawingEfficient line drawing algorithm using only incremental integer calculationsCan be adapted to draw circles and other curvesPrincipleVertical 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.TCSS458A Isabelle Bichindaritz Line Drawing Algorithms(from Donald Hearn and Pauline Baker)TCSS458A Isabelle Bichindaritz Line Drawing Algorithms(from Donald Hearn and Pauline Baker)TCSS458A Isabelle Bichindaritz Line Drawing AlgorithmsBresenhams line drawing algorithm (positive slope less than 1) dlower = y yk dupper = (yk + 1) y dlower dupper = 2m(xk+1) 2yk + 2b 1 decision parameter: pk= x (dlower dupper ) pk = 2y xk- 2x yk + c sign of pk is the same as sign of dlower dupper TCSS458A Isabelle Bichindaritz Line Drawing AlgorithmsBresenhams line drawing algorithm (positive slope less than 1Input the two line endpoints and store the left endpoint in (x0, y0).Set the color for the frame-buffer position (x0, y0) i.e. plot the first point.Calculate the constant 2y x, and set the starting value for the decision parameter as p0 = 2y x.At each xk along the line, from k=0, perform the following test: if pkCurve FunctionsSuch primitive functions as to display circles and ellipses are not provided in OpenGL core library.GLU has primitives to display spheres, cylinders, rational B-splines, including simple Bezier curves.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.TCSS458A Isabelle Bichindaritz Curve Functions(from Donald Hearn and Pauline Baker)TCSS458A Isabelle Bichindaritz Circle AlgorithmsProperties of circles:TCSS458A Isabelle Bichindaritz Circle AlgorithmsPolar coordinatesSymmetry of circlesAll these methods have long execution timeTCSS458A Isabelle Bichindaritz Curve Functions(from Donald Hearn and Pauline Baker)TCSS458A Isabelle Bichindaritz Curve Functions(from Donald Hearn and Pauline Baker)TCSS458A Isabelle Bichindaritz Circle AlgorithmsPrinciple of the midpoint algorithmReason from octants of a circle centered in (0,0), then find the remaining octants by symmetry, then translate to (xc, yc).The circle function is the decision parameter.Calculate the circle function for the midpoint between two pixels.TCSS458A Isabelle Bichindaritz Circle AlgorithmsMidpoint circle drawing algorithmInput radius r and circle center (xc, yc), then set the coordinates for the first point on the circumference of a circle centered on the origin as (xo, y0) = (0, r).Calculate the initial value of the decision parameter as p0 = 5/4 r (1 r if an integer) At each xk, from k=0, perform the following test: if pkCircle AlgorithmsMidpoint circle drawing algorithmDetermine symmetry points in the other seven octants.Move each calculated pixel position (x, y) onto the circular path centered at (xc, yc) and plot the coordinate values: x = x + xc, y = y + ycRepeat steps 3 through 5 until x >= y.TCSS458A Isabelle Bichindaritz Curve FunctionsEllipsis can be drawn similarly using a modified midpoint algorithm.Similar algorithms can be used to display polynomials, exponential functions, trigonometric functions, conics, probability distributions, etc.TCSS458A Isabelle Bichindaritz Curve Functions(from Donald Hearn and Pauline Baker)TCSS458A Isabelle Bichindaritz Curve Functions(from Donald Hearn and Pauline Baker)TCSS458A Isabelle Bichindaritz Curve Functions(from Donald Hearn and Pauline Baker)TCSS458A Isabelle Bichindaritz

Recommended

UNIT I - 2D PRIMITIVES Line, Circle and Ellipse drawing fmcet.in/CSE/CS2401_uw.pdf2014-08-051 UNIT I - 2D PRIMITIVES Output primitives – Line, Circle and Ellipse drawing algorithms - Attributes of output primitives – Two dimensional Geometric transformation - Two dimensional viewing – Line, Polygon, Curve and ...Documents