Chapter 3 Scan Conversion Lecture-02. Bresenham’s Line Algorithm Bresenham’s line algorithm – is a highly efficient incremental method for scan- converting.

Slides:



Advertisements
Similar presentations
Circle Drawing Asst. Prof. Dr. Ahmet Sayar Kocaeli University
Advertisements

Contents In today’s lecture we’ll have a look at:
Graphics Primitives Part II: Bresenhams line and circle.
Graphics Primitives: line
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
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.
CS 376 Introduction to Computer Graphics 02 / 02 / 2007 Instructor: Michael Eckmann.
Computer Graphics 4: Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling By:Kanwarjeet Singh.
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
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.
Komputer Grafik 2 (AK045206) Scan Conversion 1/31 Scan Conversion.
2D Output Primitives Graphics packages provide basic operations (called primitive operations) to describe a scene in terms of geometric structures. The.
Raster conversion algorithms for line and circle
Drawing Lines The Bresenham Algorithm for drawing lines and filling polygons.
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.
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Scan Conversion CS123 1 of 44Scan Conversion - 10/14/2014.
Rasterization Foley, Ch: 3. Pixels are represented as disjoint circles centered on uniform grid Each (x,y) of the grid has a pixel Y X (1,1) (1,2) (0,0)
©Zachary Wartell, Larry F. Hodges Scan Conversion I Revision 1.6 8/9/2007 Copyright 2006, Dr. Zachary Wartell, UNCC, All Rights Reserved.
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
Circle Drawing algo..
Rasterizing primitives: know where to draw the line Dr Nicolas Holzschuch University of Cape Town Modified.
College of Computer and Information Science, Northeastern UniversitySeptember 12, CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture.
1 CS 430/536 Computer Graphics I Circle Drawing and Clipping Week 3, Lecture 6 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent.
Dr. S.M. Malaek Assistant: M. Younesi
Jehee Lee Seoul National University
1 CPE 333 : Computer Graphics มหาวิทยาลัยเทคโนโลยีพระจอม เกล้าธนบุรี Dr. Natasha Dejdumrong.
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 & Graphical Programming Lecture 14 - Lines & Circles.
Introduction Computer Graphics & Its application Types of computer graphics Graphic display : random Scan & Raster Scan display Frame buffer and video.
1 Line Drawing Version B: Semi-Formal Methods Derivation ©Anthony Steed
Graphics Output Primitives
Line Drawing and Generalization. Outline  overview  line drawing  circle drawing  curve drawing.
 A line segment in a scene is defined by the coordinate positions of the line end-points x y (2, 2) (7, 5)
MIDPOINT CIRCLE & ELLIPSE GENERARTING ALGORITHMS
November 18, We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle.
Computer Graphics Drawing Line. Lines and Polylines Convex: For every pair of points in the polygon, the line between them is fully contained in the polygon.
Midpoint Circle Algorithm
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
Scan Conversion.
Bresenham’s Line Algorithm
Rasterization Overview Raster Display Device. Scan Conversion / Rasterization: converting vector graphics into raster graphics (determining pixels in.
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.
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
Scan Conversion of Line Segments. What is Scan conversion? Final step of rasterization (the process of taking geometric shapes and converting them into.
OUTPUT PRIMITIVES CEng 477 Computer Graphics METU, 2004.
Objectives Understand Bresenhams line drawing algorithm. Apply the algorithm to plot a line with the end points specified.
Primitive graphic objects
Scan Conversion or Rasterization
CS G140 Graduate Computer Graphics
Scan Conversion or Rasterization
Prof. Harriet Fell Spring 2007 Lecture 5 – January 17, 2006
Scan Conversion of Circles
Rasterizing Lines 2 Lecture 33 Wed, Nov 14, 2007.
2D Scan-line Conversion
Rasterizing Lines 1 Lecture 32 Mon, Nov 12, 2007.
Scan Conversion Line(DDA Line and Bresenham Line)
Chapter 3 Graphics Output Primitives
Presentation transcript:

Chapter 3 Scan Conversion Lecture-02

Bresenham’s Line Algorithm Bresenham’s line algorithm – is a highly efficient incremental method for scan- converting lines. – It produces mathematically accurate results using only integer addition, subtraction and multiplication by 2, which can be accomplished by a simple arithmetic shift operation.

Bresenham’s Line Algorithm Scan convert the line in the Figure, 0<m<1. Start with pixel P 1 (x 1,y 1 ). Choose either the pixel on the right or the pixel right and up. The coordinates of the last chosen pixel upon entering step i are (x i, y i ). Choose the next between the bottom pixel S and the top pixel T. p1 p2

The difference is – s – t = (y-y i )-[(y i +1)-y] = y-y i -y i -1+y = 2y-2y i -1 = 2(y-y i )-1 = 2 [ { m(x i + 1) + b } - y i ) ] - 1 = 2 m(x i + 1) + 2b - 2y i – 1 ∆x( s – t)=∆x [2m(x i + 1) + 2b - 2y i – 1] So di = ∆x [2m(x i + 1) + 2b - 2y i – 1] ……………. (i) If the chosen pixel is the top pixel T (di ≥ 0) then xi+1 = xi+1 and y i +1 = y i + 1 and so d i+1 = d i + 2 (Δy - Δx) Bresenham’s Line Algorithm

If the chosen pixel is pixel S (d i < 0) then x i+1 = x i +1 and y i+1 = y i and so d i+1 = d i + 2Δy where d i = 2Δy * x i - 2Δx * y i +C and C = 2Δy + Δx (2b – 1) We use here a decision variable d i. For the value of each d i we calculate the corresponding value of d i+1. p1 p2

Hence, we have Finally, we calculate d 1,the base case value for this recursive formula, from the original definition of the decision variable d i d i = ∆x [ 2m (x 1 + 1) + 2b - 2y 1 – 1] = ∆x [ 2( mx 1 + b - y 1 ) + 2m – 1] = ∆x [ 2*0 + 2m – 1] = 2(∆y / ∆x)* ∆x - ∆x =2∆y - ∆x Bresenham’s Line Algorithm

Void Bresenham( ) { Line 1: dx=x2-x1; Line 2: dy=y2-y1; Line 3: dT=2*(dy-dx); Line 4: dS=2*dy; Line 5: d=(2*dy)-dx; Line 6: putpixel(x1,y1); Line 7: while(x1<x2) Line 8: { Line 9: x1++; Line 10: if(d<0) Line 11: { Line 12: d=d+dS; Line 13: putpixel(x1,y1); Line 14: } Line 15: else Line 16: { Line 17: y1++; Line 18: d=d+dT; Line 19: putpixel(x1,y1); Line 20: } Line 21: } Line 22: putpixel(x2,y2); }

Scan-Converting a Circle

Midpoint Circle Algorithm Implicit of equation of circle is: x 2 + y 2 - R 2 = 0 Eight way symmetry  require to calculate one octant Define decision variable d as: P=(x p, y p ) M E x p +1xpxp x p +2 Previous Current Next MEME ypyp y p – 1 y p – 2 SE M SE

Midpoint Circle Algorithm If d <= 0 then midpoint m is inside circle – we choose E – Increment x – y remains unchanged P=(x p, y p ) M E x p +1xpxp x p +2 Previous Current Next MEME ypyp y p – 1 y p – 2 d < 0

Midpoint Circle Algorithm If d > 0 then midpoint m is outside circle – we choose S – Increment x – Decrement y Previous P=(x p, y p ) M SE x p +1xpxp x p +2 Current Next M SE ypyp y p – 1 y p – 2 d > 0

Midpoint Circle Algorithm Initial condition Starting pixel (0, R) Next Midpoint lies at (1, R – ½) d 0 = F(1, R – ½) = 1 + (R 2 – R + ¼) – R 2 = 5 / 4 – R To remove the fractional value 5 / 4 : d 0 = 1– R

We can now summarize the algorithm for generating all the pixel coordinates in the 90 0 to 45 0 octant : Line 1 : Int x=0,y=r,p=1-r; Line 2 : While(x<=y) Line 3 : { Line 4 : setPixel(x,y); Line 5 : If(p<0) Line 6 : p=p+2x+3; Line 7 : Else Line 8 : { Line 9 : P=p+2(x-y)+5; Line 10 : y--; Line 11 : } Line 12 : x++; Line 1 3: } Midpoint Circle Algorithm