我想绕原点旋转一个点,但我不断收到错误消息。数学部分是可靠的,但是当我希望它从特定点更新x和y值时,代码似乎失败了。你们可以帮我吗?
亲切的问候,文森特
#include <cmath>
#include <iostream>
#include <iomanip>
class Point
{
public:
double x, y;
// constructors
Point()
: x(0), y(0)
{}
Point(double X, double Y)
: x(X), y(Y)
{}
double roa(double angle)
{
double new_x = x*cos(angle) - y*sin(angle);
double new_y = x*sin(angle) + y*sin(angle);
x = x_new;
y = y_new;
return Point(x,y);
}
};
int main()
{
Point a(2,2);
a = a.roa(50);
std::cout << a << std::endl;
return 0
}
文档说,角度以弧度为单位:http://www.cplusplus.com/reference/cmath/cos/