CS 543: Computer Graphics Lecture 9 (Part I): Raster Graphics: Drawing Lines. Emmanuel Agu



Similar documents
Scan Conversion of Filled Primitives Rectangles Polygons. Many concepts are easy in continuous space - Difficult in discrete space

Scan-Line Fill. Scan-Line Algorithm. Sort by scan line Fill each span vertex order generated by vertex list

G.H. Raisoni College of Engineering, Nagpur. Department of Information Technology

Monash University Clayton s School of Information Technology CSE3313 Computer Graphics Sample Exam Questions 2007

Image Processing and Computer Graphics. Rendering Pipeline. Matthias Teschner. Computer Science Department University of Freiburg

Introduction to Computer Graphics

1. Application of Computer Graphics

Line and Polygon Clipping. Foley & Van Dam, Chapter 3

B2.53-R3: COMPUTER GRAPHICS. NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions.

VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur

Image Synthesis. Transparency. computer graphics & visualization

Geometric Transformations

INTRODUCTION TO RENDERING TECHNIQUES

Computer Graphics CS 543 Lecture 12 (Part 1) Curves. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Computer Graphics Lecture Notes

Cabri Geometry Application User Guide

A Short Introduction to Computer Graphics

Computer Graphics Hardware An Overview

Lecture Notes, CEng 477

Section 1.1 Linear Equations: Slope and Equations of Lines

What does the number m in y = mx + b measure? To find out, suppose (x 1, y 1 ) and (x 2, y 2 ) are two points on the graph of y = mx + b.

We can display an object on a monitor screen in three different computer-model forms: Wireframe model Surface Model Solid model

Linear Programming. March 14, 2014

1.1 Practice Worksheet

MATH 095, College Prep Mathematics: Unit Coverage Pre-algebra topics (arithmetic skills) offered through BSE (Basic Skills Education)

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Computer Graphics

Florida Math Correlation of the ALEKS course Florida Math 0028 to the Florida Mathematics Competencies - Upper

Practice with Proofs

2014 Chapter Competition Solutions

Quickstart for Desktop Version

Exam 1 Sample Question SOLUTIONS. y = 2x

Polynomials. Key Terms. quadratic equation parabola conjugates trinomial. polynomial coefficient degree monomial binomial GCF

Linear and quadratic Taylor polynomials for functions of several variables.

Higher Education Math Placement

COWLEY COUNTY COMMUNITY COLLEGE REVIEW GUIDE Compass Algebra Level 2

Math 120 Final Exam Practice Problems, Form: A

EQUATIONS and INEQUALITIES

Drawing Lines with Pixels. Joshua Scott March 2012

Introduction Week 1, Lecture 1

Computer Science 217

TWO-DIMENSIONAL TRANSFORMATION

Answer Key for California State Standards: Algebra I

Algebra 2 PreAP. Name Period

Contents. 2 Lines and Circles Cartesian Coordinates Distance and Midpoint Formulas Lines Circles...

2: Introducing image synthesis. Some orientation how did we get here? Graphics system architecture Overview of OpenGL / GLU / GLUT

4. How many integers between 2004 and 4002 are perfect squares?

Solving Quadratic Equations

GeoGebra. 10 lessons. Gerrit Stols

ab = c a If the coefficients a,b and c are real then either α and β are real or α and β are complex conjugates

The Point-Slope Form

Mathematics Pre-Test Sample Questions A. { 11, 7} B. { 7,0,7} C. { 7, 7} D. { 11, 11}

Answer: The relationship cannot be determined.

SPECIAL PRODUCTS AND FACTORS

Computer Graphics. Anders Hast

Section 1: How will you be tested? This section will give you information about the different types of examination papers that are available.

What are the place values to the left of the decimal point and their associated powers of ten?

Each function call carries out a single task associated with drawing the graph.

2.3 WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION

Lecture 2 Mathcad Basics

Graphics Module Reference

MATH 21. College Algebra 1 Lecture Notes

a. all of the above b. none of the above c. B, C, D, and F d. C, D, F e. C only f. C and F

Algebra II End of Course Exam Answer Key Segment I. Scientific Calculator Only

Triangulation by Ear Clipping

CS 4204 Computer Graphics

MA107 Precalculus Algebra Exam 2 Review Solutions

GPU(Graphics Processing Unit) with a Focus on Nvidia GeForce 6 Series. By: Binesh Tuladhar Clay Smith

Algebra and Geometry Review (61 topics, no due date)

Visualization and Feature Extraction, FLOW Spring School 2016 Prof. Dr. Tino Weinkauf. Flow Visualization. Image-Based Methods (integration-based)

Graphing - Parallel and Perpendicular Lines

MMGD0203 Multimedia Design MMGD0203 MULTIMEDIA DESIGN. Chapter 3 Graphics and Animations

Examples of Functions

Solving Systems of Linear Equations Graphing

x 2 + y 2 = 1 y 1 = x 2 + 2x y = x 2 + 2x + 1

Shader Model 3.0. Ashu Rege. NVIDIA Developer Technology Group

The Evolution of Computer Graphics. SVP, Content & Technology, NVIDIA

Nonlinear Algebraic Equations. Lectures INF2320 p. 1/88

Gerrit Stols

Vector Notation: AB represents the vector from point A to point B on a graph. The vector can be computed by B A.

Tessellating with Regular Polygons

Real Roots of Univariate Polynomials with Real Coefficients

AP Calculus AB 2006 Scoring Guidelines

1 Shapes of Cubic Functions

Chapter One Introduction to Programming

GPU Architecture. Michael Doggett ATI

Examples. Pac-Man, Frogger, Tempest, Joust,

Triangle Scan Conversion using 2D Homogeneous Coordinates

An Extremely Inexpensive Multisampling Scheme

Factoring Quadratic Expressions

1.4. Arithmetic of Algebraic Fractions. Introduction. Prerequisites. Learning Outcomes

Graphing - Slope-Intercept Form

Slope-Intercept Equation. Example

Graphical displays are generally of two types: vector displays and raster displays. Vector displays

Florida Math for College Readiness

COMP175: Computer Graphics. Lecture 1 Introduction and Display Technologies

Additional Topics in Math

SAT Math Facts & Formulas Review Quiz

How To Teach Computer Graphics

15.1 Factoring Polynomials

Transcription:

CS 543: Computer Graphics Lecture 9 (Part I): Raster Graphics: Drawing Lines Emmanuel Agu

2D Graphics Pipeline Clipping Object World Coordinates Applying world window Object subset window to viewport mapping Simple 2D Drawing Pipeline Display Rasterization Object Screen coordinates

Rasterization (Scan Conversion) Convert high-level geometry description to pixel colors in the frame buffer Example: given vertex x,y coordinates determine pixel colors to draw line Two ways to create an image: Scan existing photograph Procedurally compute values (rendering) Viewport Transformation Rasterization

Rasterization A fundamental computer graphics function Determine the pixels colors, illuminations, textures, etc. Implemented by graphics hardware Rasterization algorithms Lines Circles Triangles Polygons

Rasterization Operations Drawing lines on the screen Manipulating pixel maps (pixmaps): copying, scaling, rotating, etc Compositing images, defining and modifying regions Drawing and filling polygons Previously glbegin(gl_polygon), etc Aliasing and antialiasing methods

Line drawing algorithm Programmer specifies (x,y) values of end pixels Need algorithm to figure out which intermediate pixels are on line path Pixel (x,y) values constrained to integer values Actual computed intermediate line values may be floats Rounding may be required. E.g. computed point (10.48, 20.51) rounded to (10, 21) Rounded pixel value is off actual line path (jaggy!!) Sloped lines end up having jaggies Vertical, horizontal lines, no jaggies

Line Drawing Algorithm 8 7 6 5 4 3 2 1 Line: (3,2) -> (9,6)? Which intermediate pixels to turn on? 0 1 2 3 4 5 6 7 8 9 10 11 12

Line Drawing Algorithm Slope-intercept line equation y = mx + b Given two end points (x0,y0), (x1, y1), how to compute m and b? m dy y1 y0 = = b = y0 m * x0 dx x1 x0 (x1,y1) dy (x0,y0) dx

Line Drawing Algorithm Numerical example of finding slope m: (Ax, Ay) = (23, 41), (Bx, By) = (125, 96) m = By Bx Ay Ax = 96 41 125 23 = 55 102 = 0.5392

Digital Differential Analyzer (DDA): Line Drawing Algorithm Walk through the line, starting at (x0,y0) Constrain x, y increments to values in [0,1] range Case a: x is incrementing faster (m < 1) Step in x=1 increments, compute and round y Case b: y is incrementing faster (m > 1) Step in y=1 increments, compute and round x m>1 (x1,y1) m=1 (x0,y0) dx dy m<1

DDA Line Drawing Algorithm (Case a: m < 1) yk +1 = yk + m (x1,y1) x = x0 y = y0 Illuminate pixel (x, round(y)) x = x0 + 1 y = y0 + 1 * m Illuminate pixel (x, round(y)) x = x + 1 y = y + 1 * m Illuminate pixel (x, round(y)) (x0, y0) Until x == x1

DDA Line Drawing Algorithm (Case b: m > 1) x k + 1 = xk + 1 m (x1,y1) x = x0 y = y0 Illuminate pixel (round(x), y) y = y0 + 1 x = x0 + 1 * 1/m Illuminate pixel (round(x), y) y = y + 1 x = x + 1 /m Illuminate pixel (round(x), y) (x0,y0) Until y == y1

DDA Line Drawing Algorithm Pseudocode compute m; if m < 1: { } float y = y0; // initial value for(int x = x0;x <= x1; x++, y += m) else // m > 1 { } float x = x0; setpixel(x, round(y)); // initial value for(int y = y0;y <= y1; y++, x += 1/m) setpixel(round(x), y); Note: setpixel(x, y) writes current color into pixel in column x and row y in frame buffer

Line Drawing Algorithm Drawbacks DDA is the simplest line drawing algorithm Not very efficient Round operation is expensive Optimized algorithms typically used. Integer DDA E.g.Bresenham algorithm (Hill, 10.4.1) Bresenham algorithm Incremental algorithm: current value uses previous value Integers only: avoid floating point arithmetic Several versions of algorithm: we ll describe midpoint version of algorithm

Bresenham s Line-Drawing Algorithm Problem: Given endpoints (Ax, Ay) and (Bx, By) of a line, want to determine best sequence of intervening pixels First make two simplifying assumptions (remove later): (Ax < Bx) and (0 < m < 1) Define Width W = Bx Ax Height H = By - Ay (Bx,By) (Ax,Ay)

Bresenham s Line-Drawing Algorithm Based on assumptions: W, H are +ve H < W As x steps in +1 increments, y incr/decr by <= +/ 1 y value sometimes stays same, sometimes increases by 1 Midpoint algorithm determines which happens

Bresenham s Line-Drawing Algorithm (x1,y1) What Pixels to turn on or off? Consider pixel midpoint M(Mx, My) M = (x0 + 1, Y0 + ½) M(Mx,My) Build equation of line through and compare to midpoint If midpoint is above line, y stays same If midpoint is below line, y increases + 1 (x0, y0)

Bresenham s Line-Drawing Algorithm Using similar triangles: y x Ay Ax = H W (x,y) (Ax,Ay) (Bx,By) H(x Ax) = W(y Ay) -W(y Ay) + H(x Ax) = 0 Above is ideal equation of line through (Ax, Ay) and (Bx, By) Thus, any point (x,y) that lies on ideal line makes eqn = 0 Double expression (to avoid floats later), and give it a name, F(x,y) = -2W(y Ay) + 2H(x Ax)

Bresenham s Line-Drawing Algorithm So, F(x,y) = -2W(y Ay) + 2H(x Ax) Algorithm, If: F(x, y) < 0, (x, y) above line F(x, y) > 0, (x, y) below line Hint: F(x, y) = 0 is on line Increase y keeping x constant, F(x, y) becomes more negative

Bresenham s Line-Drawing Algorithm Example: to find line segment between (3, 7) and (9, 11) F(x,y) = -2W(y Ay) + 2H(x Ax) = (-12)(y 7) + (8)(x 3) For points on line. E.g. (7, 29/3), F(x, y) = 0 A = (4, 4) lies below line since F = 44 B = (5, 9) lies above line since F = -8

Bresenham s Line-Drawing Algorithm (x1,y1) What Pixels to turn on or off? Consider pixel midpoint M(Mx, My) M = (x0 + 1, Y0 + ½) M(Mx,My) If F(Mx,My) < 0, M lies above line, shade lower pixel (same y as before) If F(Mx,My) > 0, M lies below line, shade upper pixel (x0, y0)

Can compute F(x,y) incrementally Initially, midpoint M = (Ax + 1, Ay + ½) F(Mx, My) = -2W(y Ay) + 2H(x Ax) = 2H W Can compute F(x,y) for next midpoint incrementally If we increment x + 1, y stays same, compute new F(Mx,My) F(Mx, My) += 2H If we increment x +1, y + 1 F(Mx, My) -= 2(W H)

Bresenham s Line-Drawing Algorithm Bresenham(IntPoint a, InPoint b) { // restriction: a.x < b.x and 0 < H/W < 1 int y = a.y, W = b.x a.x, H = b.y a.y; int F = 2 * H W; // current error term for(int x = a.x; x <= b.x; x++) { setpixel at (x, y); // to desired color value if F < 0 F = F + 2H; else{ Y++, F = F + 2(H W) } } } Recall: F is equation of line

Bresenham s Line-Drawing Algorithm Final words: we developed algorithm with restrictions 0 < m < 1 and Ax < Bx Can add code to remove restrictions To get the same line when Ax > Bx (swap and draw) Lines having m > 1 (interchange x with y) Lines with m < 0 (step x++, decrement y not incr) Horizontal and vertical lines (pretest a.x = b.x and skip tests) Important: Read Hill 9.4.1

References Hill, chapter 9