- #include <math.h>
- #include <stdio.h>
- // 本函数主要是为了演示中点画圆的描点的方法
- // 这里仅仅打印点的坐标
- //
- void MidpointCircle(int r)
- {
- int x, y;
- float d;
- x = 0;
- y = r;
- d = 1.25-r;
- //打印八个初始点的坐标
- printf("this point is:(%d,%d)\\n", x, y );
- printf("this point is:(%d,%d)\\n", -x, y );
- printf("this point is:(%d,%d)\\n", x, -y );
- printf("this point is:(%d,%d)\\n", -x, -y );
- printf("this point is:(%d,%d)\\n", y, x );
- printf("this point is:(%d,%d)\\n", -y, x );
- printf("this point is:(%d,%d)\\n", y, -x );
- printf("this point is:(%d,%d)\\n", -y, -x );
- while( x <= y)
- {
- if(d < 0)
- {
- d += 2 * x + 3;
- x++;
- }
- else
- {
- d += 2 * (x - y) + 5;
- x++;
- y--;
- }
- //打印点的坐标!
- printf("this point is:(%d,%d)\\n", x, y );
- printf("this point is:(%d,%d)\\n", -x, y );
- printf("this point is:(%d,%d)\\n", x, -y );
- printf("this point is:(%d,%d)\\n", -x, -y );
- printf("this point is:(%d,%d)\\n", y, x );
- printf("this point is:(%d,%d)\\n", -y, x );
- printf("this point is:(%d,%d)\\n", y, -x );
- printf("this point is:(%d,%d)\\n", -y, -x );
- }
- }
- void main()
- {
- MidpointCircle(100);
- system("pause");
- }
- //该片段来自于http://www.codesnippet.cn/detail/111020136348.html
来源: http://www.codesnippet.cn/detail/111020136348.html