CS 548: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE

Similar documents
CS 450: COMPUTER GRAPHICS RASTERIZING LINES SPRING 2016 DR. MICHAEL J. REALE

CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE

Chapter 3: Graphics Output Primitives. OpenGL Line Functions. OpenGL Point Functions. Line Drawing Algorithms

CS335 Fall 2007 Graphics and Multimedia. 2D Drawings: Lines

Computer Graphics. Computer Graphics. Lecture 3 Line & Circle Drawing

GRAPHICS OUTPUT PRIMITIVES

Scan Conversion. CMP 477 Computer Graphics S. A. Arekete

OUTPUT PRIMITIVES. CEng 477 Introduction to Computer Graphics METU, 2007

CSC Computer Graphics

Computer Graphics. Lecture 3 Graphics Output Primitives. Somsak Walairacht, Computer Engineering, KMITL

CS 450: COMPUTER GRAPHICS RASTERIZING CONICS SPRING 2016 DR. MICHAEL J. REALE

Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

Raster Graphics Algorithms

Output Primitives. Dr. S.M. Malaek. Assistant: M. Younesi

Chapter - 2: Geometry and Line Generations

CSCI 4620/8626. Coordinate Reference Frames

Computer Graphics. Modelling in 2D. 2D primitives. Lines and Polylines. OpenGL polygon primitives. Special polygons

1 Introduction to Graphics

MODULE - 4. e-pg Pathshala

In today s lecture we ll have a look at: A simple technique The mid-point circle algorithm

Dr Pavan Chakraborty IIIT-Allahabad

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

Raster Displays and Scan Conversion. Computer Graphics, CSCD18 Fall 2008 Instructor: Leonid Sigal

Digital Differential Analyzer Bresenhams Line Drawing Algorithm

UNIT -8 IMPLEMENTATION

Graphics Output Primitives

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

Prof. Feng Liu. Fall /25/2018

Output Primitives Lecture: 3. Lecture 3. Output Primitives. Assuming we have a raster display, a picture is completely specified by:

Overview of Computer Graphics

Rasterization, or What is glbegin(gl_lines) really doing?

CS 450: COMPUTER GRAPHICS 2D TRANSFORMATIONS SPRING 2016 DR. MICHAEL J. REALE

Line Drawing Week 6, Lecture 9

(Refer Slide Time: 00:03:51)

Line Drawing. Foundations of Computer Graphics Torsten Möller

UNIT 2 GRAPHIC PRIMITIVES

From Ver(ces to Fragments: Rasteriza(on

Intermediate Algebra. Gregg Waterman Oregon Institute of Technology

CS 130. Scan Conversion. Raster Graphics

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu

521493S Computer Graphics Exercise 3 (Chapters 6-8)

This library uses only GL functions but contains code for creating common objects and simplifying viewing.

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored.

CS 543: Computer Graphics. Rasterization

CS488 2D Graphics. Luc RENAMBOT

Computer Graphics D Graphics Algorithms

(Refer Slide Time: 9:36)

2-3. Attributes of Absolute Value Functions. Key Concept Absolute Value Parent Function f (x)= x VOCABULARY TEKS FOCUS ESSENTIAL UNDERSTANDING

Simple example. Analysis of programs with pointers. Points-to relation. Program model. Points-to graph. Ordering on points-to relation

Topic #1: Rasterization (Scan Conversion)

Rasterization: Geometric Primitives

Transformations of Absolute Value Functions. Compression A compression is a. function a function of the form f(x) = a 0 x - h 0 + k

Chapter 8: Implementation- Clipping and Rasterization

Efficient Plotting Algorithm

Rasterization and Graphics Hardware. Not just about fancy 3D! Rendering/Rasterization. The simplest case: Points. When do we care?

Computer Graphics. Chapter 3 Computer Graphics Software

y = f(x) x (x, f(x)) f(x) g(x) = f(x) + 2 (x, g(x)) 0 (0, 1) 1 3 (0, 3) 2 (2, 3) 3 5 (2, 5) 4 (4, 3) 3 5 (4, 5) 5 (5, 5) 5 7 (5, 7)

Scan Conversion. Drawing Lines Drawing Circles

Transformations of Functions. 1. Shifting, reflecting, and stretching graphs Symmetry of functions and equations

A New Line Drawing Algorithm Based on Sample Rate Conversion

GRAPHING QUADRATIC FUNCTIONS IN STANDARD FORM

20 Calculus and Structures

0. Introduction: What is Computer Graphics? 1. Basics of scan conversion (line drawing) 2. Representing 2D curves

R asterisation. Part I: Simple Lines. Affine transformation. Transform Render. Rasterisation Line Rasterisation 2/16

Computer Graphics (CS 543) Lecture 10: Rasterization and Antialiasing

CS-321 Thursday 12 September 2002 Quiz (3 pts.) What is the purpose of a control grid in a cathode ray tube (CRT)?

Introduction to Computer Graphics (CS602) Lecture 05 Line Drawing Techniques

Computer Graphics: Line Drawing Algorithms

Announcements. Midterms graded back at the end of class Help session on Assignment 3 for last ~20 minutes of class. Computer Graphics

Functions Project Core Precalculus Extra Credit Project

CS5620 Intro to Computer Graphics

Using Characteristics of a Quadratic Function to Describe Its Graph. The graphs of quadratic functions can be described using key characteristics:

Rendering. A simple X program to illustrate rendering

Display Technologies: CRTs Raster Displays

Week 3. Topic 5 Asymptotes

1 Points and Distances

of Straight Lines 1. The straight line with gradient 3 which passes through the point,2

Scan Converting Lines

2.8 Distance and Midpoint Formulas; Circles

MATH SPEAK - TO BE UNDERSTOOD AND MEMORIZED

Graphing Quadratics: Vertex and Intercept Form

Numerical Precision. Or, why my numbers aren t numbering right. 1 of 15

To Do. Computer Graphics (Fall 2004) Course Outline. Course Outline. Motivation. Motivation

LESSON 3.1 INTRODUCTION TO GRAPHING

Week 10. Topic 1 Polynomial Functions

Graphing Equations. The Rectangular Coordinate System

CPSC / Scan Conversion

void drawdot(glint x, GLint y) { glbegin(gl_points); glvertex2i(x,y); glend();

2.2 Absolute Value Functions

2D Graphics Primitives II. Additional issues in scan converting lines. 1)Endpoint order. Want algorithms to draw the same pixels for each line

Does the table or equation represent a linear or nonlinear function? Explain.

Output Primitives Lecture: 4. Lecture 4

Topic 2 Transformations of Functions

Points and lines. x x 1 + y 1. y = mx + b

Graphs, Linear Equations, and Functions

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

GRAPHS AND GRAPHICAL SOLUTION OF EQUATIONS

Pointers CMPE-013/L. Pointers. Pointers What do they do? Pointers What are pointers? Gabriel Hugh Elkaim Winter 2014

Name Course Days/Start Time

Transcription:

CS 548: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 05 DR. MICHAEL J. REALE

OPENGL POINTS AND LINES

OPENGL POINTS AND LINES In OenGL, there are different constants used to indicate what ind of rimitive we are tring to draw For oints, we have GL_POINTS For lines, we have GL_LINES, GL_LINE_STRIP, and GL_LINE_LOOP

DRAWING POINTS: LEGACY VS. NEW To draw oints in legac OenGL: glbegingl_points); glverte3f,5,0); glverte3f,3,); glend); To draw oints in OenGL 3.0+, we set u our buffers and then call: gldrawarrasgl_points, 0, ointcnt); For other rimitives lie lines), the rocedure would be the same just relace GL_POINTS with what ou want instead.

DRAWING LINES Deending on which constant we choose, the lines will be drawn differentl GL_LINES = draw individual lines with ever vertices GL_LINE_STRIP = draw a olline connecting all vertices in sequence GL_LINE_LOOP = draw a olline, and then also connect the first and last vertices

DRAWING LINES glbegingl_lines); glverteiv) glverteiv); glverteiv3); glverteiv4); glverteiv5); glend); NOTE: 5 is ignored, since there isn t another verte to air it with ALSO NOTE: the v art means assing in an arra

DRAWING LINES glbegingl_line_strip); glverteiv) glverteiv); glverteiv3); glverteiv4); glverteiv5); glend); Creates a olline

DRAWING LINES glbegingl_line_loop); glverteiv) glverteiv); glverteiv3); glverteiv4); glverteiv5); glend); Creates a closed olline

DDA LINE DRAWING ALGORITHM

THE PROBLEM WITH PIXELS Prett much all modern dislas use a grid of iels to disla images Discrete digital) locations Problem: when drawing lines that aren t erfectl horizontal, vertical, or diagonal, the oints in the middle of the line do not fall erfectl into the iel locations I.e., have to round line coordinates to integers Lines end u having this stair-ste effect jaggies ) aliasing

LINE EQUATIONS A straight line can be mathematicall defined using the Cartesian sloe-intercet equation: m b We re dealing with line segments, so these have secified starting and ending oints: So, we can comute the sloe m and the intercet b as follows: m b 0 end end m 0 0 0 0, 0) end, end )

INTERVALS For a given interval δ along a line, we can comute the corresonding interval δ: m Similarl, we can get δ from δ: m

DDA ALGORITHM Digital differential analzer DDA) Scan-conversion line algorithm based on calculating either d or d Samle one coordinate at unit intervals find nearest integer value for other coordinate Eamle: 0 < m <=.0 sloe ositive, with δ > δ) Increment in unit intervals δ = ) Comute successive values as follows: Round value to nearest integer m

DDA ALGORITHM: M >.0 Problem: If sloe is ositive AND greater than.0 m >.0), then we increment b si iels in! Solution: swa roles of and! Increment in unit intervals δ = ) Comute successive values as follows: Round value to nearest integer m

DDA ALGORITHM: WHICH DO WE STEP IN? So, to summarize so far, which coordinate should be increment? Remember: If absd) > absd): Ste in X Otherwise: Ste in Y m end end 0 0 d d We ll see later in another algorithm an eas wa to do this is to swa the roles of and So is reall, and is reall

DDA ALGORITHM: LINES IN REVERSE We ve been assuming that the ending oint has a coordinate value greater than the starting oint: Left to right, if incrementing Bottom to to, if incrementing However, we could be going in reverse. If so, then: If right to left, δ = - If to to bottom, δ = -

DDA ALGORITHM: CODE // Get d and d int d = - 0; int d = - 0; int stes, ; float Increment, Increment; // Set starting oint float = 0; float = 0;

DDA ALGORITHM: CODE // Determine which coordinate we should ste in if absd) > absd)) stes = absd); else stes = absd); // Comute increments Increment = floatd) / floatstes); Increment = floatd) / floatstes);

DDA ALGORITHM: CODE // Let s assume we have a magic function called setpiel,) that sets a iel at,) to the aroriate color. // Set value of iel at starting oint setpielround), round)); // For each ste for = 0; < stes; ++) { // Increment both and += Increment; += Increment; } // Set iel to correct color // NOTE: we need to round off the values to integer locations setpielround), round));

DDA ALGORITHM: PROS AND CONS Advantage: Faster than using the sloe-intercet form directl no multilication, onl addition Caveat: initial division necessar Disadvantages: Accumulation of round-off error can cause the line to drift off true ath Rounding rocedure still time-consuming Question: can we do this with nothing but integers?

YES Yes, we can.

BRESENHAM S LINE DRAWING ALGORITHM

BRESENHAM S LINE ALGORITHM: INTRODUCTION Taes advantage of fact that sloe m is reall a fraction of integers Sa we have a ositive sloe and d > d so we re incrementing in ) We have a iel lotted at, ) Given +, the net value is going to be either: + The question is: which one is closer to the real line? +, ) or +, +)?

BRESENHAM S LINE ALGORITHM: THE IDEA The basic idea is to loo at a decision variable to hel us mae the choice at each ste Our revious osition:, ) d lower = distance of +, ) from the true line coordinate +, ) d uer = distance of +, + ) from the true line coordinate +, )

BRESENHAM S LINE ALGORITHM: MATH The value of for the mathematical line at + ) is given b: Ergo: b m ) b m d b m d uer lower ) ) )

BRESENHAM S LINE ALGORITHM: MORE MATH To determine which of the two iels is closer to the true line ath, we can loo at the sign of the following: Positive d uer is smaller choose + ) Negative d lower is smaller choose ) ) ) ) ) ) ) b m b m b m b m b m d d uer lower

BRESENHAM S LINE ALGORITHM: EVEN MORE MATH Remember that: Substituting with our current equation: We will let our decision variable be the following d d m end end 0 0 ) b d d uer lower c b b b b d d uer lower ) ) ) ) ) )

BRESENHAM S LINE ALGORITHM: DECISION VARIABLE c Multiling b Δ won t affect the sign of, since Δ > 0 Note that constant c does not deend on the current osition at all, so can comute it ahead of time: So, as before: c b ) ositive d uer is smaller choose + ) negative d lower is smaller choose

BRESENHAM S LINE ALGORITHM: UPDATING P K We can get the net value of the decision variable i.e., + ) using c c c c c c

BRESENHAM S LINE ALGORITHM: UPDATING P K However, we now: Therefore: So, we need to determine what + ) was: If was ositive + ) = If was negative + ) = 0

BRESENHAM S LINE ALGORITHM: SUMMARIZED. Inut two line endoints and store LEFT endoint in 0, 0 ). Plot first oint 0, 0 ) 3. Comute constants Δ, Δ, Δ, and Δ - Δ. Also comute first value of decision variable: 0 = Δ Δ 4. At each, test : If < 0 lot +, ) + = + Δ Otherwise lot +, +) + = + Δ - Δ 5. Perform ste 4 Δ ) times NOTE: Effectivel assuming line starts at 0,0) and thus b = 0 0) 0) 0) ) ) b ) NOTE: This version ONLY wors with 0 < m <.0!!! Ergo, Δ and Δ are ositive here!

BRESENHAM S LINE ALGORITHM: CODE // NOTE: d and d are ABSOLUTE VALUES in this code int d = fabs - 0); int d = fabs - 0); int = *d - d; int twod = *d; int twodminusd = *d - d); int,;

BRESENHAM S LINE ALGORITHM: CODE // Determine which endoint to use as start osition if0 > ) { = ; = ; = 0; } else { = 0; = 0; } // Plot first iel setpiel,);

BRESENHAM S LINE ALGORITHM: CODE while < ) { ++; } if < 0) += twod; else { ++; += twodminusd; } setpiel,);

BRESENHAM S LINE ALGORITHM: GENERALIZED What we re taled about onl wors with 0 < m <.0 For other sloes, we tae advantage of smmetr: If d > d swa and WARNING: Would then need to call setpiel, ) After swaing endoints and otentiall swaing and, if 0 > decrement rather than increment NOTE: ma actuall be if ou swaed them Two more warnings: ) In the samle code, d and d are ABSOLUTE VALUES ) In the net image, when I sa and, I mean the actual and

BRESENHAM S LINE ALGORITHM: SPECIAL CASES To save time, if ou have a line that is: Δ = 0 vertical) Δ = 0 horizontal) Δ = Δ diagonal) ou can just draw it directl without going through the entire algorithm.

MIDPOINT ALGORITHM A more general wa of viewing Bresenham s Algorithm that can be alied to other conics is called the Midoint Algorithm: Uses the imlicit reresentation e.g., imlicit line equation If a oint is on the inside, F,) < 0 If a oint is on the outside, F,) > 0 If a oint is eactl on the boundar, F,) = 0 Test whether the oint F+, + ½) is inside or outside choose closest oint F, ) A B C 0

MIDPOINT CIRCLE ALGORITHM

INTRODUCTION A circle can be defined b its imlicit form: c, c ) center of circle r = radius Since a circle is smmetric in all 8 octants just comute one octant and relicate in others 0 ) ) ), r F c c

DECISION VARIABLE Assume the circle is centered at 0,0) We re going to start b: Incrementing b Choose whether to go down or not in To determine our net choice, we will loo at our decision variable based on the midoint +, - ½): If < 0 midoint inside circle choose If > 0 midoint outside circle choose - F ), r

UPDATING THE DECISION VARIABLE To figure out how to udate the decision variable, let s loo at the net value: ), r F ), r F Remember:

HOLD ON TO YOUR MATHEMATICAL HATS ), r F Remember: ) ) ) 4 4 ) ) 4 4 ) 4 4 4 3 ) 4 4 4 4 ) r r r r r r

NEXT DECISION VARIABLE + is: if < 0 - ) if > 0 ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )

UPDATING THE DECISION VARIABLE If < 0 add + + If > 0 add + + + We can also udate + and + incrementall: ) )

INITIAL VALUES We will start at 0,r) Initial decision variable value: 0 F, r 5 4 r ) r r r r r 4 However, if our radius r is an integer, we can round 0 to 0 = r, since all increments are integers

MIDPOINT CIRCLE ALGORITHM SUMMARIZED. Inut radius r and circle center c, c ); first oint = 0, 0 ) = 0,r). Calculate initial decision variable value: 5 0 r 4 3. At each, test : If < 0 net oint is +, ) and: Otherwise net oint is +, - ) and: Where: 4. For each calculated osition,), lot + c, + c ) 5. Plot corresonding smmetric oints in other seven octants 6. Reeat stes 3 through 5 UNTIL >=