CS-321 Dr. Mark L. Hornick 1 Line Drawing Algorithms.

Slides:



Advertisements
Similar presentations
Graphics Primitives: line
Advertisements

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.
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.
Line Drawing Algorithms
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.
Lecture 5 Rendering lines 1.Steps of line rendering 2.Scan-conversion for line segments 3.A1 tutorial CP411 Computer Graphics Fall 2007 Wilfrid Laurier.
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.
Lecture 17 Fun with Graphics Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
The lines of this object appear continuous However, they are made of pixels 2April 13, 2015.
CS 376 Introduction to Computer Graphics 01 / 29 / 2007 Instructor: Michael Eckmann.
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.
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.
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
CS 325 Introduction to Computer Graphics 02 / 01 / 2010 Instructor: Michael Eckmann.
1Computer Graphics Implementation III Lecture 17 John Shearer Culture Lab – space 2
1 Circle Drawing Algorithms Pictures snagged from
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
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.
10/15/02 (c) 2002 University of Wisconsin, CS559 Who Am I? Prof Stephen Chenney These notes will be online after the lecture – in fact they’re online already.
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.
CS 551 / 645: Introductory Computer Graphics
Rendering.
Lecture 13: Raster Graphics and Scan Conversion
Bresenham’s Line Algorithm
Example: (7,9) (12,0) Example 2: Point1 V:(7,9 ) C:( 0,255,0) Point2 V:(12,0) C:(0,255,0) (0,0) (18,0) (0,9) What are the problems with this method? Slope>1.
Lecture 2: 19/4/1435 Graphical algorithms Lecturer/ Kawther Abas CS- 375 Graphics and Human Computer Interaction.
Rasterization Overview Raster Display Device. Scan Conversion / Rasterization: converting vector graphics into raster graphics (determining pixels in.
Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing
Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
Rasterization CENG 477 Introduction to Computer Graphics Slides from Steve Marschner, CS4620, 2008 Cornell University.
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.
Computer Graphics Lecture 05 Line Drawing Techniques Taqdees A. Siddiqi
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.
CSCE 441 Lecture 2: Scan Conversion of Lines
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Lecture 8 Shear and Line Drawing Algorithms
Implementation III.
CSCE 441 Lecture 2: Scan Conversion of Lines
2D Scan-line Conversion
Line Drawing ©Anthony Steed 1999.
Rasterization and Antialiasing
Line Drawing Algorithms
Computer Graphics Implementation III
Rasterization and Antialiasing
Edited from The Rasterization Problem: Idealized Primitives Map to Discrete Display Space Edited from.
S.JOSEPHINE THERESA, DEPT OF CS, SJC, TRICHY-2
Line Drawing Algorithms
Presentation transcript:

CS-321 Dr. Mark L. Hornick 1 Line Drawing Algorithms

CS-321 Dr. Mark L. Hornick 2 Line Drawing Algorithms (x 0, y 0 ) (x 1, y 1 ) Which pixels should be set to represent the line?

CS-321 Dr. Mark L. Hornick 3 Line Equations (x 0, y 0 ) (x 1, y 1 )

CS-321 Dr. Mark L. Hornick 4 Simple Algorithm Start x at origin of line Evaluate y value Set nearest pixel (x,y) Move x one pixel toward other endpoint Repeat until done

CS-321 Dr. Mark L. Hornick 5 Implementation How does this work? // SimplePixelCalc - elementary pixel calculation using // variation of y=mx+b void SimplePixelCalc( int x0, int xn, int y0, int yn ) { for( int ix=x0; ix<=xn; ix++ ) { float fy = y0 + float(yn-y0)/float(xn-x0)*ix; // round to nearest whole integer int iy = (int)(fy+0.5); SetPixel(ix, iy, 1); // write pixel value } How well does this work?

CS-321 Dr. Mark L. Hornick 6 Use the lab1 program on the following coordinates Example 1 (x 0, y 0 ) = (0,1) (x 1, y 1 ) = (10,4) Example 2 (x 0, y 0 ) = (0,8) (x 1, y 1 ) = (9,0) Example 3 (x 0, y 0 ) = (0,1) (x 1, y 1 ) = (2,7)

CS-321 Dr. Mark L. Hornick 7 Example 1 Results? m=0.3

CS-321 Dr. Mark L. Hornick 8 Example 2 Results? m=-0.89

CS-321 Dr. Mark L. Hornick 9 Example 3 Results? m=3

CS-321 Dr. Mark L. Hornick 10 Simple Algorithm Adjustment for m If |m|<1 If |m|>1 If |m|=1 x = y

11 Simple Algorithm Summary Evaluate y = f(x) at each x position Requires floating multiplication for each evaluation of y

CS-321 Dr. Mark L. Hornick 12 Digital Differential Analyzer (DDA) Algorithm Step through either x or y based on slope Build the line parametrically If |m|<1 x k+1 = x k + 1 y k+1 = y k + m If |m|>1 x k+1 = x k + 1/m y k+1 = y k + 1 If |m|=1 x k+1 = x k + 1 y k+1 = y k + 1

CS-321 Dr. Mark L. Hornick 13 DDA Implementation void dda( int x0, int xn, int y0, int yn ) { float dx = float(xn - x0); // total span in x float dy = float(yn - y0); // total span in y float y = float(y0); float x = float(x0); float Dx, Dy; // incremental steps in x & y // determine if slope m GT or LT 1 if( dx > dy ) { Dx = 1; Dy = dy/dx;// floating division, but only done once per line } else { Dx = dx/dy; Dy = 1; } int ix, iy; // pixel coords for( int k=0; k dy)? dx:dy); k++ ) { ix = int(x + 0.5); // round to nearest pixel coordinate iy = int(y + 0.5); x += Dx;// floating point calculations y += Dy; }

CS-321 Dr. Mark L. Hornick 14 DDA Results?

CS-321 Dr. Mark L. Hornick 15 DDA Algorithm Highlights Reduction in strength Replaces multiplication with addition Still some limitations Round-off error accumulates Floating point addition (e.g. not on PPC)

16 Line-Drawing Algorithms Simple algorithm Evaluate y = f(x) at each x position Floating multiplication DDA algorithm Floating addition only Can we do better? Tomorrow: Bresenham’s algorithm!