您的位置:首页 > 其它

hdoj 4998 平面旋转

2015-08-07 10:49 232 查看
hdoj 4998

题意:一个平面绕若干点旋转若干角度后相当于绕某一点旋转某一角度,求这个点和这个角度。

思路:可以根据线代转化为矩阵变换,但是本蒟蒻并不会。。

任选一直线(可以表示为点或向量)模拟旋转,旋转角度就是所有转角的和,之后知道原直线、目标直线、旋转角度,就可以反推旋转公式解个方程得到旋转点了。

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

const double eps = 1e-6;
struct Point {
double x, y;
Point(){}
Point(double a, double b): x(a), y(b){}
void input() {
cin >> x >> y;
}
Point operator -(const Point &a) {
return Point(x - a.x, y - a.y);
}
Point operator +(const Point &a) {
return Point(x + a.x, y + a.y);
}
double length() {
return sqrt(x * x + y * y);
}
};
const double PI = acos(-1.0);
double dot(Point a, Point b) {
return a.x * b.x + a.y * b.y;
}
double det(Point a, Point b) {
return a.x * b.y - a.y * b.x;
}
Point rotate(Point a, double r) {
Point ra(cos(r), sin(r));
return Point(a.x*cos(r)-a.y*sin(r), a.x*sin(r)+a.y*cos(r) );
}
int cmp(double x) {
if(fabs(x) < eps) return 0;
if(x > 0) return 1;
return - 1;
}
int main() {
int t;
cin >> t;
while(t--) {
Point b(0, 0);
int n;
cin >> n;
double sum = 0;
for(int i = 0; i < n; i++) {
Point p;
double angle;
p.input(), cin >> angle;
b = p - rotate(p - b, angle);
sum += angle;
}

while(sum - 2*PI > 1e-6) sum -= 2*PI;
double x, y;
if(cmp(sin(sum)) == 0) {
x = b.x / (1 - cos(sum));
y = b.y / (1 - cos(sum));
}else {
double t = (1 - cos(sum)) / sin(sum);
y = (b.y * t + b.x) / ((1 - cos(sum)) * t + sin(sum));
x = (b.x - y * sin(sum)) / (1 - cos(sum));
}
printf("%.9f %.9f %.9f\n", x, y, sum);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: