 A line segment in a scene is defined by the coordinate positions of the line end-points x y (2, 2) (7, 5)

Slides:



Advertisements
Similar presentations
Line Drawing Algorithms
Advertisements

Contents In today’s lecture we’ll have a look at:
Graphics Primitives: line
5.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 5 – Drawing A 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.
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.
OUTPUT PRIMITIVES Screen vs. World coordinate systems ● Objects positions are specified in a Cartesian coordinate system called World Coordinate.
Raster conversion algorithms for line and circle
University of Missouri at Columbia 2D Scan-line Conversion University of Missouri at Columbia.
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.
Circle Drawing algo..
Computer Graphics- SCC 342
Scan Conversion. Also known as rasterization In our programs objects are represented symbolically –3D coordinates representing an object’s position –Attributes.
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.
Triangle Scan Conversion. 2 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Rasterization Rasterization (scan conversion) –Determine which.
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
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.
Instructor: Dr. Shereen Aly Taie If (P>0)
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.
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
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
Line Drawing Algorithms
Lecture 9 Line Drawing Algorithms (Bresenham’s Line Algorithm)
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
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:

 A line segment in a scene is defined by the coordinate positions of the line end-points x y (2, 2) (7, 5)

 When drawn on a pixel based display. Which pixel has to be chosen?

Points to be considered  Line should not be jarred  It should be fast Line equation The slope intercept form of a line is y=m.x+b Where m=y 2 -y 1 /x 2 -x 1 b=y-m.x

 The slope of a line ( m ) is defined by its start and end coordinates  The diagram below shows some examples of lines and their slopes m = 0 m = - 1 / 3 m = - 1 / 2 m = -1 m = -2 m = -4 m = ∞ m = 1 / 3 m = 1 / 2 m = 1 m = 2 m = 4 m = 0

 Let’s consider the following example: x y (2, 2) (7, 5)

x y (2, 2) (7, 5)  First work out m and b : Now for each x value work out the y value:

 Round off the results

 The approach is slow  Multiplication of m,x  Rounding of y value Alternate solution x=y-b/m

 X(3)=2,x(4)=

 If the slope of a line is between -1 and 1 then we work out the y coordinates for a line based on it’s unit x coordinates  Otherwise we do the opposite – x coordinates are computed based on unit y coordinates m = 0 m = - 1 / 3 m = - 1 / 2 m = -1 m = -2 m = -4 m = ∞ m = 1 / 3 m = 1 / 2 m = 1 m = 2 m = 4 m = 0

 The digital differential analyzer (DDA) algorithm takes an incremental approach in order to speed up scan conversion  Simply calculate y k+1 based on y k The original differential analyzer was a physical machine developed by Vannevar Bush at MIT in the 1930’s in order to solve ordinary differential equations.

 Consider the list of points that we determined for the line in our previous example:  (2, 2), (3, 2 3 / 5 ), (4, 3 1 / 5 ), (5, 3 4 / 5 ), (6, 4 2 / 5 ), (7, 5)  Notice that as the x coordinates go up by one, the y coordinates simply go up by the slope of the line  This is the key insight in the DDA algorithm

 When the slope of the line is between -1 and 1 begin at the first point in the line and, by incrementing the x coordinate by 1, calculate the corresponding y coordinates as follows:  When the slope is outside these limits, increment the y coordinate by 1 and calculate the corresponding x coordinates as follows:

 Again the values calculated by the equations used by the DDA algorithm must be rounded to match pixel values (x k, y k ) (x k +1, y k +m) (x k, round(y k )) (x k +1, round(y k +m)) (x k, y k ) (x k + 1 / m, y k +1) (round(x k ), y k ) (round(x k + 1 / m ), y k +1)

 Try out the following ◦ A(2,2) B(7,5) ◦ C(3,2),D(2,7)

 The DDA algorithm is much faster than previous attempt ◦ In particular, there are no longer any multiplications involved  However, there are still two big issues: ◦ 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.

 The Bresenham algorithm is another incremental scan conversion algorithm  The big advantage of this algorithm is that it uses only integer calculations Jack Bresenham worked for 27 years at IBM before entering academia. Bresenham developed his famous algorithms at IBM in the early 1960s

 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:  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

 So, d upper and d lower are given as follows:  and:  We can use these to make a simple decision about which pixel is closer to the mathematical line

 This simple decision is based on the difference between the two pixel positions:  Let’s substitute m with ∆ y /∆ x where ∆ x and ∆ y are the differences between the end-points:

 So, a decision parameter p k for the k th step along a line is given by:  The sign of the decision parameter p k is the same as that of d lower – d upper  If p k is negative, then we choose the lower pixel, otherwise we choose the upper pixel

 Remember coordinate changes occur along the x axis in unit steps so we can do everything with integer calculations  At step k +1 the decision parameter is given as:  Subtracting p k from this we get:

 But, x k+1 is the same as x k +1 so:  where y k+1 - y k is either 0 or 1 depending on the sign of p k  The first decision parameter p0 is evaluated at (x0, y0) is given as:

BRESENHAM’S LINE DRAWING ALGORITHM (for | m | < 1.0) 1.Input the two line end-points, storing the left end- point in ( x 0, y 0 ) 2.Plot the point ( x 0, y 0 ) 3.Calculate the constants Δx, Δy, 2Δy, and ( 2Δy - 2Δx ) and get the first value for the decision parameter as: 4.At each x k along the line, starting at k = 0, perform the following test. If p k < 0, the next point to plot is (x k +1, y k ) and:

 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

 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

kpkpk (x k+1,y k+1 )

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

 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