我已经读了this,我试图用C++来实现它,但输出是完全不同的。我不知道什么是错的。 我使用的代码:将圆划分成n等分来得到每个划分点的坐标
double cordinate_print()
{
int x, y;
int number_of_chunks = 5;
double angle=0;
double x_p[5] ; // number of chunks
double y_p[5]; // number of chunks
//double x0, y0 = radious;
double rad = 150;
for (int i = 0; i < number_of_chunks; i++)
{
angle = i * (360/number_of_chunks);
float degree = (angle * 180/M_PI);
x_p[i] = 0 + rad * cos(degree);
y_p[i] = 0 + rad * sin(degree);
//printf("x-> %d y-> %d \n", x_p[i], y_p[i]);
cout << "x -> " << x_p[i] << "y -> " << y_p[i] << "\n";
}
//printing x and y values
printf("\n \n");
return 0;
}
输出
x -> 150 y -> 0
x -> -139.034 y -> -56.2983
x -> 107.74 y -> 104.365
x -> -60.559 y -> -137.232
x -> 4.77208 y -> 149.924
正确输出
(150,0)
(46,142)
(-121,88)
(-121,-88)
(46,-142)
调用变量“度数”时,实际上以弧度表示的角度会误导人类。不过,编译器并不在乎。不要直接看到问题,但点确实出现在圆上 - 这只是角度错误。 – MSalters