我想在 C++ 中使用 graphics.h 画一个圆,但不是直接使用 circle() 函数。我要绘制的圆圈使用较小的圆圈作为它的点,即较小的圆圈将构成较大圆圈的圆周。所以我想,如果我做这样的事情,它会起作用:
{
int radius = 4;
// Points at which smaller circles would be drawn
int x, y;
int maxx = getmaxx();
int maxy = getmaxy();
// Co-ordinates of center of the larger circle (centre of the screen)
int h = maxx/2;
int k = maxy/2;
//Cartesian cirle formula >> (X-h)^2 + (Y-k)^2 = radius^2
//Effectively, this nested loop goes through every single coordinate on the screen
int gmode = DETECT;
int gdriver;
initgraph(&gmode, &gdriver, "");
for(x = 0; x<maxx; x++)
{
for(y = 0; y<maxy; y++)
{
if((((x-h)*(x-h)) + ((y-k)*(y-k))) == (radius*radius))
{
circle(x, y, 5) //Draw smaller circle with radius 5
} //at points which satisfy circle equation only!
}
}
getch();
}
这是我在 Turbo C++ 上使用 graphics.h 的时候,因为这是我们在学校学习的编译器。
我知道它很古老。
所以,理论上,由于嵌套的 for 循环检查屏幕上的所有点,并在每个点上画一个只满足圆方程的小圆,我想我会得到一个大半径圆,其周长构成我在 for 循环中制作的小圆圈。
然而,当我尝试这个程序时,我得到了四个双曲线(都指向屏幕的中心),当我增加半径时,双曲线的尖度(因为没有更好的词)增加,直到最后,当半径是 256 或更多,上下两条双曲线相交在我的屏幕上形成一个大十字:“就是这样,用户,我放弃了!”
我发现值是 256,因为我注意到半径是 4 的倍数,这些数字看起来……更好?
我四处寻找解决方案很长一段时间,但无法得到任何答案,所以我在这里。
有什么建议么???
编辑>>这是我得到的输出的粗略图......