0% found this document useful (0 votes)
89 views11 pages

MidPoint Circle Algorithmnew

The document describes the midpoint circle algorithm for drawing circles on a pixel grid. It works as follows: 1. Calculate the midpoint between the current pixel and the next potential pixel. 2. Use this midpoint to calculate a decision parameter based on the circle equation. 3. If the decision parameter is negative, the midpoint is inside the circle so use the current pixel. If positive or zero, the midpoint is outside so use the next potential pixel.

Uploaded by

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

MidPoint Circle Algorithmnew

The document describes the midpoint circle algorithm for drawing circles on a pixel grid. It works as follows: 1. Calculate the midpoint between the current pixel and the next potential pixel. 2. Use this midpoint to calculate a decision parameter based on the circle equation. 3. If the decision parameter is negative, the midpoint is inside the circle so use the current pixel. If positive or zero, the midpoint is outside so use the next potential pixel.

Uploaded by

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

MidPoint Circle Algorithm

It is based on the following function for testing the spatial relationship between the
arbitrary point (x, y) and a circle of radius r centered at the origin:

Now, consider the coordinates of the point halfway between pixel T and pixel S

This is called midpoint (xi+1,yi- ) and we use it to define a decision parameter:

            Pi=f (xi+1,yi- ) = (xi+1)2+(yi- )2-r2 ...............equation 2

6.8M
148
OOPs Concepts in Java

If Pi is -ve ⟹midpoint is inside the circle and we choose pixel T

If Pi is+ve ⟹midpoint is outside the circle (or on the circle)and we choose pixel S.

The decision parameter for the next step is:


Pi+1=(xi+1+1)2+(yi+1- )2- r2............equation 3

Since xi+1=xi+1, we have

If pixel T is choosen ⟹Pi<0

We have yi+1=yi

If pixel S is choosen ⟹Pi≥0

We have yi+1=yi-1

We can continue to simplify this in n terms of (x i,yi) and get

Now, initial value of Pi (0,r)from equation 2

We can put  ≅1
∴r is an integer
So, P1=1-r
OR( those who want to know complete derivation can learn below II derivation) or you can write the
above only
Or
II Complete derivation steps(those who needed only )

A circle is highly symmetrical and can be divided into 8 Octets on


graph. Lets take center of circle at Origin i.e (0,0) :
We need only to conclude the pixels of any one of the octet rest
we can conclude because of symmetrical properties of circle.
Radius = OR = r

Radius = x intercept = y intercept


At point R
     coordinate of x = coordinate of y   or we can say  x=y
let us take Octet 2 of quadrant 1
here first pixel would be (0,y)
            here value of y intercept = radius (r)
 as circle’s center is at origin
let us assume we have plotted Pixel P whose
coordinates are  
Now we need to determine the next pixel. 

We have chosen octet 2 where circle is moving forward and


downwards so y can never be increased, either it can be same or
decremented. Similarly x will always be increasing as circle is
moving forward too.

So y is needed to be decided.


Now we need to decide whether we should go with point N or S.

For that decision Mid Point circle drawing technique will us decide
our next pixel whether it will be N or S.

As    is the next most pixel of    therefore we can write,
                    

And similarly    in this case.

Let M is the midpoint between    and  . 


And coordinates of point (M) are

                        

                                  

                 

Equation of Circle with Radius r

(x– h)2 + (y – k)2 = r2

When coordinates of centre are  at Origin i.e.,  (h=0, k=0)

     x2 + y2 = r2    (Pythagoras theorem)


Function of Circle Equation

F(C) =   x2 + y2 - r2


Function of Midpoint M (xk+1 ,  yk -1/2) in circle equation

F(M)= xk+12 + (yk -1/2)2 - r2 


          
= (xk+1)2 + (yk -1/2)2 - r2 

The above equation is too our decision parameter pk

Pk = (xk+1)2 + (yk -1/2)2 - r2           …….(i)

To find out the next decition parameter we need to get Pk+1


Pk+1 = (xk+1+1)2 + (yk+1 -1/2)2 - r2

Now,
Pk+1- Pk =  (xk+1+1)2 + (yk+1 -1/2)2 - r2
                          -[(xk+1)2 + (yk -1/2)2 - r2]

                     =  ((xk+1)+1)2 + (yk+1 -1/2)2
                            - (xk+1)2   - (yk -1/2)2 

                 = (xk+1)2 + 1 +2(xk+1) + yk+12 +(1/4) - yk+1


                      - (xk+1)2   - yk2 – (1/4) + yk+1

                = 2(xk+1) + yk+12 - yk2 - yk+1 + yk +1

                =  2(xk+1) +( yk+12 - yk2 ) - (yk+1 - yk) +1

Pk+1 = Pk + 2(xk+1)+( yk+12 - yk2 ) - (yk+1 - yk) +1     …..(ii)

Now let us conclude the initial decision parameter


For that we have to choose coordinates of starting point
i.e. (0,r)

Put this in (i) i.e. Pk

Pk = (xk+1)2 + (yk -1/2)2 - r2
P0 = (0+1)2 + (r -1/2)2 - r2
        = 1 + r2 + ¼ - r – r2
        = 1 + ¼ - r

                …..(initial decision parameter)


Now If Pk ≥ 0 that means midpoint is outside the circle and S is
closest pixel so we will choose S (xk+1,yk-1)
That means yk+1 = yk-1
Putting coordinates of S in (ii) then,

Pk+1 = Pk + 2(xk+1)+( yk-12 - yk2 ) - (yk-1 - yk) +1


        = Pk + 2(xk+1)+( yk -1)2 - yk2 ) - ((yk-1) - yk) +1
        = Pk + 2(xk+1)+yk 2+1-2yk - yk2 - yk+1 + yk +1
        = Pk + 2(xk+1)-2yk +2 + 1
        = Pk + 2(xk+1)-2(yk -1) + 1

As we know (xk+1 = xk+1) and (yk-1 = yk-1)


Therefore,
                Pk+1 = Pk + 2xk+1 - 2yk-1 + 1

And if Pk < 0 that means midpoint is inside the circle and N is


closest pixel so we will choose N (xk+1 , yk)
i.e. yk+1 = yk
        Now put coordinates of N in (ii)
Pk+1 = Pk + 2(xk+1)+( yk2 - yk2 ) - (yk - yk) +1
        = Pk + 2(xk+1)+( yk2 - yk2 ) - (yk - yk) +1
        = Pk + 2(xk+1) +1

as xk+1 = xk+1 , therefore,
                        Pk+1 = Pk + 2xk+1 +1

You might also like