Lecture 9 Line Drawing Algorithms (Bresenham’s Line Algorithm)

Slides:



Advertisements
Similar presentations
Contents In today’s lecture we’ll have a look at:
Advertisements

Graphics Primitives Part II: Bresenhams line and circle.
Graphics Primitives: line
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.
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.
ECE291 Computer Engineering II Lecture 19 Josh Potts University of Illinois at Urbana- Champaign.
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.
Lecture 17 Fun with Graphics Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
The lines of this object appear continuous However, they are made of pixels 2April 13, 2015.
OUTPUT PRIMITIVES Screen vs. World coordinate systems ● Objects positions are specified in a Cartesian coordinate system called World Coordinate.
Lecture 16 Fun with graphics
Raster conversion algorithms for line and circle
University of Missouri at Columbia 2D Scan-line Conversion University of Missouri at Columbia.
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
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
Graphics Graphics Korea University cgvr.korea.ac.kr Raster Graphics 고려대학교 컴퓨터 그래픽스 연구실.
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.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
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.
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.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
Computer Graphics Lecture 06 Circle Drawing Techniques 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
CSCE 441 Lecture 2: Scan Conversion of Lines
Raster Graphics.
MID-POINT CIRCLE ALGORITHM
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Lecture 8 Shear and Line Drawing Algorithms
Lecture 05: Mid-point Ellipse algorithm Dr. Manal Helal – Fall 2014
Chapter Three Part I Output Primitives CS 380.
Methods Anti-Aliasing Super Sampling
CSCE 441 Lecture 2: Scan Conversion of Lines
2D Scan-line Conversion
Rasterizing Lines 1 Lecture 32 Mon, Nov 12, 2007.
Scan Conversion Line(DDA Line and Bresenham Line)
Line Drawing Algorithms
Scan Conversion (From geometry to pixels)
Chapter 3 Graphics Output Primitives
Primitive Drawing Algorithm
Type to enter a caption. Computer Graphics Week 1 Lecture 2.
Primitive Drawing Algorithm
Line Drawing Algorithms
INTERACTIVE COMPUTER GRAPHICS
Presentation transcript:

Lecture 9 Line Drawing Algorithms (Bresenham’s Line Algorithm) Computer Graphics Lecture 9 Line Drawing Algorithms (Bresenham’s Line Algorithm)

Bresenham’s Line Algorithm DDA algorithm has a disadvantage, that is, the round off error. This error happens because the algorithm rounds off the actual floating point line values to integer values (for example, if actual value of a point of line is 12.34, the DDA algorithm rounds it to 12 and if the value is 12.62, it will round it to 13). This causes the calculated pixel positions to move away from the actual line path for long lines. For this reason we use another accurate and efficient line drawing algorithm called Bresenham’s algorithm because it was developed by Bresenham. This algorithm draws line by using only integer calculations.

Horizontal axis shows the pixel columns Vertical axis shows the line position. If we take unit x-intervals and we plot a point at (xk,yk), then in order to calculate the y values we need to check which of the two points is closer to the line path at each sample step. That is, we need to decide at the next sample position xk+1 whether to choose the pixel (xk+1,yk) or (xk+1,yk+1), that is, whether to choose point (11,11) or (11,12) for the next step.

These issues are solved by Bresenham’s algorithm. It decides which value to take at next position whether (xk+1, yk) or (xk+1, yk+1). It does this by checking the sign of a decision parameter (pk) which is equal to the difference between the separations of the two pixel positions (yk and yk+1) from the actual line path. If pk is negative it takes the point as (xk+1, yk). If pk is positive it takes point as (xk+1, yk+1)

Suppose we have determined the first pixel position as (xk,yk). Now, we have to decide which pixel to plot at xk+1, that is, whether (xk+1,yk) or (xk+1, yk+1). At position (xk+1), we label separation between pixels yk and yk+1 from the line path (y) as d1 and d2. that is, d1 = y – yk; and d2 = yk+1 - y Then we calculate the decision parameter pk as pk = (d1-d2).

At pixel xk+ 1, we can calculate y as: y = m.x + b y = m (xk+ 1) + b Then d1 = y – yk d1 = m (xk+ 1) + b – yk d2 = yk+ 1 – y d2 = yk+1 – (m (xk+ 1) + b) d2 = yk+1 - m (xk+ 1) - b d1 – d2 = (m (xk+1) + b – yk) – (yk + 1 - m (xk+1) – b) d1 – d2 = m(xk + 1) + b – yk – yk - 1 + m(xk+1) + b d1 – d2 = 2m(xk + 1) – 2yk + 2b - 1

The decision parameter pk for kth step is given as pk = δx(d1 – d2) pk = 2δy . xk – 2δx. yk + 2δy + δx (2b – 1) pk = 2δy. xk – 2δx. yk + c c is a constant as it is not dependent on pixel positions (xk,yk) The decision parameter pk for step k + 1 is given as pk+1 = 2δy. xk+1 – 2δx. yk+1 + c => pk+1 – pk = 2δy (xk+1 – xk) – 2δx (yk+1 – yk) xk+1 = xk + 1 pk+1 – pk = 2δy (xk+ 1 – xk) – 2δx (yk+1 – yk) pk+1 – pk = 2δy (1) – 2δx (yk+1 – yk) pk+1 = pk + 2δy – 2δx (yk+1 – yk)

If the pixel at yk is closer to line path than yk+1 (that is, d1 < d2) then pk is negative and we take y-value as yk that is we plot the point as (xk+1, yk). Then the term (yk+1 – yk) will become (yk – yk), which is equal to 0. Therefore, pk+1 = pk + 2δy – 2δx (0) => pk+1 = pk + 2δy If yk+1 is closer to line path than yk (that is d1 > d2) then pk is positive and we take y-value as yk+1 that is we plot the point as (xk+1, yk+1). Then the term (yk+1 – yk) will become (yk + 1 – yk), which is equal to 1. Therefore, pk+1 = pk + 2δy – 2δx (1) => pk+1 = pk + 2δy – 2δx

Algorithm Input the line endpoints and store left endpoint in (x0, y0) Load (x0, y0) into frame buffer and plot the first point. Calculate δx, δy, 2δy and 2δy - 2δx calculate p0 = 2δy – δx 4. At each xk, starting at k = 0, do the following if pk < 0, next point to plot is (xk+1, yk) and pk+1 = pk + 2δy if pk > 0, next point to plot is (xk+1, yk+1) and pk+1 = pk + 2δy - 2δx Step 4 is repeated δx times.