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



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

Exam 1 Sample Question SOLUTIONS. y = 2x

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

Linear algebra and the geometry of quadratic equations. Similarity transformations and orthogonal matrices

Drawing Lines with Pixels. Joshua Scott March 2012

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

Math 241, Exam 1 Information.

This makes sense. t /t 2 dt = 1. t t 2 + 1dt = 2 du = 1 3 u3/2 u=5

Solutions for Review Problems

Math 432 HW 2.5 Solutions

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

299ReviewProblemSolutions.nb 1. Review Problems. Final Exam: Wednesday, 12/16/2009 1:30PM. Mathematica 6.0 Initializations

Figure 2.1: Center of mass of four points.

Two vectors are equal if they have the same length and direction. They do not

GRAPHING IN POLAR COORDINATES SYMMETRY

Common Core Unit Summary Grades 6 to 8

(Refer Slide Time: 1:42)

Math Assignment 6

Section 1.1. Introduction to R n

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

11.1. Objectives. Component Form of a Vector. Component Form of a Vector. Component Form of a Vector. Vectors and the Geometry of Space

+ 4θ 4. We want to minimize this function, and we know that local minima occur when the derivative equals zero. Then consider

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

AP Calculus AB 2010 Free-Response Questions Form B

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

5: Magnitude 6: Convert to Polar 7: Convert to Rectangular

Graphs of Polar Equations

The Fourth International DERIVE-TI92/89 Conference Liverpool, U.K., July Derive 5: The Easiest... Just Got Better!

GeoGebra. 10 lessons. Gerrit Stols

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

1.1 Practice Worksheet

15.3. Calculating centres of mass. Introduction. Prerequisites. Learning Outcomes. Learning Style

Derive 5: The Easiest... Just Got Better!

Solutions to Exercises, Section 5.1

Mathematics 2540 Paper 5540H/3H

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

Higher Education Math Placement

Chapter 8 Geometry We will discuss following concepts in this chapter.

Number Sense and Operations

4.2. LINE INTEGRALS ; z = t. ; y = sin

Parametric Equations and the Parabola (Extension 1)

Classroom Tips and Techniques: The Student Precalculus Package - Commands and Tutors. Content of the Precalculus Subpackage

Algebra 1 Course Title

Solutions to Homework 5

Visualizing Differential Equations Slope Fields. by Lin McMullin

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.

MULTIPLE INTEGRALS. h 2 (y) are continuous functions on [c, d] and let f(x, y) be a function defined on R. Then

1.3. DOT PRODUCT If θ is the angle (between 0 and π) between two non-zero vectors u and v,

H.Calculating Normal Vectors

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

PROBLEM SET. Practice Problems for Exam #1. Math 1352, Fall Oct. 1, 2004 ANSWERS

Section 6.4. Lecture 23. Section 6.4 The Centroid of a Region; Pappus Theorem on Volumes. Jiwen He. Department of Mathematics, University of Houston

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

Practice Final Math 122 Spring 12 Instructor: Jeff Lang

Geometry and Measurement

WORK SCHEDULE: MATHEMATICS 2007

Feb 28 Homework Solutions Math 151, Winter Chapter 6 Problems (pages )

Lecture 8 : Coordinate Geometry. The coordinate plane The points on a line can be referenced if we choose an origin and a unit of 20

Review Sheet for Test 1

In the above, the number 19 is an example of a number because its only positive factors are one and itself.

With the Tan function, you can calculate the angle of a triangle with one corner of 90 degrees, when the smallest sides of the triangle are given:

Planar Curve Intersection

Cabri Geometry Application User Guide

Solutions to Practice Problems

MATH 21. College Algebra 1 Lecture Notes

1. First-order Ordinary Differential Equations

SOLUTIONS. f x = 6x 2 6xy 24x, f y = 3x 2 6y. To find the critical points, we solve

Section 1.5 Linear Models

Algebra 2 Year-at-a-Glance Leander ISD st Six Weeks 2nd Six Weeks 3rd Six Weeks 4th Six Weeks 5th Six Weeks 6th Six Weeks

Algebra I Vocabulary Cards

Calculus with Parametric Curves

Computer Graphics Lecture Notes

Copyrighted Material. Chapter 1 DEGREE OF A CURVE

Algebra 2: Themes for the Big Final Exam

Grade 6 Mathematics Performance Level Descriptors

Solutions - Homework sections

12.5 Equations of Lines and Planes

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

C relative to O being abc,, respectively, then b a c.

MAC Learning Objectives. Module 10. Polar Form of Complex Numbers. There are two major topics in this module:

Algebra Geometry Glossary. 90 angle

vector calculus 2 Learning outcomes

Review of Fundamental Mathematics

Analyzing Piecewise Functions

Section 12.6: Directional Derivatives and the Gradient Vector


correct-choice plot f(x) and draw an approximate tangent line at x = a and use geometry to estimate its slope comment The choices were:

Lesson 10: Polynomials

Homework #1 Solutions

An Introduction to Applied Mathematics: An Iterative Process

tegrals as General & Particular Solutions

EL-9650/9600c/9450/9400 Handbook Vol. 1

1) (-3) + (-6) = 2) (2) + (-5) = 3) (-7) + (-1) = 4) (-3) - (-6) = 5) (+2) - (+5) = 6) (-7) - (-4) = 7) (5)(-4) = 8) (-3)(-6) = 9) (-1)(2) =

Content. Chapter 4 Functions Basic concepts on real functions 62. Credits 11

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

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

1.2 GRAPHS OF EQUATIONS. Copyright Cengage Learning. All rights reserved.

Solving Simultaneous Equations and Matrices

RADIUS OF CURVATURE AND EVOLUTE OF THE FUNCTION y=f(x)

A QUICK GUIDE TO THE FORMULAS OF MULTIVARIABLE CALCULUS

Transcription:

Walters@buffalo.edu CSE 480/580 Lecture 7 Slide 1 2D Primitives I Point-plotting (Scan Conversion) Lines Circles Ellipses Scan Conversion of Filled Primitives Rectangles Polygons Clipping In graphics must approximate the ideal mathematical continuous primitive with a discrete version Many concepts are easy in continuous space - Difficult in discrete space Example: Lines

Walters@buffalo.edu CSE 480/580 Lecture 7 Slide 2 Line Drawing Algorithms Lines used a lot - want to get them right Criteria for Line Drawing Algorithms: 1) Lines should appear straight - no jaggies Discretization problem Horizontal, vertical and diagonals easy Others difficult 2) Lines should terminate accurately Discretization Cumulative round-off: e.g. octagon 3) Lines should have constant density dots/line length equal spacing of dots

Walters@buffalo.edu CSE 480/580 Lecture 7 Slide 3 4) Line density should be independent of line length or angle 5) Lines should be drawn rapidly Efficient algorithms Mathematical Preliminaries How to represent a line with an equation? Nonparametric: Explicit y = f(x) example? Implicit f(x,y) = 0 f(x,y) = ax + by + c = 0 Parametric: x = f(t) y = g(t) t=0 t=1

Walters@buffalo.edu CSE 480/580 Lecture 7 Slide 4 Scan Converting Lines Drawing lines by identifying each point Rastor (discrete) Space 8 7 6 5 4 3 2 1 8 7 6 5 4 3 2 1 Line Algorithm: 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 Line from (x1, y1) to (x2,y2) dx = x2-x1 dy = y2-y1 m = dy/dx y = y1 for x = x1 to x2 {DrawPixel(x,Round(y) y = y + m} Different possibilities: Pixels lie at intersections Pixels lie in centers Different locations for origin Different size or shape pixels square in Timex/Sinclare ~round on CRT overlap versus none Horizontal, vertical, diagonal Oblique Problems: slow floating point math almost vertical lines get dotty How solve last one? axis of greatest motion

Walters@buffalo.edu CSE 480/580 Lecture 7 Slide 5 DDA Algorithm: (Digital Differential Analyzer) xn+1 = xn + x yn+1 = yn + y x y (x2, y2) y (x1, y1) x update x and y by their differentials (epsilon is some small positive constant) Problems: still slow still floating point math Advantages: mathematically well defined no spotty lines Bresenhams Algorithm: one of the best for lines (doesn't generalize) only integer math simple but weird algorithm based on the error keeps track of how far a pixel is from the "true line" and corrects when it gets too far

Walters@buffalo.edu CSE 480/580 Lecture 7 Slide 6 yi-1 +1 yi d2 d1 yi-1 xi-1 xi-1 + 1 xi Ideal Continuous Line: (xa, ya) to (xb, yb) y = m (x - xa) + ya where m is the slope Assume: xa < xb 0 < m < 1 y what set of possible lines? how many sets of possible lines? x For this set, which will be axis of greatest movement? true point is at y choose yi-1 or yi-1 + 1? look at difference (error) is d1 or d2 smaller? choose point with smallest difference

Walters@buffalo.edu CSE 480/580 Lecture 7 Slide 7 yi-1 +1 yi yi-1 xi-1 xi-1 + 1 xi d2 d1 Look at (d1 - d2) if > 0, choose yi-1 + 1 if < 0, choose yi-1 d1 - d2 = (y - yi-1) - (yi-1+1 - y) = 2 y - 2(yi-1) -1 (regroup) = 2m (xi - xa) + 2(ya -yi-1) - 1 (substitute in for y) (multiply by x) ei = x(d1 - d2) = 2 y (xi-xa) + 2 x(ya-yi-1) - x This will be the decision variable Calculate ei incrementally: ei+1 = ei + 2 y (xi+1 - xi) - 2 x(yi - yi-1) = 1 = 0 or 1 if y was incremented: ei+1 = ei + 2( y - x) otherwise: ei+1 = ei + 2 y Now very simple to compute!

Walters@buffalo.edu CSE 480/580 Lecture 7 Slide 8 Bresenham's Initial Conditions i = 0 x0 =? y0 =? ei = x(d1 - d2) e1 = x[(y-ya) - ((ya+1)-y)] =? Bresenham's Algorithm: x = xa y = ya Why efficient? dx = xb -xa dy = yb - ya err = 2 dy - dx How Generalize to other sets of lines? for i = 1 to dx { was xa < xb and o < m < 1 drawpixel (x,y) if err > 0 xa > xb? { y = y + 1 m > 1? err = err + 2dy - 2dx } 0 > m > -1? else (dy = -dy and dec y) err = err + 2dy x = x + 1 m = 1 or m = 0? }

Walters@buffalo.edu CSE 480/580 Lecture 7 Slide 9 Midpoint Line Algorithm Bresenham's cannot generalize to arbitrary conics Thus use Midpoint Line Algorithm For lines and circles, end up with identical algorithm yi-1 +1 yi Q M e(si) = d2 e(ti) = d1 yi-1 xi-1 xi-1 + 1 xi Bresenhams: look at sign of scaled difference in errors Midpoint: look at which side of line midpoint falls on (see derivation in the text) It has been proven that Bresenhams gives an optimal fit for lines It has been proven that Midpoint is equivalent to Bresenhams for line

Walters@buffalo.edu CSE 480/580 Lecture 7 Slide 10 Scan Converting Circles Circle equation: x 2 + y 2 = R 2 1) So try plotting y = +/- SQRT(R 2 - x 2 ) (see example) Problem: gets spotty in places Why? (axis of greatest motion) 2) Try polar coordinates x = R cos( 0 ) y = R sin( 0 ) Problem: very slow Why? So we need a better technique - like for lines 8 - Way Symmetry assume circle is centered at origin How much of circle do we have to compute? (how many axes of symmetry) If compute (x,y) for a point in the second octant drawpixel(x,y) drawpixel(-x,y) drawpixel(-y,x) drawpixel(-y,-x) drawpixel(-x,-y) drawpixel(x,-y) drawpixel(y,-x) drawpixel(y,x) What if circle centered about pixel other than origin? What if circle not centered about a pixel?

Walters@buffalo.edu CSE 480/580 Lecture 7 Slide 11 Mitchner's Circle Algorithm: Based on Breshenham's ideas Derive it for the second octant x 2 + y 2 = R 2 start from x=0, and go to x=y 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 Since our points Pi-1 = (xi-1,yi-1) will be integers, there will be errors e(pi-1) = (xi-1 2 + yi-1 2 ) - R 2 what sign is e(p i-1 ) when (x,y) inside circle? outside circle? Only two possible next points in this octant Si and Ti choose one with smallest error Create error difference di = e(si) + e(ti) Pi-1 a Si b c Ti So if di < 0, choose Si else, choose Ti Only five possible cases: show it works in each for c: S is outside, T is inside errors will have opposite signs, S's positive if d < 0, T's is larger, choose S for a and b: S is on or inside circle, T inside T's is negative, S's is negative or 0 d < 0, choose S for d and e: T is on or outside; S is outside S's error positive, T's is positive d > 0, choose T e d

Walters@buffalo.edu CSE 480/580 Lecture 7 Slide 12 Incremental version of decision variable: di+1 = di + 4xi-1 + 6 + 2(yi 2 -yi-1 2 ) - 2(yi-yi-1) (should be able to derive this) if di < 0, then y didn't change di+1 = di + 4xi-1 + 6 else, y changed by -1 di+1 = di + 4(xi-1) + 6-2 (2yi-1-2) -2 = di + 4(xi-1 -yi-1) + 10 Initial Conditions: x0 = 0, y0 =? S1 = (1, R) T1 = (1, R-1) d1 = (xs 2 + ys 2 ) - R 2 + (xt 2 + yt 2 - R 2 ) = 1 + R 2 - R 2 + (1 + R 2-2R + 1 - R 2 ) = 3-2R Michner's Circle Algorithm: x = 0 y = R d = 3-2R while x <= y { DrawPixel(x,y) if d < 0 d = d + 4x +6 else { d = d + 4(x-y) + 10 y = y - 1 } x = x +1 } Problems: multiplication doesn't generalize to all conics

Walters@buffalo.edu CSE 480/580 Lecture 7 Slide 13 Midpoint Circle Algorithm Do analysis based on whether midpoint is inside or outside of circle E P M SE See derivations in text for: midpoint circle algorithm integer midpoint circle algorithm integer second-order difference midpoint circle algorithm Midpoint Circle Algorithm x = 0 y = R d = 1-R de = 3 dse = 5-2R DrawPixel(x,y) while (y > x){ if d < 0{ d = d + de de = de + 2 dse = dse + 2 x = x + 1 }else{ d = d + dse de = de + 2 dse = dse + 4 x = x + 1 y = y -1 } DrawPixel(x,y) } What is initial sign of d? How can d ever go from positive to negative?