为什么我的程序的轴偏离了

Why is the axis for my program off

本文关键字:我的 程序 为什么      更新时间:2023-10-16
    //============================================================================
// Name        : Assignment.cpp
// Author      : Tim Bialecki
// Version     :
//============================================================================
#include <iostream>
#include <math.h>
using namespace std;
void circle(int x, int y, int radius);
void line(int a, int b, int c, int d);
bool buffer[26][81];
char drawSpace[26][81];
int main() {
    int a = 75;
    int b = 5;
    int c = 4;
    int d = 26;
    /*cout << "please enter an x coordinate for the center of the circle";
    cin >> x;
    cout << "please enter a y coordinate for the center of the circle";
    cin >> y;
    cout << "please enter a value for the radius of the circle";
    cin >> radius;*/
    circle(a, b, c);
    for (int col = 80; col >= 0; col--) {
        for (int row = 25; row >= 0; row--) {
                cout << drawSpace[row][col];
            }
        cout << "n";
        }
    return 0;
}
void circle(int x, int y, int radius){
    /*if (x + radius >= 81 || y + radius >= 26 || y - radius <= 26){
        cout << "the coordinates provided for the circle will not fit on the screen" << endl;
        return;
    }*/
    for (int i = 0; i < 26; i++) {
        for(int j = 0; j < 81; j++) {
            int a = abs (x - j);
            int b = abs (y - i);
            int distance =  pow(a, 2) + pow(b, 2);
            int realDistance = pow(radius, 2);
            if (abs(realDistance - distance) <= 3){
                buffer[i][j] = true;
            }
        }
    }
    for (int m = 0; m < 26; m++){
        for(int n = 0; n < 81; n++){
            if (buffer[m][n]){
                drawSpace[m][n] = 42;
            }
            else
                drawSpace[m][n] = 32;
        }
    }
}
void line(int a, int b, int c, int d){
    int intercept = 0;
    double rise = d - b;
    double run = c - a;
    double slope = rise/run;
    intercept = b - (slope*a);
    for (int i = 0; i < 26; i++) {
        for(int j = 0; j < 81; j++) {
            int newIntercept = i - (slope*j);
            int test = abs (intercept - newIntercept);
            if (test <= 0)
                buffer[i][j] = true;
            else
                buffer[i][j] = false;
        }
    }
    for (int m = 0; m < 26; m++){
        for(int n = 0; n < 81; n++){
            if (buffer[m][n])
                drawSpace[m][n] = 42;
            else
                drawSpace[m][n] = 32;
        }
    }
}

这段代码是一个正在进行的工作,但我试图写一个程序,输入直线和圆的坐标和尺寸,并在终端窗口中将它们打印出来,就好像它是一个81x26的图形一样。我刚刚提供了样本输入来测试这一点,但由于某种原因,形状没有以适当的方向打印到应该是x轴和y轴的方向。我已经尝试了很多不同的方法来解决这个问题,但都没有运气。希望有人能帮忙。由于

看起来不错:

               ***    
             **   **  
             *     *  
            *       * 
            *       * 
            *       * 
             *     *  
             **   **  
               ***    

它不是完美的圆形,因为字符的高大于宽。

编辑:这只是我输出的前几行。根据注释和再次查看代码,我认为行和列混淆了。

 for (int col = 80; col >= 0; col--) {
    for (int row = 25; row >= 0; row--) {
            cout << drawSpace[row][col];
        }
    cout << "n";
    }

每个"column"后面都有一个换行符。交换两个for行可能会产生您想要的结果。

相关文章: