-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mid_point_elipse_drawing_algorithm.cpp
91 lines (89 loc) · 2.31 KB
/
Mid_point_elipse_drawing_algorithm.cpp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
Parmar Fenil Milankumar
Information & Technology
Vishwakarma Goverment Engineering College
*/
#include<iostream>
#include<graphics.h>
using namespace std;
int main()
{
int rx,ry;
cout<<"Enter Radius :\n";
cout<<"Rx=";
cin>>rx;
cout<<"Ry=";
cin>>ry;
int xc,yc;
cout<<"Enter Center Point: ";
cin>>xc>>yc;
int po=(ry*ry)-((rx*rx)*ry)+((rx*rx)/4);
int x=0,y=ry;
if(rx<0 ||ry<0 || (xc+rx)>800 ||(yc+ry)>800 ||(yc-ry)<0 || (xc-rx)<0)
{
cout<<"Error:Enter Right Value For Radius Or Center Points.\n(1)May be you entered negative or zero value for radius! \n(2)May be your combination of center points and radius leads circle outside of our window!\n";
main();
}
else
{
initwindow(800,800);
putpixel(xc,yc,15);
putpixel(xc+x,yc+y,15);
putpixel(xc+x,yc-y,15);
putpixel(xc+rx,yc+x,15);
putpixel(xc-rx,yc+x,15);
while((ry*ry*x)<(rx*rx*y))
{
if(po<0)
{
x=x+1;
po=po+(2*x*ry*ry)+(ry*ry);
//cout<<"Dicision Parameter:"<<po<<"x="<<x<<" y="<<y<<endl;
}
else
{
x=x+1;
y=y-1;
po=po+(2*x*ry*ry)+(ry*ry)-(2*y*rx*rx);
//cout<<"Dicision Parameter:"<<po<<"x="<<x<<" y="<<y<<endl;
}
/*We only have to find for one octant then there are all similar , so we just have to put pixels of other 7 octants.*/
putpixel(xc+x,yc+y,15);
// putpixel(xc+y,yc+x,15);
putpixel((xc-x),(yc-y),15);
// putpixel((xc-y),(yc-x),15);
putpixel(xc-x,(yc+y),15);
// putpixel(xc-y,(yc+x),15);
putpixel(xc+x,(yc-y),15);
// putpixel((xc+y),yc-x,15);
}
po=((ry*ry)*(x+(1/2))*(x+(1/2)))+((rx*rx)*(y-1)*(y-1))-(rx*rx*ry*ry);
while(y>=0)
{
if(po>0)
{
y=y-1;
po=po-(2*rx*rx*y)+(rx*rx);
//cout<<"Dicision Parameter:"<<po<<"x="<<x<<" y="<<y<<endl;
}
else
{
x=x+1;
y=y-1;
po=po+(2*ry*ry*x)-(2*rx*rx*y)+(rx*rx);
//cout<<"Dicision Parameter:"<<po<<"x="<<x<<" y="<<y<<endl;
}
/*We only have to find for one octant then there are all similar , so we just have to put pixels of other 7 octants.*/
putpixel(xc+x,yc+y,15);
//putpixel(xc+y,yc+x,15);
putpixel((xc-x),(yc-y),15);
// putpixel((xc-y),(yc-x),15);
putpixel(xc-x,(yc+y),15);
// putpixel(xc-y,(yc+x),15);
putpixel(xc+x,(yc-y),15);
// putpixel((xc+y),yc-x,15);
}
}
getch();
return 0;
}