Midpoint Circle Algorithm

Slides:



Advertisements
Similar presentations
Circle Drawing Asst. Prof. Dr. Ahmet Sayar Kocaeli University
Advertisements

PARAMETRIC EQUATIONS AND POLAR COORDINATES
CS 450: COMPUTER GRAPHICS DRAWING ELLIPSES AND OTHER CURVES SPRING 2015 DR. MICHAEL J. REALE.
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.
CS 376 Introduction to Computer Graphics 02 / 02 / 2007 Instructor: Michael Eckmann.
Computer Graphics 4: Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling By:Kanwarjeet Singh.
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphics Drawing Elementary Figures Dr. Eng. Farag Elnagahy.
CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
Larry F. Hodges (modified by Amos Johnson) 1 Design of Line, Circle & Ellipse Algorithms.
Trigonometric Functions
Polar Coordinates Objective: To look at a different way to plot points and create a graph.
Copyright © Cengage Learning. All rights reserved.
2D Output Primitives Graphics packages provide basic operations (called primitive operations) to describe a scene in terms of geometric structures. The.
Raster conversion algorithms for line and circle
Bresenham’s Midpoint Algorithm CS5600 Computer Graphics Rich Riesenfeld Spring 2006 Lecture Set 1.
Rasterization Foley, Ch: 3. Pixels are represented as disjoint circles centered on uniform grid Each (x,y) of the grid has a pixel Y X (1,1) (1,2) (0,0)
Section 1.1 The Distance and Midpoint Formulas. x axis y axis origin Rectangular or Cartesian Coordinate System.
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
Circle Drawing algo..
P OLAR E QUATIONS Section Polar Coordinates Given: r: Directed distance from the Polar axis (pole) to point P Ɵ: Directed angle from the Polar axis.
Integration in polar coordinates involves finding not the area underneath a curve but, rather, the area of a sector bounded by a curve. Consider the region.
1 © 2011 Pearson Education, Inc. All rights reserved 1 © 2010 Pearson Education, Inc. All rights reserved © 2011 Pearson Education, Inc. All rights reserved.
10.8 Polar Equations and Graphs. An equation whose variables are polar coordinates is called a polar equation. The graph of a polar equation consists.
CGMB214: Introduction to Computer Graphics
Rasterizing primitives: know where to draw the line Dr Nicolas Holzschuch University of Cape Town Modified.
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
Scan Conversion. Also known as rasterization In our programs objects are represented symbolically –3D coordinates representing an object’s position –Attributes.
College of Computer and Information Science, Northeastern UniversitySeptember 12, CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture.
1 CS 430/536 Computer Graphics I Circle Drawing and Clipping Week 3, Lecture 6 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent.
Dr. S.M. Malaek Assistant: M. Younesi
Jehee Lee Seoul National University
WHERE TO DRAW A LINE?? Line drawing is accomplished by calculating intermediate positions along the line path between specified end points. Precise definition.
Scan Conversion Line and Circle
CS 450: COMPUTER GRAPHICS REVIEW: DRAWING ELLIPSES AND OTHER CURVES SPRING 2015 DR. MICHAEL J. REALE.
2 Graphs and Functions © 2008 Pearson Addison-Wesley. All rights reserved Sections 2.1–2.4.
coordinates, lines and increment
Larry F. Hodges 1 Design of Line and Circle Algorithms.
1 Circle Drawing Algorithms Pictures snagged from
1 Line Drawing Version B: Semi-Formal Methods Derivation ©Anthony Steed
Graphics Output Primitives
Chapter 3 Scan Conversion Lecture-02. Bresenham’s Line Algorithm Bresenham’s line algorithm – is a highly efficient incremental method for scan- converting.
ELLIPSE GENERATING ALGORITHMS 1. DEFINITION Ellipse is an elongated circle. Elliptical curves can be generated by modifying circle-drawing procedures.
Vectors and the Geometry of Space 2015
MIDPOINT CIRCLE & ELLIPSE GENERARTING ALGORITHMS
November 18, We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle.
Computer Graphics Drawing Line. Lines and Polylines Convex: For every pair of points in the polygon, the line between them is fully contained in the polygon.
Copyright © 2011 Pearson Education, Inc. Equations and Graphs in Two Variables Section 1.3 Equations, Inequalities, and Modeling.
Sullivan Algebra and Trigonometry: Section 10.2 Objectives of this Section Graph and Identify Polar Equations by Converting to Rectangular Coordinates.
10/15/02 (c) 2002 University of Wisconsin, CS559 Who Am I? Prof Stephen Chenney These notes will be online after the lecture – in fact they’re online already.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
Conic Sections.
2 Graphs and Functions © 2008 Pearson Addison-Wesley. All rights reserved Sections 2.1–2.4.
Lesson: ____ Section: 3.7  y is an “explicitly defined” function of x.  y is an “implicit” function of x  “The output is …”
Scan Conversion.
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
Copyright © Cengage Learning. All rights reserved. Trigonometric Functions: Unit Circle Approach.
Computer Graphics Lecture 07 Ellipse and Other Curves Taqdees A. Siddiqi
Computer Graphics Lecture 06 Circle Drawing Techniques Taqdees A. Siddiqi
Primitive graphic objects
Scan Conversion or Rasterization
MID-POINT CIRCLE ALGORITHM
Scan Conversion or Rasterization
Lecture 05: Mid-point Ellipse algorithm Dr. Manal Helal – Fall 2014
Prof. Harriet Fell Spring 2007 Lecture 5 – January 17, 2006
Chapter Three Part I Output Primitives CS 380.
Scan Conversion of Circles
Scan Conversion (From geometry to pixels)
Chapter 3 Graphics Output Primitives
Presentation transcript:

Midpoint Circle Algorithm Spring 2006 Midpoint Circle Algorithm CS5600

More Raster Line Issues Spring 2006 More Raster Line Issues Fat lines with multiple pixel width Symmetric lines End point geometry – how should it look? Generating curves, e.g., circles, etc. Jaggies, staircase effect, aliasing... 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Prepared by Narendra V G CSE MIT Spring 2006 Generating Circles 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Where do we draw a circle??? Properties of a circle: A circle is defined as a set of points that are all the given distance (xc,yc). This distance relationship is expressed by the pythagorean theorem in Cartesian coordinates as (x – xc)2 + (y – yc) 2 = r2 We could use this equation to calculate the points on the circle circumference by stepping along x-axis in unit steps from xc-r to xc+r and calculate the corresponding y values at each position as y = yc +(- ) (r2 – (xc –x )2)1/2 This is not the best method: Considerable amount of computation Spacing between plotted pixels is not uniform

Polar co-ordinates for a circle We could use polar coordinates r and θ, x = xc + r cosθ y = yc + r sinθ A fixed angular step size can be used to plot equally spaced points along the circumference A step size of 1/r can be used to set pixel positions to approximately 1 unit apart for a continuous boundary But, note that circle sections in adjacent octants within one quadrant are symmetric with respect to the 45 deg line dividing the to octants Thus we can generate all pixel positions around a circle by calculating just the points within the sector from x=0 to x=y This method is still computationally expensive

Bresenham to Midpoint Bresenham requires explicit equation Not always convenient (many equations are implicit) Based on implicit equations: Midpoint Algorithm (circle, ellipse, etc.) Implicit equations have the form F(x,y)=0.

Midpoint Circle Algorithm We will first calculate pixel positions for a circle centered around the origin (0,0). Then, each calculated position (x,y) is moved to its proper screen position by adding xc to x and yc to y Note that along the circle section from x=0 to x=y in the first octant, the slope of the curve varies from 0 to -1 Circle function around the origin is given by fcircle(x,y) = x2 + y2 – r2 Any point (x,y) on the boundary of the circle satisfies the equation and circle function is zero

Exploit 8-Point Symmetry Spring 2006 Exploit 8-Point Symmetry 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Once More: 8-Pt Symmetry Spring 2006 Once More: 8-Pt Symmetry 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Prepared by Narendra V G CSE MIT Spring 2006 Only 1 Octant Needed We will generate 2nd Octant 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Generating pt (x,y) gives Spring 2006 Generating pt (x,y) gives the following 8 pts by symmetry: {(x,y), (-x,y), (-x,-y), (x,-y), (y,x), (-y,x), (-y,-x), (y,-x)} 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Prepared by Narendra V G CSE MIT Spring 2006 2nd Octant Is a Good Arc It is a function in this domain single-valued no vertical tangents: |slope|  1 Lends itself to Bresenham only need consider E or SE 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Implicit Eq’s for Circle Spring 2006 Implicit Eq’s for Circle Let F(x,y) = x 2 + y 2 – r 2 For (x,y) on the circle, F(x,y) = 0 So, F(x,y) > 0  (x,y) Outside And, F(x,y) < 0  (x,y) Inside 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Prepared by Narendra V G CSE MIT Spring 2006 Choose E or SE Function is x 2 + y 2 – r 2 = 0 So, F(M)  0  SE And, F(M) < 0  E 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Prepared by Narendra V G CSE MIT Spring 2006 Decision Variable d Again, we let, d = F(M ) 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Prepared by Narendra V G CSE MIT Spring 2006 Look at Case 1: E ideal curve 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Prepared by Narendra V G CSE MIT Spring 2006 dold < 0  E 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Prepared by Narendra V G CSE MIT Spring 2006 dold < 0  E 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Prepared by Narendra V G CSE MIT Spring 2006 dold < 0  E Since, 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Prepared by Narendra V G CSE MIT Spring 2006 dold < 0  E where, 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Prepared by Narendra V G CSE MIT Spring 2006 Look at Case 2: SE ideal curve 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

dold  0  SE Because,…, straightforward manipulation Spring 2006 dold  0  SE Because,…, straightforward manipulation 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Prepared by Narendra V G CSE MIT Spring 2006 dold  0  SE I.e., 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Prepared by Narendra V G CSE MIT Spring 2006 Note: Δ΄s Not Constant depend on values of xp and yp 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Prepared by Narendra V G CSE MIT Spring 2006 Summary Δ΄s are no longer constant over entire line Algorithm structure is exactly the same Major difference from the line algorithm Δ is re-evaluated at each step Requires real arithmetic 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Prepared by Narendra V G CSE MIT Spring 2006 Initial Condition Let r be an integer. Start at Next midpoint M lies at So, 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Circle Algorithm void MidPointCircle(int radius ) { x = 0; y = radius; d = (5/4) - radius; Circle_Points(x,y); while(y>x) If (d < 0) /*Select E */ d = d + 2*x + 3 else { /*Select SE */ d= d + 2*(x-y) + 5 y = y-1; } x = x+1; Circle_Points(int x, int y) { putpixel(x,y); putpixel(y,x); putpixel(x,-y); putpixel(y,-x); putpixel(-x,-y); putpixel(-y,-x); putpixel(-x,y); putpixel(-y,x); }

Prepared by Narendra V G CSE MIT Spring 2006 Getting to Integers Note the previous algorithm involves real arithmetic Can we modify the algorithm to use integer arithmetic? 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Integer Circle Algorithm Spring 2006 Integer Circle Algorithm Define a shift decision variable In the code, plug in 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Integer Circle Algorithm Spring 2006 Integer Circle Algorithm Now, the initialization is h = 1 - r So the initial value becomes 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Integer Circle Algorithm Spring 2006 Integer Circle Algorithm Then, Since h an integer 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Integer Circle Algorithm Spring 2006 Integer Circle Algorithm But, h begins as an integer And, h gets incremented by integer Hence, we have an integer circle algorithm Note: Sufficient to test for h < 0 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600

Fast Circle Algorithm void MidPointCircle(int radius ) { x = 0; y = radius; d = 1- radius; Circle_Points(x,y); while(y>x) If (d < 0) /*Select E */ d = d + 2*x + 3 else { /*Select SE */ d= d + 2*(x-y) + 5 y = y-1; } x = x+1; Circle_Points(int x, int y) { putpixel(x,y); putpixel(y,x); putpixel(x,-y); putpixel(y,-x); putpixel(-x,-y); putpixel(-y,-x); putpixel(-x,y); putpixel(-y,x); }

Prepared by Narendra V G CSE MIT Spring 2006 End of Midpoint Circle 4/26/2017 3:02 AM Prepared by Narendra V G CSE MIT CS5600