📅  最后修改于: 2020-12-20 09:32:15             🧑  作者: Mango
定义圆的第二种方法利用极坐标,如图所示:
x = r cosθy = r sinθ
=="" =圆半径
x="x坐标
y" p="" y坐标<="" θ="当前角度
r">
步骤1:设置初始变量:
r =圆半径
(h,k)=圆心坐标
i >
="" =步长
θ_end="
步骤2:如果θ>θ结束,则停止。
第三步:计算
步骤4:在当前(x,y)坐标上绘制对称找到的八个点,即中心(h,k)。
绘图(x + h,y + k)绘图(-x + h,-y + k)
绘图(y +="" h,-x="" h,-y="" h,x="" h,y="" k)<="" k)
绘图(-x="" k)
绘图(-y="" k)绘图(-y="" k)绘图(x="" k)绘图(y="" p="">
步骤5:递增θ=θ+ i
步骤6:转到步骤(ii)。
#include
#include
#define color 10
void eightWaySymmetricPlot(int xc,int yc,int x,int y)
{
putpixel(x+xc,y+yc,color);
putpixel(x+xc,-y+yc,color);
putpixel(-x+xc,-y+yc,color);
putpixel(-x+xc,y+yc,color);
putpixel(y+xc,x+yc,color);
putpixel(y+xc,-x+yc,color);
putpixel(-y+xc,-x+yc,color);
putpixel(-y+xc,x+yc,color);
}
void PolarCircle(int xc,int yc,int r)
{
int x,y,d;
x=0;
y=r;
d=3-2*r;
eightWaySymmetricPlot(xc,yc,x,y);
while(x<=y)
{
if(d<=0)
{
d=d+4*x+6;
}
else
{
d=d+4*x-4*y+10;
y=y-1;
}
x=x+1;
eightWaySymmetricPlot(xc,yc,x,y);
}
}
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
int xc,yc,r;
initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
printf("Enter the values of xc and yc ,that is center points of circle : ");
scanf("%d%d",&xc,&yc);
printf("Enter the radius of circle : ");
scanf("%d",&r);
PolarCircle(xc,yc,r);
getch();
closegraph();
return 0;
}
输出:
绘图(y>(h,k)=圆心坐标