Line Drawing by Algorithm. Line Drawing Algorithms Line drawn as pixels Graphics system –Projects the endpoints to their pixel locations in the frame.

Slides:



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

Graphics Primitives: line
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
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.
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.
CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics May 3, 2007.
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
Circle Drawing algo..
Dr. Scott Schaefer Scan Conversion of Lines. 2/78 Displays – Cathode Ray Tube.
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.
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)
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.
Rendering.
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 : output primitives.. 2 of 32 T1 – pp. 103–123, 137–145, 147–150, 164–171 Points and LinesPoints Line Drawing AlgorithmsLine Mid–Point.
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
CSCE 441 Lecture 2: Scan Conversion of Lines
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.
CSCE 441 Lecture 2: Scan Conversion of Lines
2D Scan-line Conversion
Line and Curve Drawing Algorithms
Scan Conversion (From geometry to pixels)
Chapter 3 Graphics Output Primitives
Primitive Drawing Algorithm
Primitive Drawing Algorithm
Line Drawing Algorithms
OUTPUT PRIMITIVES / DISPLAY TECHNIQUES
Presentation transcript:

Line Drawing by Algorithm

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.

Line Drawing Algorithms Line equation –Slope-intercept form y = m. x + b slope m Y-intercept b –Slope –Y-intercept

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

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)); }

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.

Observation on lines. while( n-- ) { draw(x,y); move right; if( below line ) move up; }

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.

Bresenham ’ s Algorithm Improve upon DDA algorithm to use integer arithmetic only. Applicable to circle drawing too. We discuss only the line drawing here. An Accurate and efficient raster line generating Algo. And scan converts lines using only incrementa1 integer calculations that can be adapted to display circles and other curves

Testing for the side of a line. Need a test to determine which side of a line a pixel lies. Write the line in implicit form: Easy to prove Y=m*X+Cnts below.

Decision Variables Variables a and b record the distances to the pixel centers of (i+1, j) and (i+1, j+1) If d1 < d2, then y=j If d1 > d2, then y= j+1

The vertical axes show-scan-line positions, and the horizontal axes identify pixel columns. Sampling at unit x intervals in these examples, we need to decide which of two possible pixel positions is closer to the line path at each sample step. Starting from the left endpoint we need to determine at the next sample position whether to plot the pixel at position (11, 11) or the one at (11, 12) Line with negative slope-line path starting from the left endpoint at pixel position (50, 50). In this one, do we select the next pixel position as (51,50)or as (51,49)? These questions are answered with Bresenham's line algorithm by testing the sign of an integer parameter, whose value is proportional to the difference between the separations of the two pixel positions from the actual line path. we- first consider the scan- conversion process for lines with positive slope less than 1. Pixel positions along a line path are then determined by sampling at unit x intervals. Starting from the left end point (x0, yo) of a given line, we step to each successive column ( x position) and plot the pixel whose scan-line y value is closest to the line path. demonstrates the Kh step in this process. Assuming we have determined that the pixel at (xk, yk) 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 ( Xk+l, yk) and (xk+l, yk+l). At sampling position xk+l, we label vertical pixel separations from the mathematical line path as d1 and d2

Y co-ordinate at column Xk+1 can be calculated as Y=m(Xk+1)+b then D1=y-yk=m(xk+1)+b-yk D2=(Yk+1) – y=Yk+1 –m(Xk+1)-b Difference in these two sepration is D1-D2=2m(Xk+1)-2Yk+2b-1 Decision Parameter Pk( Kth iteration) Pk=DX(d1-d2)=2Dy * Xk-2Dx * Yk+C Note Pk has Same Sign as d1-d2Sine DX>1,C is constant & C=2Dy+Dx(2b-1) is Independent of Pixel Position,Ignored In recursive cal of Pk Pk+1 can be calculated then Recursive Pk+1 be as Pk+1=Pk+2Dy-2Dx(Yk+1- Yk) then Po=2Dy-Dx

void lineares (int xa,Int ya, int x b, int yb) (int dx = a b s ( x a - x b), dy = abs (ya - yb); int p = 2 * dy - d x ; int twoDy = 2 * dy, twoDyDx = 2 *( dy - dx ) ; int x, y, xEnd: / * Determine which point to use a s start, which as end * / if ( x a > x b ) { x = x b ; Y = yb; xEnd = x a ;} else { x = xa;Y = ya;xEnd = xb;} setpixel ( x, y); while (x < xEnd) { x++; if (p < 0 ) p+= twoDy; else {y + + ;P += twoDyDx;} setpixel ( x, y);}}