1

我需要遍历给定数量的采样点。这些采样点是表示方向的归一化向量。它们应该在代码中计算出来。从正向向量开始1, 0,我想围绕原点旋转,以便得出给定数量的方向。

for(int i = 0; i < number_of_sampling_points; ++i)
{
    // get direction vector based on i and number_of_sampling_points
    // ...
}

例如, with number_of_sampling_pointsis4在循环内,我想获取值对1, 0, 0, 1, -1, 0, 0, -1。顺序无关紧要。

4

2 回答 2

2

尝试这个:

const double PI = 3.14159265358979323846;
const int number_of_sampling_points = 4;
for (int i = 0; i < number_of_sampling_points; ++i)
{
    const double a = PI * 2 * (1.0 - i) / number_of_sampling_points;

    double x = sin(a);
    double y = cos(a);

    cout << "(" << x << " , " << y << ")" << endl;
}

输出(四舍五入):

(1 , 0)
(0 , 1)
(-1 , 0)
(0 , -1)
于 2013-05-10T10:13:53.247 回答
2

使用触发:

double x = std::cos(pi * 2 * (double)i / (double)number_of_sampling_points);
double y = std::sin(pi * 2 * (double)i / (double)number_of_sampling_points);
于 2013-05-10T10:08:43.700 回答