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.

Slides:



Advertisements
Similar presentations
Objective - To graph linear equations using the slope and y-intercept.
Advertisements

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.
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.
2.2 Linear Equations.
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.
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
Komputer Grafik 2 (AK045206) Scan Conversion 1/31 Scan Conversion.
Raster conversion algorithms for line and circle
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 50 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 45 Computer Graphics Implementation I.
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.
Rules of Integers. Positive numbers are numbers that are above zero. Negative numbers are numbers below zero.
1.2 Linear Equations in Two Variables
Dr. Scott Schaefer Scan Conversion of Lines. 2/78 Displays – Cathode Ray Tube.
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
Graphics Primitives: line. Pixel Position
Scan Conversion Line and Circle
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
Slope – Intercept Form y = mx + b m represents the slope b represents the y-intercept.
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.
Three forms for describing linear functions using equations.
 A line segment in a scene is defined by the coordinate positions of the line end-points x y (2, 2) (7, 5)
CS-321 Dr. Mark L. Hornick 1 Line Drawing Algorithms.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
Quick Graphs Using Slope-Intercept form 4.6 Objective 1 – Graph a linear equation in slope-intercept form.
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
Solving 1-Step Equations 2 An Equation is Like a Balance.
Scan Conversion.
Graphing Linear Inequations y > y is greater than  all points above the line are a solution y < y is less than  all points below the line are a solution.
Bresenham’s Line Algorithm
Lecture 2: 19/4/1435 Graphical algorithms Lecturer/ Kawther Abas CS- 375 Graphics and Human Computer Interaction.
Scan Conversion of Line Segments. What is Scan conversion? Final step of rasterization (the process of taking geometric shapes and converting them into.
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.
1. Write the equation in standard form.
Linear Equations in Two Variables
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Equations of Lines.
1 Step Equation Practice + - x ÷
CSCE 441 Lecture 2: Scan Conversion of Lines
Rasterizing Lines 2 Lecture 33 Wed, Nov 14, 2007.
4.5 Point-Slope form of a linear equation
2D Scan-line Conversion
Line Drawing ©Anthony Steed 1999.
Rasterizing Lines 1 Lecture 32 Mon, Nov 12, 2007.
Writing Linear Equations in Standard Form
Edited from The Rasterization Problem: Idealized Primitives Map to Discrete Display Space Edited from.
Convert Standard to Slope-Intercept
Standard Form Section 5-5.
Write and graph lines in point-slope form and standard form
Graphing Functions x f(x) = 2x (2) + 7 = (3) + 7 = 13 4
Lines in the Plane and Slope
Line Drawing Algorithms
Presentation transcript:

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

Revised Slope Intercept DrawLine (Point point1, Point point2){ m=(point2.y-point1.y) / (point2.x-point2.x); b=point1.y + (-point1.x) * m; if (m>1){ for i = point1.x to < point2.x { SetPixel(i, round(i*m+b)); } else{ for i = point1.y to point2.y { SetPixel(round(i-b/m), i); } Which one should we use if m=1? What is the cost per pixel?

Optimization (DDA Algorithm) Since we increment y by the same amount, we can also inline rounding: New cost: one floating point addition, one integer addition, one cast. DrawLine (Point point1, Point point2){ m=(point2.y-point1.y) / (point2.x-point2.x); j=point1.y + (-point1.x) * m + 0.5; for i=point1.x to point2.x SetPixel(i, (int)j+=m)); }

Optimizations In general processing unit: –Addition and Subtraction are faster than Multiplication which is faster than Division –Integer calculations are faster than Floating and double calculations –Logical operation is lighter the math operations –Bitwise operation is the lightest

Bresenham Line Drawing Algorithm Let us consider a line equation y = mx + b could be written as F (x, y) =ax + by + c F(x,y) is zero on the line, positive above the, and negative below the line M E NE if ( d > 0) then we choose NE If ( d < 0 ) then we choose E If ( d == 0) we choose any of them

Bresenham Line Drawing Algorithm What happens to next grid point after x p +2, that depends on whether we select E or NE. If E was selected then M E NE If NE was selected then Since the first point (x 0,y 0 ) We can directly calculate d to choose NE or E

public void DrawLine(Point point1, Point point2) { int dy = point2.y - point1.y; int dx = point2.x - point1.x; dy <<= 1; // dy is now 2*dy dx <<= 1; // dx is now 2*dx int fraction = dy - (dx >> 1); // same as 2*dy - dx j=point1.y; for (i=point1.x; i<point2.x; i++) { if (fraction >= 0) { j++; fraction -= dx; // same as fraction -= 2*dx } fraction += dy; // same as fraction -= 2*dy SetPixel(i, j); }