Computer Graphics Lecture 06 Circle Drawing Techniques Taqdees A. Siddiqi

Slides:



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

Contents In today’s lecture we’ll have a look at:
CS 450: COMPUTER GRAPHICS DRAWING ELLIPSES AND OTHER CURVES SPRING 2015 DR. MICHAEL J. REALE.
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.
CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
+ CPCS 391 Computer Graphics 1 Instructor: Dr. Sahar Shabanah Lecture 3.
Larry F. Hodges (modified by Amos Johnson) 1 Design of Line, Circle & Ellipse Algorithms.
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.
Circle Drawing algo..
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.
CGMB214: Introduction to Computer Graphics
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
Graphics Primitives: line. Pixel Position
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.
Larry F. Hodges 1 Design of Line and Circle Algorithms.
Slide 5- 1 Copyright © 2006 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Slide 9- 1 Copyright © 2006 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
1 Circle Drawing Algorithms Pictures snagged from
Introduction Computer Graphics & Its application Types of computer graphics Graphic display : random Scan & Raster Scan display Frame buffer and video.
Graphics Output Primitives
Copyright © Cengage Learning. All rights reserved. Polar Coordinates and Parametric Equations.
 A line segment in a scene is defined by the coordinate positions of the line end-points x y (2, 2) (7, 5)
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.
Midpoint Circle Algorithm
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.
Computer Graphics Lecture 08 Taqdees A. Siddiqi Computer Graphics Filled Area Primitives I Lecture 08 Taqdees A. Siddiqi
Instructor: Dr. Shereen Aly Taie If (P>0)
Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Write Bresenham’s algorithm for generation of line also indicate which raster locations would be chosen by Bresenham’s algorithm when scan converting.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
Computer Graphics Lecture 07 Ellipse and Other Curves Taqdees A. Siddiqi
Computer Graphics Lecture 05 Line Drawing Techniques Taqdees A. Siddiqi
Line Drawing Algorithms 1. A line in Computer graphics is a portion of straight line that extends indefinitely in opposite direction. 2. It is defined.
Objectives Understand Bresenhams line drawing algorithm. Apply the algorithm to plot a line with the end points specified.
Primitive graphic objects
5.1 The Unit Circle.
Scan Conversion or Rasterization
Computer Graphics Lecture 13 Graphics Systems Taqdees A
MID-POINT CIRCLE ALGORITHM
Parametric equations Parametric equation: x and y expressed in terms of a parameter t, for example, A curve can be described by parametric equations x=x(t),
Computer Graphics Lecture 14 CLIPPING I Taqdees A. Siddiqi
The Dance of the Foci David Seppala-Holtzman St. Joseph’s College
In other words, at time t, the particle is located at the point Sketch the curve with parametric equations.
CS G140 Graduate Computer Graphics
Co-ordinate Geometry in the (x, y) Plane.
Polynomial Functions.
Scan Conversion or Rasterization
Lecture 05: Mid-point Ellipse algorithm Dr. Manal Helal – Fall 2014
Chapter Three Part I Output Primitives CS 380.
Circles Geometry = 40 points.
Fitting Curve Models to Edges
Image Processing, Leture #12
Scan Conversion of Circles
5.1 The Unit Circle.
Coordinate Geometry in the (x,y) plane.
Rasterizing Lines 1 Lecture 32 Mon, Nov 12, 2007.
Copyright © Cengage Learning. All rights reserved.
ENGINEERING MECHANICS
Chapter 3 Graphics Output Primitives
Finding Basic Shapes Hough Transforms
OUTPUT PRIMITIVES / DISPLAY TECHNIQUES
Presentation transcript:

Computer Graphics Lecture 06 Circle Drawing Techniques Taqdees A. Siddiqi

What is Circle A circle is the set of points in a plane that are equidistant from a given point O. The distance r from the center is called the radius, and the point O is called the center. Twice the radius is known as the diameter. The angle a circle subtends from its center is a full angle, equal to 360° or 2  radians.

Circle Cont..

A circle has the maximum possible area for a given perimeter, and the minimum possible perimeter for a given area. The perimeter C of a circle is called the circumference, and is given by C = 2  r

Circle Drawing Techniques - Input for circle drawing. one center point (x c, y c ) and. radius r Now, using these two inputs there are a number of ways to draw a circle.

Circle Drawing Techniques These techniques have: - Understanding curve. very simple to. complex - Time complexity. inefficient to. efficient

Circle Drawing Using Cartesian Coordinates This technique uses the equation for a circle with radius r centered at (0,0): x 2 + y 2 = r 2, an obvious choice is to plot y = ± r 2 - x 2 against different values of x.

Circle Drawing Using Cartesian Coordinates Using above equation a circle can be easily drawn. The value of x varies from r-x c to r+x c, and y is calculated using above formula. Using this technique a simple algorithm will be:

Circle Drawing Using Cartesian Coordinates for x= radius-x center to radius+x center y = y c + r 2 – ( x - x c ) 2 drawPixel (x, y) y = y c - r 2 – ( x - x c ) 2 drawPixel (x, y)

Drawbacks/ Shortcomings This works, but …. is inefficient. multiplications & square root. large gaps in the circle for values of x close to r (as shown in the next figure)

Drawbacks/ Shortcomings

Circle Drawing Using Polar Coordinates Polar Coordinates: Radiusr Angle  calculate points along the circular boundary using polar coordinates r and  Expressing the circle equation in parametric polar form yields the pair of equations:

Circle Drawing Using Polar Coordinates Cont… x = x c + r cos  y = y c + r sin  Using above equation circle can be plotted by calculating x and y coordinates as  takes values from 0 to 360 degrees or 0 to 2  radians.

Circle Drawing Using Polar Coordinates Cont… The step size for  depends on:. application and. display device Larger angular separations along the circumference can be connected with straight-line segments to approximate the circular path. Step size at 1/r gives continuous boundary This plots pixel positions that are approximately one unit apart.

Polar Coordinates Algorithm Circle2 (xcenter, ycenter, radius) for  = 0 to 2  step 1/r x = x c + r * cos  y = y c + r * sin  drawPixel (x, y)

Discussion - very simple technique - solves problem of unequal space - is inefficient in terms of calculations - involves floating point calculations

Reduction in Calculations  Symmetry in octants  Upper half circle symmetric to lower half circle  Left half circle symmetric to right half circle  Finally two halves of the same quarters are symmetric to each other

Eight Octants Symmetry

Optimizing the Algorithm Now this algorithm can be optimized by using symmetric octants as: Circle2 (xcenter, ycenter, radius) for  = 0 to  /4 step 1/r x = x c + r * cos  y = y c + r * sin  DrawSymmetricPoints(xcenter, ycenter, x,y)

Optimized Algorithm DrawSymmeticPoints (xcenter, ycenter, x, y) Plot (x + xcenter, y + ycenter) Plot (y + xcenter, x + ycenter) Plot (y + xcenter, -x + ycenter) Plot (x + xcenter, -y + ycenter) Plot (-x + xcenter, -y + ycenter) Plot (-y + xcenter, -x + ycenter) Plot (-y + xcenter, x + ycenter) Plot (-x + xcenter, y + ycenter)

Inefficiency Still Prevails  Reduction in calculations by exploiting symmetric octants but…  Floating point calculations still involved

Midpoint Circle Algorithm  Derivation of decision parameter  Decrement decision in the y coordinate against increment of x coordinate

Midpoint Circle Algorithm Consider only the first octant of a circle of radius r centered on the origin. We begin by plotting point (0, r) and end when x = y.

Midpoint Circle Algorithm The decision at each step is whether to choose : the pixel to the right of the current pixel or the pixel which is to the right and below the current pixel (8-way stepping)

Midpoint Circle Algorithm Assume: P = (x k, y k ) is the current pixel. Q = (x k +1, y k ) is the pixel to the right R = (x k +1, y k -1) is the pixel to the right and below. X = Y X 2- Y 2 - r 2 =0

Midpoint Circle Algorithm To apply the midpoint method, we define a circle function: f circle (x, y) = x 2 + y 2 – r 2 The following relations can be observed: f circle (x, y) < 0,if (x, y) is inside the circle boundary f circle (x, y) = 0,if (x, y) is on the circle boundary f circle (x, y) > 0,if (x, y) is outside the circle boundary

Midpoint Circle Algorithm Circle function tests are performed for the midpoints between pixels near the circle path at each sampling step.

Midpoint Circle Algorithm X k +1 X 2+ Y 2 -R 2 =0 k k k

Midpoint Circle Algorithm Figure given in previous slide shows the midpoint between the two candidate pixels at sampling position x k +1. Our decision parameter is the circle function evaluated at the midpoint between these two pixels:

Decision Parameter P k = f circle ( x k + 1, y k - ½ ) P k = ( x k + 1 ) 2 + ( y k - ½ ) 2 – r 2 ……...(1)

Decision Parameter If p k < 0, this midpoint is inside the circle and the pixel on scan line y k is closer to the circle boundary. Otherwise, the mid position is outside or on the circle boundary, and we select the pixel on scan-line y k -1.

Decision Parameter Successive decision parameters are obtained using incremental calculations. We obtain a recursive expression for the next decision parameter by evaluating the circle function at sampling position x k+1 +1 = x k +2:

Decision Parameter P k+1 = f circle ( x k+1 + 1, y k+1 - ½ ) P k+1 = [ ( x k + 1 ) + 1 ] 2 + ( y k+1 - ½ ) 2 – r 2.……… (2)

Decision Parameter Subtracting (1) from (2), we get: P k+1 - P k = [ ( x k + 1 ) + 1 ] 2 + ( y k+1 - ½ ) 2 – r 2 – ( x k + 1 ) 2 - ( y k - ½ ) 2 + r 2 or P k+1 = P k + 2( x k + 1 ) + ( y 2 k+1 - y 2 k ) – ( y k+1 - y k ) + 1

Decision Parameter Where y k+1 is either y k or y k -1, depending on the sign of P k. Therefore, if P k < 0 or negative then y k+1 will be y k and the formula to calculate P k+1 will be:

Decision Parameter P k+1 = P k + 2( x k + 1 ) + ( y 2 k - y 2 k ) – ( y k - y k ) + 1 P k+1 = P k + 2( x k + 1 ) + 1

Decision Parameter Otherwise, if P k > 0 or positive then y k+1 will be y k -1 and the formula to calculate P k+1 will be:

Decision Parameter P k+1 = P k + 2( x k + 1 ) + [ (y k -1) 2 - y 2 k ] – (y k -1- y k ) + 1 P k+1 = P k + 2(x k + 1) + (y 2 k - 2 y k +1 - y 2 k ) – ( y k -1- y k ) + 1 P k+1 = P k + 2( x k + 1 ) - 2 y k P k+1 = P k + 2( x k + 1 ) - 2 y k P k+1 = P k + 2( x k + 1 ) - 2 ( y k – 1 ) + 1

Decision Parameter Now a similar case that we observed in line algorithm is that how would starting P k be calculated. For this, the starting pixel position will be (0, r). Therefore, putting this value in equation, we get

Decision Parameter P 0 = ( ) 2 + ( r - ½ ) 2 – r 2 P 0 = 1 + r 2 - r + ¼ – r 2 P 0 = 5/4 – r If radius r is specified as an integer, we can simply round p 0 to: P 0 = 1 – r Since all increments are integer. Finally the algorithm can be summed up as :

Algorithm MidpointCircle (xcenter, ycenter, radius) x = 0; y = r; p = 1 - r; do DrawSymmetricPoints (xcenter, ycenter, x, y) x = x + 1 If p < 0 Then p = p + 2 * ( y + 1 ) + 1

Algorithm Cont… else y = y - 1 p = p + 2 * ( y + 1) –2 ( x – 1 ) + 1 while ( x < y ) Example to calculate first octant of the circle using above algorithm.

Example center ( 0, 0 )radius =10

Example Cont… Behaviour of calculated points around the circle is observable

Computer Graphics Lecture 06 Circle Drawing Techniques Taqdees A. Siddiqi