GRAPHICS OUTPUT PRIMITIVES

Similar documents
CSC Computer Graphics

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

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

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

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

Output Primitives Lecture: 4. Lecture 4

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

Graphics Output Primitives

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

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

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

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

UNIT 2 GRAPHIC PRIMITIVES

Chapter - 2: Geometry and Line Generations

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

Overview of Computer Graphics

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

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

Prof. Feng Liu. Fall /25/2018

Section 9.3: Functions and their Graphs

CSCI 4620/8626. Coordinate Reference Frames

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

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

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

Two Dimensional Viewing

is a plane curve and the equations are parametric equations for the curve, with parameter t.

MODULE - 4. e-pg Pathshala

2.8 Distance and Midpoint Formulas; Circles

2009 A-level Maths Tutor All Rights Reserved

CS 130. Scan Conversion. Raster Graphics

Reteaching Golden Ratio

Computer Graphics Lecture Notes

Computer Graphics D Graphics Algorithms

10.2: Parabolas. Chapter 10: Conic Sections. Conic sections are plane figures formed by the intersection of a double-napped cone and a plane.

Parabolas Section 11.1

CPSC / Scan Conversion

12.4 The Ellipse. Standard Form of an Ellipse Centered at (0, 0) (0, b) (0, -b) center

From Ver(ces to Fragments: Rasteriza(on

(0, 4) Figure 12. x + 3. d = c. = b. Figure 13

Beecher J.A, Penna J.A., Bittinger M.L. Algebra and Trigonometry (3ed, Addison Wesley, 2007) 58 Chapter 1 Graphs, Functions, and Models

1.2 Visualizing and Graphing Data

Computer Graphics. Lecture 2. Doç. Dr. Mehmet Gokturk

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

8.6 Three-Dimensional Cartesian Coordinate System

Lines and Their Slopes

CS2401 Computer Graphics

9Trigonometric ONLINE PAGE PROOFS. functions 1

CS6504 & Computer Graphics Unit I Page 1

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

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

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

Output Primitives. Ellipse Drawing

Module 2, Section 2 Graphs of Trigonometric Functions

LESSON 3.1 INTRODUCTION TO GRAPHING

Tópicos de Computação Gráfica Topics in Computer Graphics 10509: Doutoramento em Engenharia Informática. Chap. 2 Rasterization.

Rasterization: Geometric Primitives

Efficient Plotting Algorithm

20 Calculus and Structures

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

The Sine and Cosine Functions

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

Functions Review Packet from November Questions. 1. The diagrams below show the graphs of two functions, y = f(x), and y = g(x). y y

Line Drawing Week 6, Lecture 9

GRAPHS AND GRAPHICAL SOLUTION OF EQUATIONS

Computer Graphics D Graphics Algorithms

Double Integrals in Polar Coordinates

angle The figure formed by two lines with a common endpoint called a vertex. angle bisector The line that divides an angle into two equal parts.

9. f(x) = x f(x) = x g(x) = 2x g(x) = 5 2x. 13. h(x) = 1 3x. 14. h(x) = 2x f(x) = x x. 16.

[ ] [ ] Orthogonal Transformation of Cartesian Coordinates in 2D & 3D. φ = cos 1 1/ φ = tan 1 [ 2 /1]

Line Drawing. Introduction to Computer Graphics Torsten Möller / Mike Phillips. Machiraju/Zhang/Möller

0 COORDINATE GEOMETRY

Scan Converting Lines

UNIT -8 IMPLEMENTATION

Introduction to Trigonometric Functions. Peggy Adamson and Jackie Nicholas

1) y = 2x 7 2) (-2, 3) ( 3, -1) 3) table. 4) y 5 = ½ ( x 4) 5) 2x + 4y = 7 6) y = 5 7) 8) 9) (-1, 5) (0, 4) 10) y = -3x 7. 11) 2y = -3x 5 12) x = 5

Graphs, Linear Equations, and Functions

Chapter 3. Sukhwinder Singh

Math 26: Fall (part 1) The Unit Circle: Cosine and Sine (Evaluating Cosine and Sine, and The Pythagorean Identity)

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

SECTION 8.2 the hyperbola Wake created from shock wave. Portion of a hyperbola

Math 231E, Lecture 34. Polar Coordinates and Polar Parametric Equations

Today s class. Geometric objects and transformations. Informationsteknologi. Wednesday, November 7, 2007 Computer Graphics - Class 5 1

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

(Refer Slide Time: 00:03:51)

2.1 The ReCTAngUlAR COORdInATe SySTemS And graphs

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

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

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

C URVES AND V ECTORS

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

Polar Functions Polar coordinates

1 Introduction to Graphics

TANGENTS AND NORMALS

Scan Conversion. Drawing Lines Drawing Circles

Line Drawing. Foundations of Computer Graphics Torsten Möller

PARAMETRIC EQUATIONS AND POLAR COORDINATES

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

REMARKS. 8.2 Graphs of Quadratic Functions. A Graph of y = ax 2 + bx + c, where a > 0

What and Why Transformations?

Three-Dimensional Coordinates

Transcription:

CHAPTER 3 GRAPHICS OUTPUT PRIMITIVES LINE DRAWING ALGORITHMS DDA Line Algorithm Bresenham Line Algorithm Midpoint Circle Algorithm Midpoint Ellipse Algorithm CG - Chapter-3

LINE DRAWING Line drawing is represented b calculating intermediate positions along the line path between specified end points. Definition of line drawing: Given two points P & Q in the plane, both with integer coordinates, determine which piels on a raster screen should be on in order to mae a picture of a unit-width line segment starting from P & ending at Q. 3 Line drawing concepts The thinnest line is of one-piel wide. Drawing a line of piel resolution can be done using the Cartesian slope-intercept equation for a straight line is = m. + b where, m is the slope of the line and b is the intercept. Given the endpoints of a line segment. m = - / - b = - m. 4 CG - Chapter-3

6 5 4 3 0 0 3 4 5 6 (3, 3) 5 Line Drawing concepts Also for an given interval along a line, we can compute the corresponding interval from = m. Similarl we can obtain the interval corresponding to a specified as = / m Also, for an given interval along a line, we can compute the corresponding interval from = m. These equations form the basis for determining deflection voltages in analog devices. 6 CG - Chapter-3 3

Line Drawing concepts (cont ) On Raster sstems, lines are plotted with piels, and step sizes in the horizontal and vertical directions are constrained b piel separations. To draw sample a line at discrete positions and determine the nearest piel to the line at each sampled position. 7 Line Drawing Algorithm - an eample 8 7 6 5 4 3 Line: (3,) -> (9,6)? Which intermediate piels to turn on? 0 3 4 5 6 7 8 9 0 8 CG - Chapter-3 4

Line Drawing Algorithms Cartesian equation: = m + c where m slope c -intercept m 9 Slope if m = = 45 +ve 45 -ve 45 if m -45 < < 45 if m 45 < < 90 or -90 < < -45 0 CG - Chapter-3 5

= m = c = 0 0 0 3 3 4 4 5 5 6 6 7 7 8 8 m = 8 7 6 5 4 3 0 0 3 4 5 6 7 8 = ½ + m = ½ c = round() 0.5 3.5 3 4 3 3 5 3.5 4 6 4 4 7 4.5 5 8 5 5 m 8 7 6 5 4 3 0 0 3 4 5 6 7 8 CG - Chapter-3 6

Line Drawing Algorithm an eample (Cont ) Slope-intercept line equation : = m + b Given two end points (0,0), (, ), how to compute m and b? d 0 m b 0 m* 0 d 0 (,) d (0,0) d 3 Line Drawing Algorithm an eample to find slope Eample: Finding slope m: (A, A) = (3, 4), (B, B) = (5, 96) B m B A 96 4 A 5 3 55 0 0.539 4 CG - Chapter-3 7

DDA Algorithm (Digital Differential Analzer) DDA algorithm is an incremental Scan algorithm. The DDA algorithm samples the line at unit intervals in one coordinate corresponding integer values nearest the line path of the other coordinate. 5 DDA Algorithm Wal through the line, starting at (0,0), limit, increments to values in [0,] range. Case a: is incrementing faster (m < ) Step in = increments, compute and round Case b: is incrementing faster (m > ) Step in = increments, compute and round (,) d (0,0) d 6 CG - Chapter-3 8

DDA Line Drawing Algorithm Case a: m < m (,) = 0 = 0 Illuminate piel (, round()) = 0 + = 0 + * m Illuminate piel (, round()) = + = + * m Illuminate piel (, round()) (0, 0) Until == 7 DDA Line Drawing Algorithm Case b: m > m = 0 = 0 (,) Illuminate piel (round(), ) = 0 + = 0 + * /m Illuminate piel (round(), ) = + = + /m Illuminate piel (round(), ) (0,0) Until == 8 CG - Chapter-3 9

DDA Illustration Case a: (m < ) Net piel on net column (when slope is small) Case b: (m > ) Net piel on net row (when slope is large) 9 #include 'device. h # define ROUND(a) ( (int) (a + 0.5) ) void linedda (int a, int a, int b, int b) { int d = b - a, d = b - a, steps, ; float Increment, Increment, = a, = a; if (abs (d) > abs (d)) steps = abs (d) ; else steps = abs d); Increment = d / (float) steps; Increment = d (float) steps; DDA ALGORITHM } setpiel (ROUND(), ROUND() ) ; for (=0; <steps; ++) { += Increment; += Increment; setpiel (ROUND(), ROUND() ); } 0 CG - Chapter-3 0

round() 0 4/3 Eample (DDA) 0 m 3 i i i i 8 7 5/3 6 3 5 4 4 7/3 3 5 8/3 3 6 3 3 7 0/3 3 0 8 /3 4 0 3 4 5 6 7 8 3 Eample (DDA) 3 8 m i i i i ( round() 8 0 0 8 7 /3 0 7 6 /3 6 5 5 4 4 4/3 3 3 5/3 7/3 0 0 8/3 3 0 3 4 5 6 7 8 3 ) CG - Chapter-3

Bresenham s Line Algorithm INTRODUCTION An accurate, efficient raster line drawing algorithm developed b Bresenham, scan converts lines using onl incremental integer calculations that can be adapted to displa circles and other curves. Advantage : it uses onl integer calculations Based on smmetr propert of lines, lets derive a more efficient wa of drawing a line. Starting from the left end point ( 0, 0 ) of a given line, we step to each successive column ( position) and plot the piel whose scan-line value closest to the line path. Assuming we have determined that the piel at (, ) is to be displaed, we net need to decide which piel to plot in column +. 3 Bresenham Line Algorithm (cont ) Choices are: ( +, ) and ( +, K +) d = = m( + ) + b d = ( + ) = + - m( + ) b The difference between these separations is d- d = m( + ), + b A decision parameter p for the th step in the line algorithm can be obtained b rearranging above equation so that it involves onl integer calculations 4 CG - Chapter-3

The Bresenham Line Algorithm. Input the two line end-points, storing the left endpoint in ( 0, 0 ). Plot the point ( 0, 0 ) 3. Calculate the constants Δ, Δ, Δ, and (Δ - Δ) and get the first value for the decision parameter as: 4. At each along the line, starting at = 0, perform the following test. If p < 0, the net point to plot is ( +, ) and: p p Otherwise, the net point to plot is ( +, +) and: p p 5. Repeat step 4 (Δ ) times p 0 5 Eample Draw a line from (0,0) to (30,8) d = 0 d = 8 initial decision d 0 = d d = 6 Also d = 6, (d d) = -4 i d i ( i+, i+ ) 0 6 (,) (,) - (3,) 3 4 (4,3) 4 0 (5,4) 5 6 (6,5) 6 (7,6) 7 - (8,6) 8 4 (9,7) 9 0 (30,8) 6 9 8 7 6 5 4 3 0 (0,0) (30,8) 0 3 4 5 6 7 8 9 30 3 3 CG - Chapter-3 3

CIRCLE general concepts Properties of a circle: A circle is defined as a set of points that are all the given distance ( c, c ). This distance relationship is epressed b the pthagorean theorem in Cartesian coordinates as ( c ) + ( c ) = r We could use this equation to calculate the points on the circle circumference b stepping along -ais in unit steps from c -r to c +r and calculate the corresponding values at each position as = c +(- ) (r (c ) ) / This is not the best method: Considerable amount of computation Spacing between plotted piels is not uniform 7 Polar co-ordinates for a circle We could use polar coordinates r and θ, = c + r cosθ = c + r sinθ A fied angular step size can be used to plot equall spaced points along the circumference A step size of /r can be used to set piel positions to approimatel unit apart for a continuous boundar But, note that circle sections in adjacent octants within one quadrant are smmetric with respect to the 45 deg line dividing the to octants Thus we can generate all piel positions around a circle b calculating just the points within the sector from =0 to = Drawbac: This method is still computationall epensive 8 CG - Chapter-3 4

A Simple Circle Drawing Algorithm The equation for a circle is: r where r is the radius of the circle So, we can write a simple circle drawing algorithm b solving the equation for at unit intervals using: r 9 Midpoint Circle Drawing Algorithm To determine the closest piel position to the specified circle path at each step. For given radius r and screen center position ( c, c ), calculate piel positions around a circle path centered at the coodinate origin (0,0). Then, move each calculated position (, ) to its proper screen position b adding c to and c to. Along the circle section from =0 to = in the first quadrant, the gradient varies from 0 to -. 30 CG - Chapter-3 5

Midpoint Circle Drawing Algorithm Eight-wa smmetr: 8 segments of octants for a circle: circle drawing algorithm in which circles centred at (0, 0) is more efficient. 3 Midpoint Circle Drawing Algorithm Circle function: f circle (,) = + r f circle (,) = { > 0, (,) outside the circle < 0, (,) inside the circle = 0, (,) is on the circle boundar 3 CG - Chapter-3 6

Midpoint Circle Drawing Algorithm midpoint midpoint - - F < 0 + = Net piel = ( +, ) F >= 0 + = - Net piel = ( +, -) 33 34 CG - Chapter-3 7

Bresenham to Midpoint Circle Algorithm Bresenham requires eplicit equation Not alwas convenient (man equations are implicit) Based on implicit equations: Midpoint Algorithm (circle, ellipse, etc.) Implicit equations have the form F(,)=0. Similarl to the case with lines, there is an incremental algorithm for drawing circles the midpoint circle algorithm In the mid-point circle algorithm we use eightwa smmetr so onl ever calculate the points for the top right eighth of a circle, and then use smmetr to get the rest of the points. 35 Mid-Point Circle Algorithm (cont ) Assuming we have just plotted the piel at (, ) so we need to choose between ( +, ) and ( +, -) Our decision p variable can be defined as: fcirc(, ) ( ) ( ) r If p < 0 the midpoint is inside the circle and and the piel at is closer to the circle Otherwise the midpoint is outside and - is closer 36 CG - Chapter-3 8

CG - Chapter-3 9 Mid-Point Circle Algorithm (cont ) To ensure things are as efficient as possible we can do all of our calculations incrementall First consider: (or) where + is either or - depending on the sign of p 37 ] ) [(, r f p circ ) ( ) ( ) ( p p Mid-Point Circle Algorithm (cont ) The first decision variable is given as: Then if p < 0 then the net decision variable is given as: If p > 0 then the decision variable is: 38 r r r r f p circ 4 5 ) ( ) (, 0 p p p p

Midpoint circle algorithm ) Input radius r and circle center ( c, c ) and obtain the first point on the circumference of the circle centered on the origin as : ( 0, 0 ) = (0,r) ) Calculate the initial value of the decision parameter as P 0 = 5/4 - r 3) At each position starting at = 0, perform the following test: If p < 0, the net point along the circle centered on (0,0) is ( +, ) and p + = p + + + 39 Midpoint circle algorithm (cont..) Otherwise the net point along the circle is ( +, - ) and p + = p + + + - + where + = + and + = - 4) Determine smmetr points in the other seven octants 5) Move each calculated piel position (,) onto the circular path centered on (,c) and plot the coordinate values = + c, = + c 6) Repeat steps 3 through 5 until >= 40 CG - Chapter-3 0

Midpoint Circle Drawing Algorithm - Eample Eample: Given a circle radius = 0, determine the circle octant in the first quadrant from =0 to =. Solution: f 0 = 5 r 4 = 5 0 4 = -8.75 9 4 Midpoint Circle Drawing Algorithm - Eample Initial ( 0, 0 ) = (,0) Decision parameters are: 0 =, 0 = 0 F + + 0-9 0 0-9++=-6 0 4 0-6+4+=- 3 0 6 0 3 -+6+=6 4 9 8 8 4 6+8+-8=-3 5 9 0 8 5-3+0+=8 6 8 6 6 8++-6=5 7 7 4 4 4 CG - Chapter-3

Mid-Point Circle Algorithm - Summar The e points in the mid-point circle algorithm are: Eight-wa smmetr can hugel reduce the wor in drawing a circle Moving in unit steps along the ais at each point along the circle s edge we need to choose between two possible coordinates 43 Ellipse-Generating Algorithms Ellipse A modified circle whose radius varies from a maimum value in one direction (major ais) to a minimum value in the perpendicular direction (minor ais). F d P=(,) d F The sum of the two distances d and d, between the fied positions F and F (called the foci of the ellipse) to an point P on the ellipse, is the same value, i.e. d + d = constant 44 CG - Chapter-3

Ellipse Properties Epressing distances d and d in terms of the focal coordinates F = (, ) and F = (, ), we have: ( ) ( ) ( ) ( ) constant r r Cartesian coordinates: Polar coordinates: 45 c c r r r cos c r sin c Ellipse Algorithms Smmetr between quadrants Not smmetric between the two octants of a quadrant Thus, we must calculate piel positions along the elliptical arc through one quadrant and then we obtain positions in the remaining 3 quadrants b smmetr (-, ) (, ) r r (-, -) (, -) 46 CG - Chapter-3 3

Ellipse Algorithms f (, ) r r r r ellipse Decision parameter: 0 if (, ) is inside the ellipse fellipse(, ) 0 if (, ) is on the ellipse 0 if (, ) is outside the ellipse r r Slope = - d Slope d r r 47 Midpoint Ellipse Algorithm i i - Midpoint 48 i i + i + Assuming that we have just plotted the piels at ( i, i ). The net position is determined b: p f (, ) i ellipse i i r ( ) r ( ) r r i i If p i < 0 the midpoint is inside the ellipse i is closer If pi 0 the midpoint is outside the ellipse i is closer CG - Chapter-3 4

Midpoint Ellipse Algorithm. Input r, r, and ellipse center ( c, c ), and obtain the first point on an ellipse centered on the origin as ( 0, 0 ) = (0, r ). Calculate the initial parameter in region as p r r r r 0 4 3. At each i position, starting at i = 0, if p i < 0, the net point along the ellipse centered on (0, 0) is ( i +, i ) and p p r r i i i otherwise, the net point is ( i +, i ) and p p r r r i i i i 49 and continue until r r Midpoint Ellipse Algorithm 4. ( 0, 0 ) is the last position calculated in region. Calculate the initial parameter in region as p r ( ) r ( ) r r 0 0 0 5. At each i position, starting at i = 0, if p i > 0, the net point along the ellipse centered on (0, 0) is ( i, i ) and p p r r i i i otherwise, the net point is ( i +, i ) and p p r r r i i i i Use the same incremental calculations as in region. Continue until = 0. 6. For both regions determine smmetr points in the other three quadrants. 7. Move each calculated piel position (, ) onto the elliptical path centered on ( c, c ) and plot the coordinate values = + c, = + c 50 CG - Chapter-3 5

Eample r = 8, r = 6 r = 0 (with increment r = 7) r = r r (with increment -r = -8) Region ( 0, 0 ) = (0, 6) p r r r r 33 0 4 i p i i+, i+ r i+ r i+ 0-33 (, 6) 7 768-4 (, 6) 44 768-44 (3, 6) 6 768 3 08 (4, 5) 88 640 4-08 (5, 5) 360 640 5 88 (6, 4) 43 5 6 44 (7, 3) 504 384 5 Move out of region since r > r Eample Region ( 0, 0 ) = (7, 3) (Last position in region ) p f ellipse (7,) 5 0 i p i i+, i+ r i+ r i+ 0-5 (8, ) 576 56 33 (8, ) 576 8 745 (8, 0) - - Stop at = 0 5 6 5 4 3 0 0 3 4 5 6 7 8 CG - Chapter-3 6

Eercises Draw the ellipse with r = 6, r = 8. Draw the ellipse with r = 0, r = 4. Draw the ellipse with r = 4, r = 0 and center at (5, 0). 53 CG - Chapter-3 7