谁能讲解一下图形法画圆中参数的数学意义
图形法画圆中需要设定一个参数如下 p,但是不了解其数学意义(即如何给出其初值,又如何有那样的变化) 谁能讲解一下谢谢!#include <stdio.h>
#include <graphics.h>
#include <dos.h>
/*这是根据给出的圆心坐标和点坐标分别在八个象限画点的子程序*/
void circlePoint( int xCenter, int yCenter, int x, int y )
{
putpixel( xCenter + x, yCenter + y, YELLOW );
putpixel( xCenter - x, yCenter + y, YELLOW );
putpixel( xCenter + x, yCenter - y, YELLOW );
putpixel( xCenter - x, yCenter - y, YELLOW );
putpixel( xCenter + y, yCenter + x, YELLOW );
putpixel( xCenter - y, yCenter + x, YELLOW );
putpixel( xCenter + y, yCenter - x, YELLOW );
putpixel( xCenter - y, yCenter - x, YELLOW );
}
void myCircle(int xCenter,int yCenter,int radius)
{
int x, y, p;
/*初始化各个参数*/
x = 0;
y = radius;
p = 1 - radius;
circlePoint(xCenter, yCenter, x, y);
/*循环中计算圆上的各点坐标*/
while( x < y ) {
x++;
if( p < 0 )
p += 2*x+1;
else
{
y--;
p+=2*(x-y)+1;
}
circlePoint( xCenter, yCenter, x, y);
}
}
void main()
{
int gdriver=DETECT, gmode; /*这是用c画图时必须要使用的图像入口*/
int i;
int xCenter, yCenter, radius;
printf("Please input center coordinate :(x,y) ");
scanf("%d,%d", &xCenter, &yCenter );
printf("Please input radius : ");
scanf("%d", &radius );
/*这条语句初始化整个屏幕并把入口传给gdriver,注意引号中是tc中bgi目录的完整路径*/
registerbgidriver(EGAVGA_driver);
initgraph(&gdriver, &gmode, "..\\bgi");
setcolor( BLUE );
myCircle(xCenter, yCenter, radius);
sleep(3);
closegraph();
return;
}
[[it] 本帖最后由 llp108 于 2008-10-4 17:53 编辑 [/it]]