-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmid point ellipse.cpp
More file actions
68 lines (65 loc) · 980 Bytes
/
mid point ellipse.cpp
File metadata and controls
68 lines (65 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void disp(float x, float y, int xc, int yc)
{
putpixel(xc+x,yc+y,10);
putpixel(xc-x,yc+y,10);
putpixel(xc+x,yc-y,10);
putpixel(xc-x,yc-y,10);
}
int main()
{
int gd=DETECT,gm;
int rx,ry;
float x,y;
int xc,yc;
float p1,p2;
printf("Enter the center point :");
scanf("%d%d",&xc,&yc);
printf("Enter the value for Rx and Ry :");
scanf("%d%d",&rx,&ry);
initgraph(&gd,&gm, "");
x=0;
y=ry;
disp(x,y,xc,yc);
p1=(ry*ry)-(rx*rx*ry)+(rx*rx)/4;
while((2.0*ry*ry*x)<=(2.0*rx*rx*y))
{
x++;
if(p1<=0)
p1=p1+(2.0*ry*ry*x)+(ry*ry);
else
{
y--;
p1=p1+(2.0*ry*ry*x)-(2.0*rx*rx*y)+(ry*ry);
}
disp(x,y,xc,yc);
x=-x;
disp(x,y,xc,yc);
x=-x;
}
x=rx;
y=0;
disp(x,y,xc,yc);
p2=(rx*rx)+2.0*(ry*ry*rx)+(ry*ry)/4;
while((2.0*ry*ry*x)>(2.0*rx*rx*y))
{
y++;
if(p2>0)
p2=p2+(rx*rx)-(2.0*rx*rx*y);
else
{
x--;
p2=p2+(2.0*ry*ry*x)-(2.0*rx*rx*y)+(rx*rx);
}
disp(x,y,xc,yc);
y=-y;
disp(x,y,xc,yc);
y=-y;
}
getch();
closegraph();
return 0;
}