注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
准备面经,发现有一道draw circle, 神秘兮兮地说不允许用乘法,找到了一个Blog介绍了生成圆的算法
http://blog.csdn.net/orbit/article/details/7253285
但是第4项的quick draw algorithm真的不太懂理论依据,现贴出来,希望哪位大神提点一下!谢谢- //Center of circle: (xc,yc)
- //radius: r
- void Fast_Circle(int xc, int yc, int r)
- {
- int x, y, d;
- x = 0;
- y = r;
- d = -r / 2;
- CirclePlot(xc, yc, x, y); //Put into result set.
- if (r % 2 == 0)
- {
- while (x < y)
- {
- x++;
- if (d < 0)
- d += x;
- else
- {
- y--;
- d += x - y;
- }
- CirclePlot(xc, yc, x, y);
- }
- }
- else
- {
- while (x < y)
- {
- x++;
- if (d < 0)
- d += x + 1;
- else
- {
- y--;
- d += x - y + 1;
- }
- CirclePlot(xc, yc, x, y); //Put into result set.
- }
- }
- }
复制代码 |