Digital Differential Analyzer Bresenhams Line Drawing Algorithm

Similar documents
Scan Conversion. CMP 477 Computer Graphics S. A. Arekete

Rasterization: Geometric Primitives

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Computer Graphics

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

Computer Graphics D Graphics Algorithms

Rasterization, or What is glbegin(gl_lines) really doing?

Output Primitives Lecture: 3. Lecture 3. Output Primitives. Assuming we have a raster display, a picture is completely specified by:

Chapter - 2: Geometry and Line Generations

Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling

MODULE - 4. e-pg Pathshala

From Ver(ces to Fragments: Rasteriza(on

CS 130. Scan Conversion. Raster Graphics

Computer Graphics: Line Drawing Algorithms

UNIT 2 GRAPHIC PRIMITIVES

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu

A Mathematical Overview of Bresenham Algorithms in the Determination of Active Pixel Positions

In today s lecture we ll have a look at: A simple technique The mid-point circle algorithm

Line Drawing Week 6, Lecture 9

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored.

Computer Graphics D Graphics Algorithms

Scan Converting Lines

Scan Conversion. Lines and Circles

CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE

Introduction to Bresenham s Line Algorithm Using. Instruction Series Graphics Note 5

Introduction to Computer Graphics (CS602) Lecture 05 Line Drawing Techniques

Department of Computer Science Engineering, Mits - Jadan, Pali, Rajasthan, India

Output Primitives. Dr. S.M. Malaek. Assistant: M. Younesi

An Improved Algorithm for Scan-converting a Line

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

CS335 Fall 2007 Graphics and Multimedia. 2D Drawings: Lines

CPSC / Scan Conversion

Scan Converting Circles

Scan Conversion. Drawing Lines Drawing Circles

Painter s HSR Algorithm

2D Image Synthesis. 2D image synthesis. Raster graphics systems. Modeling transformation. Vectorization. u x u y 0. o x o y 1

Pipeline implementation II

(Refer Slide Time: 9:36)

CS6504 & Computer Graphics Unit I Page 1

Announcements. Midterms graded back at the end of class Help session on Assignment 3 for last ~20 minutes of class. Computer Graphics

Points and lines. x x 1 + y 1. y = mx + b

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

Overview of Computer Graphics

Graphics System. Processor. Output Display. Input Devices. Frame Buffer. Memory. Array of pixels. Resolution: # of pixels Depth: # of bits/pixel

Computer Graphics 7 - Rasterisation

CS 450: COMPUTER GRAPHICS RASTERIZING LINES SPRING 2016 DR. MICHAEL J. REALE

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Unit 2 Output Primitives and their Attributes

Implementation III. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

UNIT -8 IMPLEMENTATION

Computer Graphics. Lecture 2. Doç. Dr. Mehmet Gokturk

Computer Graphics. - Rasterization - Philipp Slusallek

Efficient Plotting Algorithm

Computer Graphics Lecture Notes

Realtime 3D Computer Graphics Virtual Reality

1 Introduction to Graphics

Department of Computer Sciences Graphics Fall 2003 (Lecture 2) Pixels

This library uses only GL functions but contains code for creating common objects and simplifying viewing.

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

CS 543: Computer Graphics. Rasterization

Chapter 8: Implementation- Clipping and Rasterization

CS Rasterization. Junqiao Zhao 赵君峤

Topic #1: Rasterization (Scan Conversion)

Rendering. A simple X program to illustrate rendering

Line Drawing. Foundations of Computer Graphics Torsten Möller

A New Line Drawing Algorithm Based on Sample Rate Conversion

Differentiation. The Derivative and the Tangent Line Problem 10/9/2014. Copyright Cengage Learning. All rights reserved.

Solution Notes. COMP 151: Terms Test

CSCI 4620/8626. Coordinate Reference Frames

OUTPUT PRIMITIVES. CEng 477 Introduction to Computer Graphics METU, 2007

Clipping and Scan Conversion

Output Primitives Lecture: 4. Lecture 4

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science

RASTERIZING POLYGONS IN IMAGE SPACE

Einführung in Visual Computing

Rasterization. CS4620/5620: Lecture 12. Announcements. Turn in HW 1. PPA 1 out. Friday lecture. History of graphics PPA 1 in 4621.

Computer Graphics (CS 543) Lecture 10: Rasterization and Antialiasing

Chapter 3: Graphics Output Primitives. OpenGL Line Functions. OpenGL Point Functions. Line Drawing Algorithms

Line Drawing Algorithms

Line Drawing. Introduction to Computer Graphics Torsten Möller / Mike Phillips. Machiraju/Zhang/Möller

CS 548: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE

EF432. Introduction to spagetti and meatballs

Rendering. A simple X program to illustrate rendering

(Refer Slide Time: 00:03:51)

Direction Fields; Euler s Method

Display Technologies: CRTs Raster Displays

Example 1: Give the coordinates of the points on the graph.

Practice Test (page 391) 1. For each line, count squares on the grid to determine the rise and the run. Use slope = rise

COMP371 COMPUTER GRAPHICS

Graphs of Increasing Exponential Functions

Fall CSCI 420: Computer Graphics. 7.1 Rasterization. Hao Li.

Graphs of Increasing Exponential Functions

Section 18-1: Graphical Representation of Linear Equations and Functions

Graphics (Output) Primitives. Chapters 3 & 4

Bresenham s Line Algorithm Implemented for the NS32GX32

EECS150 - Digital Design Lecture 12 - Video Interfacing. MIPS150 Video Subsystem

Notes for Unit 1 Part A: Rational vs. Irrational

Computer Graphics, Lecture 2 October 31, Department of Information Technology. - Scientific Computing. Department of Information Technology

EECS150 - Digital Design Lecture 15 - Video

GRAPHICS OUTPUT PRIMITIVES

Transcription:

Bresenham s Line Generation The Bresenham algorithm is another incremental scan conversion algorithm. The big advantage of this algorithm is that, it uses only integer calculations. Difference Between DDA Line Drawing Algorithm and Bresenhams Line Drawing Algorithm. Digital Differential Analyzer Bresenhams Line Drawing Algorithm Arithmetic Operations DDA algorithm uses floating Bresenhams algorithm uses fixed points points i.e. Real Arithmetic. i.e. Integer Arithmetic. DDA algorithm uses Bresenhams algorithm uses only multiplication and division in its subtraction and addition in its operations. operations. 1

Speed DDA algorithm is rather slowly Bresenhams algorithm is faster than DDA than Bresenhams algorithm in algorithm in line drawing because it line drawing because it uses real performs only addition and subtraction in arithmetic (floating-point its calculation and uses only integer operations). arithmetic so it runs significantly faster. DDA algorithm is not as accurate Accuracy & Bresenhams algorithm is more efficient and efficient as Bresenham Efficiency and much accurate than DDA algorithm. algorithm. Drawing Round Off Expensive DDA algorithm can draw circles Bresenhams algorithm can draw circles and curves but that are not as and curves with much more accuracy than accurate as Bresenhams DDA algorithm. algorithm. DDA algorithm round off the Bresenhams algorithm does not round off coordinates to integer that is but takes the incremental value in its nearest to the line. operation. DDA algorithm uses an Bresenhams algorithm is less expensive enormous number of floatingpoint multiplications so it is than DDA algorithm as it uses only addition and subtraction. expensive. Moving across the x axis in unit intervals and at each step choose between two different y coordinates. For example, as shown in the following illustration, from position (2, 3) you need to choose between (3, 3) and (3, 4). You would like the point that is closer to the original line. 2

At sample position Xk+1, the vertical separations from the mathematical line are labeled as dupper and dlower. The pixel positions on line can be identified by doing sampling at unit x intervals. The process of sampling begins from the pixel position (X0,Y0) and proceeds by plotting the pixels whose Y value is nearest to the line path. If the pixel to be displayed occurs at a position (X k, Y k ) then the next pixel is either at (X k +1,Y k ) or (X k +1,Y k +1) i.e, (3,2) or (3,3) The Y coordinate at the pixel position X k +1 can be obtained from Y=m(X k +1)+b........... eq 1 the separation between (X k+1,y k ) and (X k+1,y) is d1 and the separation between (X k+1,y) and (X k+1, Y k+1 ) is d2 then d1 = y y k and d2 = (Y k +1) Y 3

(X k, y k +1) (X k +1, y k +1) d 2 P 0 d 1 (X k, y k ) (X k +1,y k ) Y=m(X k +1)+b........ eq 1 d1=y y k d1=m(x k +1)+b Y k ( from eq (1))..( 2) And d2= (Y k +1) Y =(Y K +1) [m(x k +1)+b] =(Y K +1) m(x k +1) b.(3) The difference is given as d1-d2 = m(x k +1)+b-Y k -[(Y k +1)-m(X k +1)-b] =m(x k +1)+b-Y k -(Y k +1)+m(X k +1)+b =m(x k +1)+b-Y k -Y k -1+m(X k +1)+b d1-d2 = 2m(X k +1)-2Y k +2b 1 (4) A decision parameter P k can be obtained by substituting m= dy/dx in equation 4 = 2 dy/dx (X k +1) 2Y k + 2b 1 = (2 dy(x k +1)-2 dx.y k + 2b.dx -dx )/dx dx(d1-d2) = 2 dy(x k +1)-2 dx.y k + 2b.dx - dx = 2 dyx k +2 dy-2 dx.y k + 2b.dx -dx 4

= 2 dyx k - 2 dx.y k + c where c=2dy+2b.dx-dx Where, dx(d1-d2) = Pk and c= 2 dy+ dx(2b-1) Pk = 2 dyx k - 2 dx.y k + c................... (5 ) The value of c is constant and is independent of the pixel position. It can be deleted in the recursive calculations, of for P k if d1 < d2 (i.e, Yk is nearer to the line path than Yk+1) then, P k is negative, then a lower pixel (Y k ) is plotted else, an upper pixel (Y k +1) is plotted. At k+1 step, the value of Pk is given as P K+1 = 2 dyx k+1-2 dx.y k+1 + c..(6 ) (from 5) Eq 6 eq 5 Pk+1 Pk = (2 dyx k+1-2 dx.y k+1 + c ) - (2 dyx k +2 dx.y k + c) = 2dy(X k+1 -X k ) 2 dx(y k+1 Y k ).(7) Since X k+1 = X k +1 The eqn 7 becomes Pk+1 Pk = 2dy(X k +1 -X k ) 2 dx(y k+1 Y k ) = 2dy - 2 dx(y k+1 Y k ) Pk+1 = Pk + 2dy - 2 dx(y k+1 Y k )..( 8) Where (Yk+1 Yk) is either 0 or 1 based on the sign of Pk If 0 then pk+1=pk+2dy If 1 then pk+1=pk+2dy-2dx. The starting parameter P0 at the pixel position (X0,Y0) is given as P0 = 2dy dx (9) Bresenham s algorithm 5

Step 1: Enter the 2 end points for a line and store the left end point in (X0,Y0). Step 2: Plot the first point be loading (X0,Y0) in the frame buffer. Setp 3: determine the initial value of the decision parameter by calculating the constants dx, dy, 2dy and 2dy-2dx as dx=x1-x0, dy=y1-y0, P0 = 2dy dx Step 4: for each Xk, conduct the following test, starting from k= 0 If Pk <0, then the next point to be plotted is at (Xk+1, Yk) and, Pk+1 = Pk + 2dy Else, the next point is (Xk+1, Yk+1) and Pk+1 = Pk + 2dy 2dx (step 3) Step 5: iterate through step (4) dx times. Or Step 1: Enter the 2 end points for a line (X0,Y0), (X1,Y1). Step 2: Plot (X0,Y0,colo). Setp 3: determine the initial value of the decision parameter by calculating the constants dx=x1-x0, dy=y1-y0, P0 = 2dy dx for k=0 to dx do If Pk <0, then the next point to be plotted is at (Xk+1, Yk) Pk+1 = Pk + 2dy Else the next point is (Xk+1, Yk+1) Pk+1 = Pk + 2dy 2dx Endfor 6

Example Let the given end points for the line be (30,20) and (40, 28) dy = y1 y0 = 28 20 = 8 dx = x1 x0 = 40 30 = 10 m = 0.8 The initial decision parameter P0 is P0 = 2dy dx = 2(8) 10 = 16 10 = 6 The constants 2dy and 2dy-2dx are 2dy = 2(8) = 16 2dy-2dx = 2(8)- 2(10) =16 20=-4 The starting point (x0, y0)=(30,20) and the successive pixel positions are given in the following table K P k (X, Y ) k+1 k+1 0 6 (31,21) 1 2 (32,22 2-2 33,22 3 14 34,23 4 10 35,24 5 6 36,25 7

6 2 37,26 7-2 38,26 8 14 39,27 9 10 40,28 8