几何题单点旋转

单点旋转 单点旋转 单点旋转


#define db double
const db PI=acos(-1);
db theta = 顺时针度数/180 * PI;
struct P{
db x, y;
P(db _x, db _y):x(_x), y(_y){}
};
inline P turn_PP(P a,P b,db theta){
	//将点A绕点B顺时针旋转theta(弧度)
	//逆时针的话就是 theta = 2*PI - theta;
    db x=(a.x-b.x)*cos(theta)+(a.y-b.y)*sin(theta)+b.x;
    db y=-(a.x-b.x)*sin(theta)+(a.y-b.y)*cos(theta)+b.y;
    return P(x,y);
}
绕原点旋转相当于
[x, y] * [cos$, -sin$]
		 [sin$,  cos$]

你可能感兴趣的:(数学,python,算法,机器学习)