题目大意: 输入点的坐标,和需要旋转的角度,输出旋转后的点的坐标
Start:
实现方法:得到这个点距离x正半轴的弧度,和旋转的度数的弧度,相加,得到旋转后的弧度。然后用斜边成这个度数的cos值和sin值,得到最终的坐标。
代码:
#include<bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
double x, y, d, res_x, res_y;
int main(){
cin >> x >> y >> d;
if(x == 0 && y == 0){
cout<<fixed<<setprecision(20)<<x<<" "<<y<<endl;
return 0;
}
d = d * PI / 180;
double r = sqrt(x * x + y * y);
//cos(ans) = x / r
double ans = acos(x / r);
if(y < 0) ans = 2 * PI - ans;
//cos = x / r; sin = y / r
res_x = r * cos(d + ans);
res_y = r * sin(d + ans);
cout<<fixed<<setprecision(20)<<res_x<<" "<<res_y<<endl;
return 0;
}
需要注意:
Pi = arccos(-1, 0)
角度转换为弧度:/180 * PI
cos(弧度) = cos的值
arccos(cos的值) = 弧度