10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.

Slides:



Advertisements
Similar presentations
Graphics Primitives Part II: Bresenhams line and circle.
Advertisements

Graphics Primitives: line
Line and Curve Drawing Algorithms. Line Drawing x0x0 y0y0 x end y end.
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.
Graphics Output Primitives Pixel Addressing and Fill Area Dr. M. Al-Mulhem Feb. 1, 2008.
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..
CGMB214: Introduction to Computer Graphics
Dr. S.M. Malaek Assistant: M. Younesi
Jehee Lee Seoul National University
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
CS 450: COMPUTER GRAPHICS REVIEW: DRAWING ELLIPSES AND OTHER CURVES SPRING 2015 DR. MICHAEL J. REALE.
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.
Introduction Computer Graphics & Its application Types of computer graphics Graphic display : random Scan & Raster Scan display Frame buffer and video.
Graphics Output Primitives
Line Drawing and Generalization. Outline  overview  line drawing  circle drawing  curve drawing.
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.
MIDPOINT CIRCLE & ELLIPSE GENERARTING ALGORITHMS
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.
GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.
In the name of God Computer Graphics. Today Introduction Sampling Graphic Output Primitives 1.Line 2.Circle 3.Curve 4.polygon.
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.
Computer Graphics Lecture 07 Ellipse and Other Curves Taqdees A. Siddiqi
Rasterization CENG 477 Introduction to Computer Graphics Slides from Steve Marschner, CS4620, 2008 Cornell University.
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.
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)
Lecture 8 Shear and Line Drawing Algorithms
Chapter Three Part I Output Primitives CS 380.
2D Scan-line Conversion
Rasterization and Antialiasing
Line and Curve Drawing Algorithms
Rasterization and Antialiasing
Scan Conversion (From geometry to pixels)
Chapter 3 Graphics Output Primitives
Presentation transcript:

10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms

10/10/2006TCSS458A Isabelle Bichindaritz2 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 as jigsaw appearance (low resolution) –Improvement: high resolution, or adjust pixel intensities on the line path.

10/10/2006TCSS458A Isabelle Bichindaritz3 Line Drawing Algorithms Line equation –Slope-intercept form y = m. x + b slope m Y-intercept b –Slope –Y-intercept

10/10/2006TCSS458A Isabelle Bichindaritz4 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

10/10/2006TCSS458A Isabelle Bichindaritz5 Line Drawing Algorithms void 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)); }

10/10/2006TCSS458A Isabelle Bichindaritz6 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 artithmetic.

10/10/2006TCSS458A Isabelle Bichindaritz7 Line Drawing Algorithms 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.

10/10/2006TCSS458A Isabelle Bichindaritz8 Line Drawing Algorithms (from Donald Hearn and Pauline Baker)

10/10/2006TCSS458A Isabelle Bichindaritz9 Line Drawing Algorithms (from Donald Hearn and Pauline Baker)

10/10/2006TCSS458A Isabelle Bichindaritz10 Line Drawing Algorithms Bresenham’s line drawing algorithm (positive slope less than 1) d lower = y – y k d upper = (y k + 1) – y d lower – d upper = 2m(x k +1) – 2y k + 2b –1 decision parameter: p k = Δx ( d lower – d upper ) p k = 2Δy x k - 2Δx y k + c sign of p k is the same as sign of d lower – d upper

10/10/2006TCSS458A Isabelle Bichindaritz11 Line Drawing Algorithms Bresenham’s line drawing algorithm (positive slope less than 1 1.Input the two line endpoints and store the left endpoint in (x 0, y 0 ). 2.Set the color for the frame-buffer position (x 0, y 0 ) – i.e. plot the first point. 3.Calculate the constant 2Δy –Δx, and set the starting value for the decision parameter as p 0 = 2Δy –Δx. 4.At each x k along the line, from k=0, perform the following test: 5.if p k <0, next point to plot is (x k + 1, y k ) and p k+1 = p k + 2Δy otherwise, 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.

10/10/2006TCSS458A Isabelle Bichindaritz12 Curve Functions Such 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.

10/10/2006TCSS458A Isabelle Bichindaritz13 Curve Functions (from Donald Hearn and Pauline Baker)

10/10/2006TCSS458A Isabelle Bichindaritz14 Circle Algorithms Properties of circles:

10/10/2006TCSS458A Isabelle Bichindaritz15 Circle Algorithms Polar coordinates Symmetry of circles All these methods have long execution time

10/10/2006TCSS458A Isabelle Bichindaritz16 Curve Functions (from Donald Hearn and Pauline Baker)

10/10/2006TCSS458A Isabelle Bichindaritz17 Curve Functions (from Donald Hearn and Pauline Baker)

10/10/2006TCSS458A Isabelle Bichindaritz18 Circle Algorithms Principle of the midpoint algorithm –Reason from octants of a circle centered in (0,0), then find the remaining octants by symmetry, then translate to (x c, y c ). –The circle function is the decision parameter. –Calculate the circle function for the midpoint between two pixels.

10/10/2006TCSS458A Isabelle Bichindaritz19 Circle Algorithms Midpoint circle drawing algorithm 1.Input radius r and circle center (x c, y c ), then set the coordinates for the first point on the circumference of a circle centered on the origin as (x o, y 0 ) = (0, r). 2.Calculate the initial value of the decision parameter as p 0 = 5/4 – r (1 – r if an integer) 3.At each x k, from k=0, perform the following test: if p k <0, next point to plot along the circle centered on (0,0) is (x k + 1, y k ) and p k+1 = p k + 2 x k otherwise, next point to plot is (x k + 1, y k - 1) and p k+1 = p k + 2 x k y k+1 where 2 x k+1 = 2 x k + 2, and 2 y k+1 = 2 y k - 2

10/10/2006TCSS458A Isabelle Bichindaritz20 Circle Algorithms Midpoint circle drawing algorithm 4.Determine symmetry points in the other seven octants. 5.Move each calculated pixel position (x, y) onto the circular path centered at (x c, y c ) and plot the coordinate values: x = x + x c, y = y + y c 6.Repeat steps 3 through 5 until x >= y.

10/10/2006TCSS458A Isabelle Bichindaritz21 Curve Functions Ellipsis 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.

10/10/2006TCSS458A Isabelle Bichindaritz22 Curve Functions (from Donald Hearn and Pauline Baker)

10/10/2006TCSS458A Isabelle Bichindaritz23 Curve Functions (from Donald Hearn and Pauline Baker)

10/10/2006TCSS458A Isabelle Bichindaritz24 Curve Functions (from Donald Hearn and Pauline Baker)