【发布时间】:2022-04-07 23:41:15
【问题描述】:
我设计了一个使用方程的圆算法: (x-a)^2+(y-b)^2=r^2
这是一个代码::::
#include<graphics.h>
#include<math.h>
float rety(int x1,int r1,int a1,int b1)
{//function simulates (x-a)^2+(y-b)^2=r^2
float tmp;
tmp=(x1-a1)*(x1-a1);
tmp=(r1*r1)-tmp;
tmp=abs(tmp);
tmp=sqrt(tmp);
tmp=tmp+b1;
return tmp;
}
void main()
{
int tmp2,x=0,y=0,r=50,a=200,b=200,gm=DETECT,gd=DETECT;
initgraph(&gm,&gd,"c://turboc3//bgi");
x=a-r;//set x position as left most point of circle
c1:
y=rety(x,r,a,b);
putpixel(x,y,5);//only draws half circle
tmp2=y-b;
putpixel(x,b-tmp2,5);//draw symmetric to above half circle
x=x+1;
if((x>a+r)==0){goto c1;}
}
输出::::: https://drive.google.com/file/d/0B4kpKF0WrDOQUk9BSm55bjJ0Zm8/view?usp=docslist_api
参考图片,看到圆圈的左右两侧出现虚线。
我只是需要帮助来改进算法,这样那些空白就会被完全填满
提前致谢, 抱歉英语不好。
【问题讨论】: