Graphics 05 Mid-Point Circle SC
Graphics 05 Mid-Point Circle SC
P=(rCos, rSin)
r rSin)
x
rCos)
Drawing a circle
= 0°
while ( < 360°)
x = rCos
y = rSin
setPixel(x,y)
= + 1°
end while
Disadvantages
• To find a complete circle varies from 0° to 360°
• The calculation of trigonometric functions is very slow.
Cartesian form
• Use Pythagoras theorem
r y
x2 + y2 = r2
• So, we can write a simple circle x
drawing algorithm by solving the y
equation for y at unit x intervals
using:
P x, r 2 x 2
y r x 2 2
r y
x x
A Simple Circle Drawing Algorithm
y0 20 2 0 2 20
y1 20 2 12 20
y2 20 2 22 20
y19 20 2 19 2 6
y20 20 20 0
2 2
Circle algorithms
• Step through x-axis to determine y-values
Problems
• However, unsurprisingly this is not a brilliant solution!
• Firstly, the resulting circle has large gaps where the
slope approaches the vertical
• Secondly, the calculations are not very efficient
• The square (multiply) operations
• The square root operation – try really hard to avoid these!
• We need a more efficient, more accurate solution
Circle Algorithms
• Use 8-fold symmetry and only compute pixel positions
for the 45° sector.
• The first thing we can notice to make our circle drawing
algorithm more efficient is that circles centred at (0, 0) have
eight-way symmetry
(-x, y) (x, y)
(-y, x) (y, x)
R
2
(-y, -x) (y, -x)
f circ ( x, y) x 2 y 2 r 2
• The equation evaluates as follows:
yk yk
midpoint midpoint
yk-1 yk-1
Fk >= 0 Fk < 0
yk+1 = yk yk+1 = yk - 1
Next pixel = (xk+1, yk) Next pixel = (xk+1, yk-1)
16
Mid-Point Circle Algorithm
Case I: When E is next
• What increment for computing a new D?
• Next midpoint is:
(0,-R)
(R,0)
(0,R)
Algorithm
Fig. 3.15, Fig. 3.16 and Fig. 3.18
Practice/Exercise: