hdu 4998 Rotate(計算幾何)

2021-07-05 03:17:03 字數 1361 閱讀 7302

解題思路:

題目大意:給定n個點和n個角度,平面內任意乙個點依次以這些點point(i)為旋轉中心,逆時針旋轉 r(i)度,求最後相當於繞哪個點旋轉多少度,求這個點的座標以及旋轉的角度。

演算法思想:

乙個點(x,y)繞另外乙個點(x0,y0)旋轉 r0 度的公式為:

x1= (x - x0)*cos(r0) - (y - y0)*sin(r0)  + x0 ;

y1= (x - x0)*sin(r0) + (y - y0)*cos(r0) + y0 ;

最後旋轉點肯定是xx,tmp1的垂直平分線以及由yy,tmp2的垂直平分線的交點,旋轉角度rad = (r1+r2+.....+rn)%(2*pi)。

最後直接套模板即可。。。

ac**:

#include #include #include #include using namespace std;

const double eps = 1e-5;

const double pi = acos(-1.0);

struct point // 建構函式,方便**編寫

};typedef point vector;

vector operator + (vector a,vector b)

vector operator - (vector a,vector b)

vector operator * (vector a,double p)

vector operator / (vector a,double p)

double dot(vector a,vector b)

double length(vector a)

double cross(vector a,vector b)

vector rotate(vector a,double rad)

vector normal(vector a)

point getlineintersection(point p,vector v,point q,vector w)

int main()

point tt1 = (xx+tmp1)/2, tt2 = (yy+tmp2)/2;

vector v1,v2;

v1 = normal(tmp1-xx);v2 = normal(tmp2-yy);

point ans = getlineintersection(tt1,v1,tt2,v2);

while(rad > 2*pi)

rad -= 2*pi;

printf("%.10lf %.10lf %.10lf\n",ans.x,ans.y,rad);

}return 0;

}

hdu 4998 矩陣表示旋轉

乙個旋轉變換可以轉化為乙個三維矩陣的變化 繞 x,y 旋轉角度r,執行十次,求等價旋轉點和角度 繞原點矩陣如下 由於是繞 x,y x1 x x0 cos0 y y0 sin0 x0 y1同理,那麼第三行前兩列即為x0 1 cos r y0 sin r 和y0 1 cos r x0 sin r 最後根...

hdu 2688 Rotate 樹狀陣列

include include include include include using namespace std define lowbit x x x const int maxn 3000030 const int maxc 10010 int n,c maxc a maxn void a...

hdu 2688 Rotate 樹狀陣列

題目連線 hdu 2688 rotate 題意 給你n數,n 3e6 有兩個操作,q為 當前有多少對數,滿足嚴格遞增,r l,r為旋轉l,r這個區間的數 題解 求嚴格遞增的順序對我們可以反向用樹狀陣列求逆序對,300w的資料還是有點夠嗆,不過這裡求出來也就nlogn,然後對於旋轉操作,因為區間大小不...