ABC-259B Counterclockwise Rotation讲解

题目大意: 输入点的坐标,和需要旋转的角度,输出旋转后的点的坐标

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的值) = 弧度

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值