小编use*_*774的帖子

将cos和sin存储到向量中并获得奇怪的值

我的代码

double to_radians(double theta)
{
    return (M_PI * theta) / 180.0;
}

int main()
{
    std::vector<std::pair<double, double>> points;
    for (double theta = 0.0; theta <= 360.0; theta += 30.0)
    {
        points.push_back(std::make_pair(std::cos(to_radians(theta)), std::sin(to_radians(theta))));
    }
    for (auto point : points)
        std::cout << point.first << " " << point.second << "\n";
}
Run Code Online (Sandbox Code Playgroud)

我希望输出

1 0
0.866025 0.5
0.5 0.866025
0 1
-0.5 0.866025
-0.866025 0.5
-1 0
-0.866025 -0.5
-0.5 -0.866025
0 -1
0.5 -0.866025
0.866025 -0.5
1 0

输出我得到:

1 0
0.866025 …

c++ floating-point

1
推荐指数
1
解决办法
315
查看次数

标签 统计

c++ ×1

floating-point ×1