📅  最后修改于: 2020-12-20 09:36:24             🧑  作者: Mango
椭圆具有长轴和短轴。如果a 1和b 1分别是长轴和短轴。椭圆的中心是(i,j)。 x的值将从i递增到1 ,y的值将使用以下公式计算
1.设置初始变量:a =主轴长度; b =短轴长度; (h,k)=椭圆中心的坐标; x = 0; i =步骤; x末端= a。
2.测试以确定整个椭圆是否已被扫描转换。如果x> x end ,停止。
3.计算y坐标的值:
4.在当前(x,y)坐标上绘制对称找到的四个点:
图(x + h,y + k)图(-x + h,-y + k)图(-y-h,x + k)图(y + h,-x + k)
5.增量x; x = x + i。
6.转到步骤2。
#include
#include
#include
#include
#include
#include
class bresen
{
float x, y, a, b, r, t, te, xend, h, k, step;
public:
void get ();
void cal ();
};
void main ()
{
bresen b;
b.get ();
b.cal ();
getch ();
}
void bresen :: get ()
{
cout<<"\n ENTER CENTER OF ELLIPSE";
cout<<"\n enter (h, k) ";
cin>>h>>k;
cout<<"\n ENTER LENGTH OF MAJOR AND MINOR AXIS";
cin>>a>>b;
cout<<"\n ENTER Step Size";
cin>> step;
}
void bresen ::cal ()
{
/* request auto detection */
int gdriver = DETECT,gmode, errorcode;
int midx, midy, i;
/* initialize graphics and local variables */
initgraph (&gdriver, &gmode, " ");
/* read result of initialization */
errorcode = graphresult ();
if (errorcode ! = grOK) /*an error occurred */
{
printf("Graphics error: %s \n", grapherrormsg (errorcode);
printf ("Press any key to halt:");
getch ();
exit (1); /* terminate with an error code */
}
x = 0;
xend=a;
whilex (x
输出: