我试图理解如何在不使用库函数的情况下绘制一组形成圆的点(/设置像素).
现在,获得给定半径的点的(x,y)坐标是直截了当的.
for (x=-r; x <r; x=x+0.1) {
y = sqrt(r*r - x*x);
draw(x,y, 0, 0);
}
Run Code Online (Sandbox Code Playgroud)
但是,一旦我得到了积分,你如何真正画圆圈就是令我困惑的事情.我可以使用图形库,但我想了解如何在不使用图形库的情况下完成它
void draw(float x, float y, float center_x, float center_y) {
//logic to set pixel given x, y and circle's center_x and center_y
// basically print x and y on the screen say print as a dot .
// u 'd need some sort of a 2d char array but how do you translate x and y
// to pixel positions
}
Run Code Online (Sandbox Code Playgroud)
有人可以分享任何链接/参考或解释这是如何工作的?
char display[80][26];
void clearDisplay(void) {
memset(display, ' ', sizeof(display));
}
void printDisplay(void) {
for (short row=0; row<26; row++) {
for (short col=0; col<80; col++) {
printf("%c", display[col][row]);
}
printf("\n");
}
}
void draw(float x, float y, float center_x, float center_y) {
if (visible(x,y)) {
display[normalize(x)][normalize(y)] = '.';
}
}
Run Code Online (Sandbox Code Playgroud)
EDITH: 你改变了你的评论,加入了更多你的问题,所以我会稍微扩展我的答案.
你有两组坐标:
您需要一个指标,将您的世界坐标转换为显示坐标.为了使事情变得更复杂,你需要一个窗口(你想向用户显示的世界的一部分)来剪辑你无法展示的东西(比如非洲,当你想展示欧洲时).您可能想要缩放世界坐标以匹配您的显示坐标(您想要显示多少欧洲)
这些指标和剪报是简单的代数转换
等等.只是维基百科"alegebraic transformation"或"geometrics"