题意:一个人要围绕一个点逆时针旋转p1弧度,然后继续围绕下一个点逆时针旋转p2弧度,旋转n次,给出了n个点的坐标和每次旋转的角度,问n次旋转后相当于围绕着哪个点旋转多少弧度,输出它的坐标和度数。弧度不超过2π。
题解:几何题还是要靠公式。。。先总结一个点(x0,y0)围绕圆心(a,b)逆时针旋转p度后的坐标(x,y)的解法。
x = a + (x0 - a) * cos(p) - (y0 - b) * sin(p)y = b + (x0 - a) * sin(p) + (y0 - b) * cos(p)
然后这道题可以先让自己设两个点,旋转n次后得到旋转后的坐标,然后把两个点和对应初始点坐标连线,得到两条线的中垂线的交点就是解,旋转角度就是所有角度之和。
#include <stdio.h>
#include <math.h>
const double pi = acos(-1.0);
int main() {
int t, n;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
double a, b, p;
double x1 = 0, y1 = 0, x2 = 1, y2 = 1, sum = 0;
for (int i = 0; i < n; i++) {
scanf("%lf%lf%lf", &a, &b, &p);
sum += p;
if (sum >= 2 * pi)
sum -= 2 * pi;
double xx1 = a + (x1 - a) * cos(p) - (y1 - b) * sin(p);
double yy1 = b + (x1 - a) * sin(p) + (y1 - b) * cos(p);
double xx2 = a + (x2 - a) * cos(p) - (y2 - b) * sin(p);
double yy2 = b + (x2 - a) * sin(p) + (y2 - b) * cos(p);
x1 = xx1, y1 = yy1, x2 = xx2, y2 = yy2;
}
double k1 = -1.0 / (y1 / x1);
double b1 = y1 / 2 - k1 * x1 / 2;
double k2 = -1.0 / ((y2 - 1) / (x2 - 1));
double b2 = (1 + y2) / 2 - k2 * (1 + x2) / 2;
double y = (b1 * k2 - b2 * k1) / (k2 - k1);
double x = (y - b1) / k1;
printf("%.10lf %.10lf %.10lf\n", x, y, sum);
}
return 0;
}