您的位置:首页 > 其它

hdu 4998 Rotate(几何)

2014-09-17 22:23 330 查看
题目链接:hdu 4998 Rotate

题目大意:给定n次旋转,每次旋转给定旋转中心和角度,问说n次旋转的等价旋转,包括中心和角度。

解题思路:根据旋转的公式:
x′=(x−rx)∗cos(r)−(y−ry)∗sin(r)+rx
y′=(x−rx)∗sin(r)+(y−ry)∗cos(r)+ry

假设起始点(0,0),经过n次旋转后得到(x',y')然后根据公式去求x,y。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

const double pi = 4 * atan(1.0);

struct point {
double x, y;
point (double x = 0, double y = 0) {
this->x = x;
this->y = y;
}
point rotate (double rx, double ry, double r) {
double x0 = (x - rx) * cos(r) - (y - ry) * sin(r) + rx;
double y0 = (x - rx) * sin(r) + (y - ry) * cos(r) + ry;
return point(x0, y0);
}
};

int main () {
int cas, n;
scanf("%d", &cas);
while (cas--) {
double R = 0, x, y, r;
scanf("%d", &n);

point S;
while (n--) {
scanf("%lf%lf%lf", &x, &y, &r);
R += r;

if (R >= 2 * pi)
R -= 2 * pi;
S = S.rotate(x, y, r);
}

double a = 1 - cos(R), b = sin(R);

double xx = (a * S.x - b * S.y) / (a * a + b * b);
double yy = (a * S.y + b * S.x) / (a * a + b * b);
printf("%.10lf %.10lf %.10lf\n", xx, yy, R);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: