Está en la página 1de 35

Computer Graphics

Lecture 06
Circle Drawing Techniques

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..

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=2r

Circle Drawing Techniques

- Input for circle drawing


. one center point (xc, yc) 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):
x2 + y2 = r2,
an obvious choice is to plot
y = r2 - x2
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-xc to r+xc, and y is calculated using above
formula. Using this technique a simple algorithm will be:

Circle Drawing Using Cartesian


Coordinates
for x= radius-xcenter to radius+xcenter
y = yc + r2 ( x - xc )2
drawPixel (x, y)
y = yc - r2 ( x - xc )2
drawPixel (x, y)

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

x close to

Drawbacks/ Shortcomings

Circle Drawing Using Polar Coordinates


Polar Coordinates:
Radius
r
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 = xc + r cos
y = yc + 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 = xc + r * cos
y = yc + 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 = xc + r * cos
y = yc + 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 = (xk, yk) is the current
pixel.
Q = (xk+1, yk) is the pixel
to the right
R = (xk+1, yk -1) is the
pixel to the right and below.

X2- Y2 - r2 =0

X=Y

Midpoint Circle Algorithm


To apply the midpoint method, we define a circle function:
fcircle(x, y) = x2 + y2 r2
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

X2+Y2-R2=0

Xk+1

Mid Point Circle Algorithm


Assuming that the pixel (xk , yk) is plotted , the next
pixled point will be either (xk+1 , y k) or (xk+1 , y k-1).
Decision parameter is the circle function at the mid
point between these two functions.
Pk = f(xk+1 , yk 0.5) = (xk+1)2 + (yk 0.5) 2 r 2..(1)

Mid Point Circle Algorithm


If(pk <0) the mid point is inside the circle boundary and
pixel on the scan line yk is closer to the circle
boundary. Otherwise the mid point position is outside
or on the circle boundary and pixel on the scan line
y k-1 is selected.

Mid Point Circle Algorithm


Successive decision parameters are obtained by using
incremental calculations. A recursive expression for the
next decision parameter is obtained by evulationg the
circle function at sampling position x k+1 +1 =xk+2.
Pk+1= f(xk+1, yk+1 -0.5)= (xk+1 +1)2 +(yk+1 -0.5) 2 r2..(2)
Y
k+1

is either yk o yk-1 depending on the sign of pk

Mid Point Circle Algorithm


The initial decision parameter is obtained by
evaluating the circle function at the start position (x0
,y0)=(0,r).
Po=f(1,r-0.5)= 1+(r-0.5)2 + r2.(2)
P0=5/4 r(3)
Specify as integer
P0=1-r

Mid Point Circle Algorithm


1)Input radius r and circle center (xc ,yc) and obtain first
point on the circumference of a circle centered on the
origin as
(xo, yo)=(0,r)
2) Calucate final value of decision parameter as:
P0=1-r
3) At each xk position starting at k=0, perfom the
following test

Midpoint Circle Algorithm


If pk<0 , the next point along the circle centred on (0,0
)is (xk+1,yk) and
Pk+1= pk + 2xK+1
Else
The next point along the circle is (xk+1 , yk-1) and
Pk+1= pk+2xk+1 +1 2yk+1
Where

2xk+1 = 2xk +2
2yk+1 =2yk -2

4) Determine octant symmetry points in the other


seven octants.
5) Move each calculated pixel position(x,y) onto the
circular path centered on(xc,yc) and plot coordinates
values.
x=x+xc
y=y +yc
6) Repeat steps 3 to 5 until x<=y

También podría gustarte