0% found this document useful (0 votes)
30 views23 pages

Graphics Lecture 04

Uploaded by

ebnahmed1112
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views23 pages

Graphics Lecture 04

Uploaded by

ebnahmed1112
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

IT-331 ( Computer Graphics

1)

Lecture 4
Circle - Generating Algorithms

Dr. Mohammed El-Said


Assistant Professor, Computer Science Dept.,
Faculty of Computers & Artificial Intelligence,
Helwan University - Cairo, Egypt.
1
Scan Converting Circles
2 2 2
( x  xc )  ( y  yc ) R

2 2
y  y c  R  ( x  xc )

• Explicit: y = f(x)
y  R 2  x 2
We could draw a quarter circle by
incrementing x from 0 to R in unit
steps and solving for +y for each
step.

Method needs lots of computation, and gives non-uniform


pixel spacing
Scan Converting Circles

• Parametric:
x R cos 
y R sin 

Draw quarter circle by stepping through the angle from 0


to 90
- avoids large gaps but still unsatisfactory
- How to set angular increment
Computationally expensive trigonometric calculations
Scan Converting Circles
• Implicit: f(x,y) = x2+y2-R2

If f(x,y) = 0 then it is on the circle.


f(x,y) > 0 then it is outside the circle.
f(x,y) < 0 then it is inside the circle.

Try to adapt the Bresenham midpoint approach

Again, exploit symmetries


Generalising the Bresenham midpoint
approach

• Set up decision parameters for finding the


closest pixel to the cırcumference at each
sampling step
– Avoid square root calculations by considering the
squares of the pixel separation distances
• Use direct comparison without squaring.
Adapt the midpoint test idea: test the halfway
position between pixels to determine if this
midpoint is inside or outside the curve
This gives the midpoint algorithm for circles
Can be adapted to other curves: conic sections
Eight-way Symmetry
- only one octant’s calculation needed
The 2nd Octant is a good arc to draw

• It is a well-defined function in this domain


– single-valued
– no vertical tangents: |slope|  1
• Lends itself to the midpoint approach
– only need consider E or SE
• Implicit formulation F(x,y) = x 2 + y 2 – r 2

– For (x,y) on the circle,


F(x,y) = 0
– F(x,y) > 0  (x,y) Outside
– F(x,y) < 0  (x,y) Inside
Choose E or SE
• Decision variable d is x 2 + y 2 – r 2
• Then d = F(M) >= 0  SE
• Or d = F(M) < 0  E
F (M) >= 0  SE

current
pixel E
ideal
curve M

SE
F (M) < 0  E

E
ideal
curve
M

SE
Decision Variable p

As in the Bresenham line algorithm we


use a decision variable to direct the
selection of pixels.
Use the implicit form of the circle
equation
p = F (M ) = x 2 + y 2 – r 2
Midpoint coordinates are ( xk  1, yk  1 )
2
Assuming we have just plotted point at
(xk,yk) we determine whether move E or SE
by evaluating the circle function at the
midpoint between the two candidate pixel
positions 1
pk Fcirc ( xk  1, yk  )
2
2
( xk  1)  ( yk  1 2
)  r 2
2

pk is the decision variable


if pk <0 the midpoint is inside the circle
Thus the pixel above the midpoint is closer to the ideal
circle, and we select pixel on scan line yk. i.e. Go E
If pk >0 the midpoint is outside the circle.
Thus the pixel below the midpoint is closer
to the ideal circle, and we select pixel on
scan line yk-1. i.e. Go SE

Calculate successive decision parameter values p by


incremental calculations.

pk 1 Fcirc ( xk 1  1, yk 1  1 )
2
[( xk  1)  1]2  ( yk 1  1 ) 2  r 2
2
recursive definition for successive decision
parameter values p

pk 1 Fcirc ( xk 1  1, yk 1  1 )
2
[( xk  1)  1]2  ( yk 1  1 ) 2  r 2
2

2 2
pk 1  pk  2( xk  1)  ( y k 1  y )  ( yk 1  yk )  1
k

Where yk+1 = yk if p<0 (move E)


yk+1 = yk-1 if p>0 (move SE)

yk+1 and xk+1 can also be defined recursively


Initialisation

x0 = 0, y0 = r
Initial decision variable found by evaluating circle
function at first midpoint test position
p0 Fcirc (1, r  1 )
2
1  (r  1 2
)  r 2
2
5
  r
4
For integer radius r p0 can be rounded to p0 =1-r
since all increments are integer.
Midpoint Circle Algorithm (cont.)
Midpoint Circle Algorithm (cont.)
Example
• r=10

You might also like