Anda di halaman 1dari 7

What is a Circle?

• Set of points that are


all at the same
distance r from a
Chapter 3 center position (xc, yc).
• The distance r
Output Primitives relationship can be y c

Circle and Ellipse drawing represented by the


algorithms Pythagorean theorem: xc
– (x - xc)2 + (y – yc)2 = r2

Using this equation to draw


a circle Using polar coordinates
• Step along the x-axis in unit step from • Calculate points along a circular
xc–r to xc+r. boundary using polar coordinates r
• Calculate y as: and θ.
– y = yc ± √r2 – (xc - x)2
• The equations for calculating x and y
• Problems:
coordinates are:
– Computationally very expensive.
– Spacing between pixels is not uniform.
– x = xc + r cos θ
– Another way to eliminate unequal spacing is – y = yc + r sin θ
by using polar coordinate equations. • Step from 00 to 900.

1
Symmetry of circles
Polar Coordinates y
(-2, 8)
(-y, x) (2, 8)
9 (y, x)
 

(-8, 2) (8, 2)
(-x, y)   (x, y)
x
9
 (x, -y)
(-x, -y) 
(8, -2)
(-8, -2) Generate pixel
positions around a
  circle by calculating
(-y, -x) (y, -x) points within the
(-2, -8) (2, -8) sector x = 0 to x = y

Midpoint Circle Algorithm


• Sample at unit intervals and determine Midpoint Circle Algorithm
the closest pixel position to the specified
circle path at each step.
• Along the circle section from x = 0 to
x = y in the first quadrant, the slope
• For a given radius r and center (xc,yc) on
the screen, we of the curve varies from 0 to -1.
– Calculate pixel positions around the circle path • Take unit step in positive x direction
centered at coordinate origin (0,0). over this octant and use the decision
– The calculated pixel position (x,y) is then parameter to determine which of the
translated as
• x’ = x + xc. two possible y positions are closer to
• y’ = y + yc. the actual circle path at each step.

2
Circle function
• fcircle (x,y) = x2 + y2 – r2
– fcircle (x,y) < 0, if (x,y) is inside the circle
boundary.
– fcircle (x,y) = 0, if (x,y) is on the circle
boundary.
– fcircle (x,y) > 0, if (x,y) is outside the circle
boundary.

– Circle function tests are performed for the


mid positions between pixels near the circle
path at each sampling step DECISION
PARAMETER

Candidate pixel positions


Decision parameter
• Assuming we have • pk = fcircle(xk+1,yk-1/2)
plotted the pixel (xk,yk),
• pk = (xk+1)2 + (yk-1/2)2 – r2
the next pixel position is:
– (xk+1,yk) EAST – pk < 0, select yk
– (xk+1,yk-1) SOUTH EAST – pk >= 0, select yk-1
N

W E

SE
S

3
Next Increments
• pk+1 = fcircle(xk+1+1,yk+1-1/2) Initial Decision parameter
• pk+1= pk+2(xk + 1)+(y2k+1 – y2k)–(yk+1 – yk)+1 • Taking the point (0,r)
• If pk < 0, yk+1 = yk • p0 = 1 + (r-1/2)2 – r2
– pk+1 = pk + 2(xk + 1) + 1
• [as xk+1 = xk+1]
• p0 = 5/4 – r
– pk+1 = pk + 2xk+1 + 1 • Round the value to make it an
• If pk >= 0, yk+1 = yk-1 integer
– pk+1 = pk + 2(xk + 1) + 1 – 2(yk – 1) • p0 = 1 - r
• [as xk+1 = xk+1]

– pk+1 = pk + 2xk+1 + 1 – 2yk+1

Midpoint Circle Algorithm


• Input radius r and circle center (xc, yc), and obtain
the first point on the circumference of a circle
Midpoint Circle Algorithm
centered at the origin as • Determine symmetry points in the other
– (x0, y0) = (0, r) seven octants.
• Calculate the initial value of the decision • Move (x, y) along the circular according to
parameter as
the symmetry and plot:
– p0 = 5/4 - r
– x = x + xc &
• At each point xk position, starting at k = 0, – y = y + yc
perform the following test:
• Repeat until x >= y
– If pk < 0, next point centered at (0, 0) is (xk+1, yk) and
– pk+1 = pk + 2xk+1 + 1
– Otherwise, 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 and 2yk+1 = 2yk - 2

4
Selected pixel positions
Example: r = 10 y=x
p0 = 1-
1-10 = -9, 2x0 = 0, 2y0 = 0

10
9
k pk (xk+1, yk+1) 2xk+1 2yk+1

8
0 -9 (1, 10) 2 20

7
1 -6 (2, 10) 4 20

6
2 -1 (3, 10) 6 20

5
3 6 (4, 9) 8 18

4
4 -3 (5, 9) 10 18

3
5 8 (6, 8) 12 16

2
6 5 (7, 7) 14 14

1
0
0 1 2 3 4 5 6 7 8 9 10

Ellipse with foci F1 and F2


What is an ellipse? y

• Simply stated: an elongated circle. d1


• Definition: An ellipse is defined as a F1 P = (x, y)
d2
set of points such that the sum of
the distance from two fixed points F2

(foci) is the same for all points.


• If the distances to the two foci from x
any poiny P = (x, y) are d1 & d2,
then
– d1 + d2 = constant.

5
Major & Minor Axes
Simple case:
• Major axis is the
straight line y semi-major and • Is when the major and minor axes
segment extending semi-minor axes
from one side of the
are oriented to align with the
ellipse to the other. coordinate axes.
• Minor axis spans ry • rx semi-major axis.
the shorter
dimension of the
yc rx • ry semi-minor axis.
ellipse, bisecting the • Equation of the ellipse:
major axis at the – (x – xc/rx)2 + (y – yc/ry)2 = 1 . . . . . . . eq (1)
halfway position xc x
between the foci.

Polar coordinates 4-way symmetry


• Using rx and ry and θ, we can
describe an ellipse using the
following equations:
– x = xc + rx cos θ
– y = yc + ry sin θ
• Unlike a circle (8-way symmetric), an
ellipse is 4-way symmetric.
• We can draw an ellipse in one
quadrant and then use 4-way
symmetry to draw points in the rest
of the quadrants.

6
Midpoint ellipse algorithm
• Given parameters rx, ry and (xc, yc),
Midpoint algorithm (contd)
we determine points (x, y) for an • The algorithm is applied throughout
ellipse in a standard position the 1st quadrant in two stages.
centered at the origin. • The algorithm is devised for ellipses
• Once we have done that, we can do with rx < ry, although it can be
two things: generalized for all ellipses.
– Add xc and yc to translate the origin to • What do we do?
(xc, yc). – Divide the quadrant in 2 regions.
– If the ellipse was not aligned with the x- – Unit increment in x and once we have
reached the region boundary, we switch
y coordinates, then we can rotate about and unit increment in y.
the center to re-orient the major and
minor axes.

Ellipse function with (xc,yc) =


(0, 0)
• Using eq (1), we define the ellipse
function as:
– fellipse(x, y) = ry2x2 + rx2y2 – rx2ry2
• Which has the following properties:
– fellipse(x, y) < 0, if (x, y) is inside the
boundary
– fellipse(x, y) = 0, if (x, y) is on the
boundary
– fellipse(x, y) > 0, if (x, y) is outside the
boundary

Anda mungkin juga menyukai