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.

Slides:



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

Graphics Primitives: line
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
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.
Scan Conversion Algorithms
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.
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
CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics May 3, 2007.
Course Website: Computer Graphics 5: Line Drawing Algorithms.
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.
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.
1Computer Graphics Implementation III Lecture 17 John Shearer Culture Lab – space 2
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.
MIDPOINT CIRCLE & ELLIPSE GENERARTING ALGORITHMS
CS-321 Dr. Mark L. Hornick 1 Line Drawing Algorithms.
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.
Bresenham’s Line Algorithm
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 Lecture 06 Circle Drawing Techniques Taqdees A. Siddiqi
Rasterization CENG 477 Introduction to Computer Graphics Slides from Steve Marschner, CS4620, 2008 Cornell University.
Scan Conversion of Line Segments. What is Scan conversion? Final step of rasterization (the process of taking geometric shapes and converting them into.
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.
Objectives Understand Bresenhams line drawing algorithm. Apply the algorithm to plot a line with the end points specified.
Primitive graphic objects
Line Drawing Algorithms
Scan Conversion or Rasterization
Lecture 9 Line Drawing Algorithms (Bresenham’s Line Algorithm)
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Scan Conversion or Rasterization
Lecture 8 Shear and Line Drawing Algorithms
Chapter Three Part I Output Primitives CS 380.
Computer Graphics 5: Line Drawing Algorithms
Computer Graphics 5: Line Drawing Algorithms
2D Scan-line Conversion
Rasterization and Antialiasing
Computer Graphics 5: Line Drawing Algorithms
Rasterization and Antialiasing
Edited from The Rasterization Problem: Idealized Primitives Map to Discrete Display Space Edited from.
Chapter 3 Graphics Output Primitives
Type to enter a caption. Computer Graphics Week 1 Lecture 2.
S.JOSEPHINE THERESA, DEPT OF CS, SJC, TRICHY-2
Line Drawing Algorithms
Presentation transcript:

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 by its two end points. 3. Its density should be independent of line length. the slope intercept equation for a line: y = mx + b (1) where, m = Slope of the line b = the y intercept of a line

The two endpoints of a line segment are specified at positions (x1,y1) and (x2,y2). x y P1(x1,y1) P2(x2,y2) b 0

We can determine the value for slope m & b intercept as m = y2-y1/x2-x1 i.e. m= Δy/ Δx (2)

Example 1 The endpoints of line are(0,0) & (6,18). Compute each value of y as x steps from 0 to 6 and plot the result. Solution : Equation of line is y= mx +b m = y2-y1/x2-x1= 18-0/6-0 = 3 Next the y intercept b is found by plugging y1& x1 into the equation y = 3x + b, 0 = 3(0) + b. Therefore, b=0, so the equation for the line is y= 3x.

The challenge is to find a way to calculate the next x,y position by previous one as quickly as possible.

DDA Algorithm The Digital differential analyzer (DDA) algorithm is an incremental scan-conversion method. Such an approach is characterized by performing calculations at each step using results from the preceding step.

Algorithm: (x1,y1) (x2,y2) are the end points and dx, dy are the float variables. Where dx= abs(x2-x1) and dy= abs(y2-y1) (i) If dx >=dy then length = dx else length = dy endif

(ii) dx = (x2-x1)/length dy = (y2-y1)/length (iii) x = x y = y (iv) i = 0 (v) Plot ((x), (y)) (vi) x = x + dx y = y + dy (vii) i = i + 1

(viii) If i < length then go to step (v) (ix) Stop Example 2 Scan convert a line having end points (3,2) & (4,7) using DDA. Solution: dx= x2 - x1 = 4-3 = 1 dy= y2 - y1 = 7-2 = 5 As, dx < dy then length = y2-y1 = 5 dx = (x2-x1)/ length = 1/5 =0.2 dy = (y2-y1)/ length = 5/5 = 1

x1y1x2y2LdxdyixyResultPlot , 2.53, ,3.53, ,4.53, ,5.54, ,6.54, ,7.54,7

Limitations of DDA: (1) The rounding operation & floating point arithmetic are time consuming procedures. (2) Round-off error can cause the calculated pixel position to drift away from the true line path for long line segment.

The Bresenham Line Algorithm The Bresenham algorithm is another incremental scan conversion algorithm The big advantage of this algorithm is that it uses only integer calculations

The Big Idea Move across the x axis in unit intervals and at each step choose between two different y coordinates For example, from position (2, 3) we have to choose between (3, 3) and (3, 4) We would like the point that is closer to the original line (x k, y k ) (x k +1, y k ) (x k +1, y k +1)

The y coordinate on the mathematical line at x k +1 is: Deriving The Bresenham Line Algorithm At sample position x k +1 the vertical separations from the mathematical line are labelled d upper and d lower y ykyk y k+1 xk+1xk+1 d lower d upper

The Bresenham Line Algorithm BRESENHAM’S LINE DRAWING ALGORITHM 1.Input the two line end-points, storing the left end-point in ( x 1, y 1 ) 2.Calculate the constants Δx i.e. dx, Δy i.e. dy, 2Δy and 2 Δx, get the first value for the decision parameter as: 3.Initialise starting 4.Initialise i=1 as a counter,

The Bresenham Line Algorithm (cont…) ACHTUNG! The algorithm and derivation above assumes slopes are less than 1. for other slopes we need to adjust the algorithm slightly. Otherwise, the next point to plot is ( x k +1, y k +1 ) and: 5.Repeat step 4 (Δx – 1) times

Adjustment For m>1, we will find whether we will increment x while incrementing y each time. After solving, the equation for decision parameter p k will be very similar, just the x and y in the equation will get interchanged.

Bresenham Example Let’s have a go at this Let’s plot the line from (20, 10) to (30, 18) First off calculate all of the constants: Δx : 10 Δy : 8 2Δy : 16 2Δy - 2Δx : -4 Calculate the initial decision parameter p 0 : p0 = 2Δy – Δx = 6

Bresenham Example (cont…) kpkpk (x k+1,y k+1 )

Bresenham Exercise Go through the steps of the Bresenham line drawing algorithm for a line going from (21,12) to (29,16)

Bresenham Exercise (cont…) kpkpk (x k+1,y k+1 )

Bresenham Line Algorithm Summary The Bresenham line algorithm has the following advantages: An fast incremental algorithm Uses only integer calculations Comparing this to the DDA algorithm, DDA has the following problems: Accumulation of round-off errors can make the pixelated line drift away from what was intended The rounding operations and floating point arithmetic involved are time consuming