This topic has been archived. It cannot be replied.
-
工作学习 / 专业技术讨论 / 一道常见的编程面试题求解, 多谢画圆:
Write a routine to draw a circle given a center coordiante (x,y) and a radius (r) without making use of any floating point computations.
-xm1223(andy);
2007-4-15
{144}
(#3617306@0)
-
not hard though
-wangqingshui(忘情水);
2007-4-16
{631}
(#3617356@0)
-
好像我用过的所有计算机语言里sqrt都是floating 函数
-ccra(ccra);
2007-4-18
(#3622202@0)
-
for sure here we can not use the predefined function sqrt().
-wangqingshui(忘情水);
2007-4-19
(#3622983@0)
-
把屏幕上的每一点都计算(x-x0)^2+(y-y0)^2, 如果值等于r^2画点,如果不是不画。
-ccra(ccra);
2007-4-18
(#3622197@0)
-
You will only draw couple pixels.
-wangqingshui(忘情水);
2007-4-19
(#3622986@0)
-
Not verified yet.for (i = r; i >= 0; i--)
{
for (j = r - i; j <= r; j++)
{
if ((i * i + j * j <= r * r) && ( i * i + (j + 1) * (j + 1) >= r * r ))
{
drawpoint( x - i, y + j);
drawpoint( x + i, y - j);
drawpoint( x - i, y + j);
drawpoint( x + i, y - j);
}
}
}
-exception(违例);
2007-4-18
{295}
(#3622375@0)
-
This is a very good answer.
-wangqingshui(忘情水);
2007-4-20
(#3625648@0)
-
You guys made me laugh. It is a very basic computer graphics concept. Even a non IT guy like me know the answer.
-xtype(xtype);
2007-4-20
(#3625655@0)
-
hehe!!graphic.drawOval(x,y,r);
-arfeifei(老顽童);
2007-4-20
{24}
(#3625672@0)
-
谁叫我今天心情好呢。写CODE我就不会,讲讲原理吧。先画第一象限的1/4。start from (x+r, y)
start from this point to draw the 1/4 circle, the first step should be up,
draw (x+r, y+1), decide this pixel is outside of the circle or inside, by
r*r + 1*1 is bigger than r*r
so the next step is left, draw (x+r-1, 1) decide it is in or out again, if it is in, go up, if it is out, go left until you reach (x, y+r)
now you got the 1/4 circle. Do the same thing four times, you now get your full circle.
-xtype(xtype);
2007-4-20
{439}
(#3625703@0)