【问题标题】:Rotate a grid of points in C++在 C++ 中旋转点的网格
【发布时间】:2015-06-20 01:11:17
【问题描述】:

如果我有一个点结构数组定义为

struct Point{

    float x;
    float y;

};

如何将数组中的点旋转给定角度?

举个例子:

任何帮助将不胜感激!

【问题讨论】:

  • 更多的数学问题,但你应该使用rotation matrix
  • @MooseBoys 你能发布一些示例代码吗?

标签: c++ math rotation grid geometry


【解决方案1】:
float x_old = p.x; float y_old = p.y;
p.x = x_old * cos(a) - y_old * sin(a);
p.y = x_old * sin(a) + y_old * cos(a);

当然,如果您将多个点旋转相同的角度,您需要保存 sin & cos,而不是每点计算两次。

【讨论】:

    猜你喜欢
    • 2021-06-23
    • 2021-11-23
    • 2017-03-31
    • 2017-08-10
    • 2015-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    相关资源
    最近更新 更多