Objectives Understand Bresenhams line drawing algorithm. Apply the algorithm to plot a line with the end points specified.

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
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.
+ CPCS 391 Computer Graphics 1 Instructor: Dr. Sahar Shabanah Lecture 3.
Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing.
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
Output Primitives Computer Graphics.
Graphics Output Primitives Pixel Addressing and Fill Area Dr. M. Al-Mulhem Feb. 1, 2008.
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..
Section P.5 Linear Equations in Two Variables 1.Slope: can either be a ratio or a rate if the x and y axis have the same units of measures then the slope.
CGMB214: Introduction to Computer Graphics
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
Dr. S.M. Malaek Assistant: M. Younesi
Jehee Lee Seoul National University
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 고려대학교 컴퓨터 그래픽스 연구실.
CS 325 Introduction to Computer Graphics 02 / 01 / 2010 Instructor: Michael Eckmann.
Slope of a Line Chapter 7.3. Slope of a Line m = y 2 – y 1 x 2 – x 1 m = rise run m = change in y change in x Given two points (x 1, y 1 ) and (x 2, y.
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
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.
Week 4 Functions and Graphs. Objectives At the end of this session, you will be able to: Define and compute slope of a line. Write the point-slope equation.
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 07 Ellipse and Other Curves Taqdees A. Siddiqi
Computer Graphics Lecture 06 Circle Drawing Techniques Taqdees A. Siddiqi
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.
OUTPUT PRIMITIVES CEng 477 Computer Graphics METU, 2004.
Primitive graphic objects
Raster Graphics.
Graphics PRIMITIVES Chapter- 3 & Unit-2.
MID-POINT CIRCLE ALGORITHM
Lecture 9 Line Drawing Algorithms (Bresenham’s Line Algorithm)
Graphing Linear Equations
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.
Rasterizing Lines 1 Lecture 32 Mon, Nov 12, 2007.
Line Drawing Algorithms
Scan Conversion (From geometry to pixels)
Chapter 3 Graphics Output Primitives
Primitive Drawing Algorithm
Primitive Drawing Algorithm
Equations of Lines Point-slope form: y – y1 = m(x – x1)
Line Drawing Algorithms
INTERACTIVE COMPUTER GRAPHICS
Presentation transcript:

Objectives Understand Bresenhams line drawing algorithm. Apply the algorithm to plot a line with the end points specified.

WHERE TO DRAW A LINE?? Line drawing is accomplished by calculating intermediate positions along the line path between specified end points. Precise definition of line drawing Given two points P and Q in the plane, both with integer coordinates, determine which pixels on a raster screen should be on in order to make a picture of a unit- width line segment starting from P and ending at Q.

Line drawing (cont) The thinnest line is of one-pixel wide. We will concentrate on drawing a line of 1 pixel resolution. The Cartesian slope-intercept equation for a straight line is y= m. x + b m is the slope of the line and b is the y intercept. Given the endpoints of a line segment. m = y2-y1 / x2-x1 b= y1-m.x1

Bresenham’s Line Algorithm An accurate, efficient raster line drawing algorithm developed by Bresenham, scan converts lines using only incremental integer calculations that can be adapted to display circles and other curves.

xk xk+1 Xk+2 Xk+3 yk yk+1 yk+2 yk+3 Section of the screen grid showing a pixel in column xk on scan line yk that is to be plotted along the path of a line segment with slope 0<m<1

In the figure mentioned left side vertical axis show scan line position and horizontal axes identify pixel columns. The sampling method at unit x interval cannot be adopted to the above lines, because we need to decide which of the two possible pixel position is closer to the line path at each sample step.

Starting from the left end point (x 0,y 0 ) of a given line, we step to each successive column (x position) and plot the pixel whose scan-line y value closest to the line path. Assuming we have determined that the pixel at (x k,y k ) is to be displayed, we next need to decide which pixel to plot in column x k+1. (x k+1,yk) or (x k+1, y k+1 )‏ Illustration of Bresenham’s Algorithm Consider the scan conversion process for the lines with positive lines with positive slope less than 1.

The difference between these 2 separations is Choices are (x k +1, y k ) and (x k +1, y K +1)‏ d 1 = y – y k = m(x k + 1) + b – y k d 2 = (y k + 1) – y = y k + 1- m(x k + 1) – b d1-d2 = 2m(xk + 1) – 2 yk + 2b – 1

A decision parameter pk for the kth step in the line algorithm can be obtained by rearranging above equation so that it involves only integer calculations. The decision parameter pk is obtained by substituting m = Δy/ Δx Define Pk = Δx ( d1-d2) = 2Δy.xk-2 Δx. yk + c

 The sign of Pk is the same as the sign of d1- d2, since Δx > 0.  Parameter c is a constant and has the value 2Δy + Δx(2b-1) (independent of pixel position)‏  Check the sign of pk (i.e, if d1 < d2) then pk is negative. Then pixel at yk is closer to line-path than pixel at yk +1 We plot lower pixel in such a case (xk+1, yk). Otherwise, upper pixel will be plotted (xk+1, yk+1).

 At step k + 1, the decision parameter can be evaluated as, pk+1 = 2Δyxk+1 - 2Δxyk+1 + c  Taking the difference of pk+ 1 and pk we get the following. pk+1 – pk = 2Δy(xk+1- xk)-2Δx(yk+1 – yk)‏ But, xk+1 = xk +1, so that pk+1 = pk + 2Δy - 2 Δx(yk+1 – yk)‏ Where the term yk+1-yk is either 0 or 1, depending on the sign of parameter pk

The first parameter p 0 is directly computed from the equation Pk = Δx ( d1-d2) = 2Δy.xk-2 Δx. yk + c ie p 0 = 2 Δy x k - 2 Δx y k + c = 2 Δy x k – 2 Δy + Δx (2b-1)‏ Since (x 0,y 0 ) satisfies the line equation, we also have y 0 = Δy/ Δx * x 0 + b Combining the above 2 equations, we will have p 0 = 2Δy – Δx The constants 2Δy and 2Δy-2Δx are calculated once for each time to be scan converted

So, the arithmetic involves only integer addition and subtraction of 2 constants 1.Input the two end points and store the left end Point in (x0,y0)‏ 2. Load (x 0,y 0 ) into the frame buffer (plot the first point)‏ 3. Calculate the constants Δx, Δy, 2Δy and 2Δy-2Δx and obtain the starting value for the decision parameter as p 0 = 2Δy- Δx Steps for Bresenhms Line Drawing Algorithm

4. At each x k along the line, starting at k=0, perform the following test: If p k < 0, the next point is (x k +1, y k ) and p k+1 = p k + 2Δy Otherwise Point to plot is (x k +1, y k +1) p k+1 = p k + 2Δy - 2Δx 5. Repeat step 4 (above step) Δx times