Line Drawing Algorithms

Slides:



Advertisements
Similar presentations
Line Drawing Algorithms
Advertisements

Graphics Primitives: line
5.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 5 – Drawing A 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.
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.
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.
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.
CS 376 Introduction to Computer Graphics 01 / 29 / 2007 Instructor: Michael Eckmann.
Computer Graphics Tz-Huan Huang National Taiwan University (Slides are based on Prof. Chen’s)
Advanced Manufacturing Laboratory Department of Industrial Engineering Sharif University of Technology Session # 7.
OUTPUT PRIMITIVES Screen vs. World coordinate systems ● Objects positions are specified in a Cartesian coordinate system called World Coordinate.
Lecture 16 Fun with graphics
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
Output Primitives Computer Graphics.
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.
CAP4730: Computational Structures in Computer Graphics Chapter 3 Hearn & Baker Portions obtained from Leonard McMillan’s COMP136 Notes:
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
Rounding Revision.
Dr. Scott Schaefer Scan Conversion of Lines. 2/78 Displays – Cathode Ray Tube.
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.
Rounding off numbers 10 thousands thousands hundreds 1/ /100
Introduction Computer Graphics & Its application Types of computer graphics Graphic display : random Scan & Raster Scan display Frame buffer and video.
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.
1 Sung-Ju Kang Department of Physics Kangwon National University Basic Concept of The Computer Graphic. For the investigation of the physical problem by.
CS-321 Dr. Mark L. Hornick 1 Line Drawing Algorithms.
1 CSCE 441 Lecture 2: Scan Conversion of Lines Jinxiang Chai.
GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.
Scan Conversion.
Lecture 13: Raster Graphics and Scan Conversion
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 CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing.
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.
IT- 601: Computer Graphics Lecture-00 Jesmin Akhter Lecturer,IIT Jahangirnagar University, Savar, Dhaka,Bangladesh 9/30/2016.
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.
Primitive graphic objects
CSCE 441 Lecture 2: Scan Conversion of Lines
Rounding Extra practice.
Lecture 9 Line Drawing Algorithms (Bresenham’s Line Algorithm)
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Polygon Filling Algorithms
Scan Conversion of Lines
CSCE 441 Lecture 2: Scan Conversion of Lines
2D Scan-line Conversion
Rasterizing Lines 1 Lecture 32 Mon, Nov 12, 2007.
Introduction to Computer Graphics
Rasterization and Antialiasing
Rasterization and Antialiasing
Round off 38 to the nearest ten.
How Computers Work Part 1 6 February 2008.
Line Drawing Algorithms
OUTPUT PRIMITIVES / DISPLAY TECHNIQUES
Presentation transcript:

Line Drawing Algorithms Mohammad Sharaf

How does computer draw line? Screen made of pixels High-level language specifies line System must color pixels

DDA Algorithm Start with starting and ending coordinates of the line: (x0, y0) and (x1, y1) Color first pixel (round to nearest integer) Suppose x1-x0 > y1-y0 (gentle slope) There will be x1-x0 steps (# pixels to be colored) Set x=x0, y=y0 At each step, increment x by (x1-x0)/numsteps, and increment y by (y1-y0)/numsteps For each step, round off x and y to nearest integer, and color pixel

DDA Pseudo-code // assume that slope is gentle DDA(float x0, float x1, float y0, float y1) { float x, y; float xinc, yinc; int numsteps; numsteps = Round(x1) – Round(x0); xinc = (x1 – x0) / numsteps; yinc = (y1 – y0) / numsteps; x = x0; y = y0; ColorPixel(Round(x),Round(y)); for (int i=0; i<numsteps; i++) { x += xinc; y += yinc; } Q: For each step, how many floating point operations are there? A: 4 Q: For each step, how many integer operations are there? A: 2

DDA Example numsteps = 12 – 2 = 10 xinc = 10/10 = 1.0 yinc = 5/10 = 0.5 Suppose we want to draw a line starting at pixel (2,3) and ending at pixel (12,8). What are the values of the variables x and y at each timestep? What are the pixels colored, according to the DDA algorithm? t x y R(x) R(y) 2 3 1 3.5 4 5 4.5 6 7 5.5 8 9 6.5 10 11 7.5 12

DDA Algorithm (continued) Y_inc X_inc … but floating point operations and rounding operations are expensive

Bresenham’s Algorithm Uses only integer calculations Uses distance between ideal y-coordinate and the upper and lower pixel (assuming gentle slope) dupper dlower

General idea how Bresenham works Suppose that the line is gently sloping upwards from left to right. Start by coloring the left-most pixel. Then, for the next column (that is, for each x value), we have to figure out whether we color the same y or y+1. How do we decide? When going from one column to the next, add an error value. If the error value is more than 0.5, we should color y+1 and reset the error value. Otherwise, color y and accumulate the error value. However, it seems like we’re still using floating point Solution, multiply both sides by 2 so that we use integer comparisons instead.

Bresenham’s Algorithm Input the two line endpoints and store left endpoint as (x0,y0) Pre-calculate the values dx, dy, 2dy and 2dy - 2dx Color pixel (x0,y0) Let p0 = 2dy – dx At each xk along the line, starting with k=0: Repeat Step-4 dx times If pk<0, then the next point to plot is (xk + 1,yk), and pk+1 = pk + 2dy Otherwise, the next point to plot is (xk + 1, yk + 1), and pk+1 = pk + 2dy – 2dx Switch Point 0 and Point 1 if necessary If negative slope, reflect If steep slope, flip y and x

Number of Operations in Bresenham’s Algorithm Q: In each step, how many floating point operations are there? A: 0 Q: In each step, how many integer operations are there? A: 3 or 4

Bresenham’s Algorithm Example dx = 12 – 2 = 10 dy = 8 – 3 = 5 p0 = 2dy – dx = 15 2dy = 10 2dy – 2dx = -10 Suppose we want to draw a line starting at pixel (2,3) and ending at pixel (12,8). What are the values of p0, dx and dy? What are the values of the variable p at each timestep? What are the pixels colored, according to Bresenham’s algorithm? t p P(x) P(y) 2 3 1 -10 4 5 6 7 8 9 10 11 12