12
PRESTIGE INSTITUTE OF MANAGEMENT

Mid-Point Cirle Drawing Algorithm

Embed Size (px)

Citation preview

Page 1: Mid-Point Cirle Drawing Algorithm

PRESTIGE INSTITUTE OF MANAGEMENT

Page 2: Mid-Point Cirle Drawing Algorithm

PRESENTATION ONMID-POINT CIRCLE DRAWING

PRESENTED BY:NEHA KAURAV

HIMANSHI GUPTA

CLASS:BCA 3rd SEM.

Page 3: Mid-Point Cirle Drawing Algorithm

ABOUT CIRCLE• A circle is all points in the same plane that lie at an equal distance from a

center point. The circle is only composed of the points on the border. • The distance between the midpoint and the circle border is called the

radius. A line segment that has the endpoints on the circle and passes through the midpoint is called the diameter. The diameter is twice the size of the radius. A line segment that has its endpoints on the circular border but does not pass through the midpoint is called a chord.

Page 4: Mid-Point Cirle Drawing Algorithm

Circle Algorithms

4

• Use 8-fold symmetry and only compute pixel positions for the 45° sector.

45°

(x, y)

(y, x)

(-x, y)

(y, -x)

(x, -y)(-x, -y)

(-y, x)

(-y, -x)

Page 5: Mid-Point Cirle Drawing Algorithm

MIDPOINT CIRCLE ALGORITHM

• Circle function: Fcircle(x,y)=x2+y2-r2

Fcircle(x,y)>0,then (x,y) lies outside the circle.Fcircle(x,y)<0,then (x,y) lies inside the circleFcircle(x,y)=0,then (x,y) is on the circle boundary.

.

Fk<0Yk+1=yk

Next pixel=(xk+1,yk)Midpoint inside the circle

.

Fk>=0Yk+1=yk-1

Next pixel=(xk+1,yk-1)Midpoint above the

circle

Page 6: Mid-Point Cirle Drawing Algorithm

MIDPOINT CIRCLE ALGORITHM• The decision parameter is the circle at the midpoint between the

pixels ykand yk – 1. f=fcircle(xk+1,yk-1/2) =(xk+1)2+(yk-1/2)2-r2

We know that Xk+1=xk+1,

Fk=f(xk+1,yk-1/2) Fk=(xk+1)2+(yk-1/2)2-r2 (i)

Fk+1=f(xk+2,yk+1-1/2)

Fk+1=(xk+2)2+(yk+1-1/2)2-r2 (ii)Now subtracting eqn (ii) by (i)

Fk+1-fk=2(xk+1)+(y2k+1-y2

k)-(yk+1-yk)+1

Page 7: Mid-Point Cirle Drawing Algorithm

So, If fk<0: yk+1=yk

Fk+1=fk+2xk+1+1 If fk>=0: yk+1=yk-1

Fk+1=fk+2xk+1-2yk+1+1For the initial points, (x0,y0)=(0,r)

F0=fcircle(1,r-1/2) =1+(r-1/2)2-r

=5/4-r=1-r

Page 8: Mid-Point Cirle Drawing Algorithm

The Algorithm1. Initial values:- point(0,r)x0 = 0y0 = r

2. Initial decision parameter

3. At each xi position, starting at i = 0, perform the following test: if pi < 0, the next point is (xi + 1, yi) and

pi+1 = pi + 2xi+1 + 1 If pi ≥ 0, the next point is (xi+1, yi-1) and

pi+1 = pi + 2xi+1 + 1 – 2yi+1

where 2xi+1 = 2xi + 2 and 2yi+1 = 2yi – 24. Determine symmetry points in the other octants5. Move pixel positions (x,y) onto the circular path centered

on (xc, yc) and plot the coordinates: x = x + xc, y = y + yc

6. Repeat 3 – 5 until x >= y

2 2 51 10 2 2 4(1, ) 1 ( )circlep f r r r r

8

Page 9: Mid-Point Cirle Drawing Algorithm

MIDPOINT ALGORITHMvoid plotpoints(int xcenter,int ycenter,int x,int y){

setpixel(xcenter+x, ycenter+y);setpixel(xcenter+x, ycenter-y);setpixel(xcenter-x, ycenter+y);setpixel(xcenter-x, ycenter-y);setpixel(xcenter+y, ycenter+x);setpixel(xcenter+y, ycenter-x);setpixel(xcenter-y, ycenter+x);setpixel(xcenter-y, ycenter-x);

}

void midpoint(int xcenter,int ycenter,int radius){

int x = 0, y = radius;int f = 1 – radius;

plotpoints(xcenter,ycenter,x,y);while (x<y) {

x++;if (f<0) f += 2*x + 1;else {

y--;f+= 2*(x-y) + 1;

}plotpoints(xcenter,ycenter,x,y);

}}

Page 10: Mid-Point Cirle Drawing Algorithm

Example

10

9 8 7 6 5 4 3 2 1 0

0 1 2 3 4 5 6 7 8 9 1010

i pi xi+1, yi+1 2xi+1 2yi+1

0 -9 (1, 10) 2 20

1 -6 (2, 10) 4 20

2 -1 (3, 10) 6 20

3 6 (4, 9) 8 18

4 -3 (5, 9) 10 18

5 8 (6, 8) 12 16

6 5 (7, 7)

r = 10p0 = 1 – r = -9 (if r is integer round p0 = 5/4 – r to integer)

Initial point (x0, y0) = (0, 10)

Page 11: Mid-Point Cirle Drawing Algorithm

PROGRAM

Page 12: Mid-Point Cirle Drawing Algorithm

THANK YOU