0% found this document useful (0 votes)
26 views3 pages

Experiment No.04: Neel Sanjay Bhatt Se Comps-A Roll NO.07

This document summarizes an experiment implementing the midpoint ellipse algorithm. The code first takes radius inputs rx and ry, then initializes graphics mode. It uses two formulas p1 and p2 to iterate through pixels, plotting them to form an ellipse. It plots all four quadrants at once for symmetry. When both while loops finish, it adds axes lines and delays before ending graphics mode. In conclusion, the student successfully studied and implemented the midpoint ellipse algorithm.

Uploaded by

piyush
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)
26 views3 pages

Experiment No.04: Neel Sanjay Bhatt Se Comps-A Roll NO.07

This document summarizes an experiment implementing the midpoint ellipse algorithm. The code first takes radius inputs rx and ry, then initializes graphics mode. It uses two formulas p1 and p2 to iterate through pixels, plotting them to form an ellipse. It plots all four quadrants at once for symmetry. When both while loops finish, it adds axes lines and delays before ending graphics mode. In conclusion, the student successfully studied and implemented the midpoint ellipse algorithm.

Uploaded by

piyush
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/ 3

Neel Sanjay Bhatt

SE COMPS-A
Roll NO.07

EXPERIMENT NO.04

AIM:IMPLEMENTATION OF MIDPOINT ELLIPSE ALGORITHM

CODE:

#include<stdio.h>
#include<graphics.h>

void main()
{
int rx,ry,i,gd=DETECT,gm,dx,dy,x,y;
float p1,p2;
printf("Enter value of rx and ry\n");
scanf("%d%d",&rx,&ry);
x=0;
y=ry;
p1=(float)((ry*ry)-(rx*rx*ry)+0.25*(rx*rx));
dx=2*ry*ry*x;
dy=2*rx*rx*y;
initgraph(&gd,&gm,NULL);
while(dx<dy)
{
putpixel(x+200,-y+200,3);
putpixel(-x+200,-y+200,3);
putpixel(-x+200,y+200,3);
putpixel(x+200,y+200,3);
if(p1<0)
{
x++;
dx+=(2*ry*ry);
p1+=(dx+ry*ry);
}
else
{
x++;
y--;
dx+=(2*ry*ry);
dy-=(2*rx*rx);
p1=p1+(dx-dy+(ry*ry));
}
}
p2=(float)(((ry*ry)*(float)((x+0.5)*(x+0.5)))+((rx*rx)*(y-1)*(y-1))-
((rx*rx)*(ry*ry)));
while(y>=0)
{
putpixel(x+200,-y+200,3);
putpixel(-x+200,-y+200,3);
putpixel(-x+200,y+200,3);
putpixel(x+200,y+200,3);
if(p2>0)
{
y--;
dy=dy+2*rx*rx;
p2=p2+dy+rx*rx;
}
else
{
x++;
y--;
dy=dy-2*rx*rx;
dx=dx+2*ry*ry;
p2=p2+dx-dy+rx*rx;
}
}
for(i=0;i<100;i++)
{
putpixel(i+200,200,1);
putpixel(-i+200,200,2);
putpixel(200,i+200,3);
putpixel(200,-i+200,4);
}
delay(10000);
closegraph();
}

OUTPUT:
CONCLUSION:

Hence, we successfully studied and implemented Midpoint Ellipse Algorithm.

You might also like