Bresenham's Mid Point Ellipse Generation Algorithm Mathematical Analysis
Bresenham's Mid Point Ellipse Generation Algorithm Mathematical Analysis
Bresenham's Mid Point Ellipse Generation Algorithm Mathematical Analysis
Experiment No.6
Title: Write and study Bresenham’s mid point ellipse generation algorithm and it’s c program.
Mathematical Analysis
Ellipse is another important geometric entity. It is a symmetric entity about its major axis and
minor axis. Figure 1 shows an origin centered ellipse divided into 4 parts. This property of
ellipse (symmetric about its major axis and minor axis) can be used in generation of ellipse with
minimum codes. Out of the four parts shown in Fig. 1, only first part is to be generated,
remaining three fourth part is generated by using the symmetry of ellipse. Generation starts from
point (0, Ry) where Ry is semi-minor axis of the ellipse.
Figure 2 shows two parts of a quarter ellipse. If a tangent is drawn to part 1 then the absolute
slope of the tangent would be less than one. Similarly if a tangent is drawn to the part 2, then the
absolute slope of the tangent would be greater than one. This indicates that the arc of part 1 is
more horizontal than part 2 whereas arc of part 2 is more vertical than part 1. But slope of
tangent would be equal to one at point where part 1 and part 2 meets (point m). Hence generation
of ellipse starts from point (0, Ry) and ends at point m. The condition at point m is derived in
equation (2.39a).
or
Figure 3 shows part 1 of a quarter ellipse. As discussed in previous topic, that if a tangent is
drawn to part 1 then the absolute slope of the tangent would be less than one or the arc of part 1
is more horizontal. So, the value of x coordinate will be incremented by one in every step and y
coordinate needs to be calculated. The value of Y coordinate is calculated depending upon the
position of midpoint of two successive vertical points. Two cases are discussed below from
which Fig.4 shows position of mid point is outside the ellipse and Fig. 5 shows position of mid
point is inside the ellipse.
Figure 6 shows part 2 of a quarter ellipse. As discussed in previous topic, that if a tangent is
drawn to part 2 then the absolute slope of the tangent would be greater than one or the arc of
part 2 is more vertical. So, the value of y coordinate will be incremented by one in every step and
x coordinate needs to be calculated. The value of x coordinate is calculated depending upon the
position of midpoint of two successive horizontal points. Two cases are discussed below from
which Fig. 7 shows position of mid point is inside the ellipse and Fig. 8 shows position of mid
point is outside the ellipse.
STEP 2: [INITIALIZATION]
Read
Read
x=0
y=
loop,
put pixel ( x, y)
if
else
x=
y=0
loop,
put pixel ( x, y)
if
else
put pixel
put pixel
put pixel
put pixel
STEP 4: [STOP]
#include<graphics.h>
#include<math.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int rx,ry,xc,yc,x1,y1,x2,y2,p1,p2,i,j;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("enter the center of the ellipse");
scanf("%d%d",&xc,&yc);
printf("enter semi_major and semi_minor axis");
scanf("%d%d",&rx,&ry);
x1=0;
y1=ry;
p1=(ry^2-ry*rx^2);
for(i=0;x1*ry^2<y1*rx^2;i++)
{
if(p1<0)
{
x1=x1+1;
y1=y1;
p1=p1+(2*x1+3)*ry^2;
}
else
{
x1=x1+1;
y1=y1-1;
p1=p1+(2*x1+3)*ry^2+(2-2*y1)*rx^2;
}
putpixel(x1+xc,y1+yc,1);
putpixel(-x1+xc,y1+yc,1);
putpixel(x1+xc,-y1+yc,1);
putpixel(-x1+xc,-y1+yc,1);
}
x2=rx;
y2=0;
p2=rx^2-rx*ry^2;
for(j=0;x2*ry^2>y2*rx^2;j++)
{
if(p2<0)
{
x2=x2;
y2=y2+1;
p2=p2+(2*y2+3)*rx^2;
}
else
{
x2=x2-1;
y2=y2+1;
p2=p2+(2*y2+3)*rx^2-(2*x2-2)*ry^2;
}
putpixel(x2+xc,y2+yc,1);
putpixel(-x2+xc,y2+yc,1);
putpixel(x2+xc,-y2+yc,1);
putpixel(-x2+xc,-y2+yc,1);
}
getch();
}
4. Problem
Generate ellipse using Bresenham’smid point algorithm with center of ellipse (15, 17)
& .
SOLUTION:
Raster Screen:
Result: Thus Bresenham’s mid point ellipse generation technique and its c program is studied.