## HDOJ 4998 Rotate（求直线交点、绕定点旋转）

2019年02月12日 ⁄ 综合 ⁄ 共 1573字 ⁄ 字号 评论关闭

```#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

const int maxn = 15;
const double pi = acos(-1.0);

typedef struct Point
{
double x, y, p;

Point(double _x = 0, double _y = 0, double _p = 0):
x(_x), y(_y), p(_p) {}

Point operator +(Point argu)
{
return Point(x + argu.x, y + argu.y);
}

Point operator -(Point argu)
{
return Point(x - argu.x, y - argu.y);
}

double operator ^(Point argu)
{
return x * argu.y - y * argu.x;
}

Point operator *(double k)
{
return Point(x * k, y * k);
}

Point operator /(double k)
{
return Point(x / k, y / k);
}

Point rotate(Point argu)
{
Point r = argu - (*this);
return Point(x + r.x * cos(p) - r.y * sin(p), y + r.x * sin(p) + r.y * cos(p));
}

void push(double nx, double ny)
{
x = nx;
y = ny;
}

void in(void)
{
scanf("%lf%lf%lf", &x, &y, &p);
}
void out(void)
{
printf("%.10lf %.10lf ", x, y);
}
}Vector;

Point pp[maxn];
Point reala, realb, stana, stanb;
Point mida, midb;
Vector va, vb;
double xa = 10010, ya = 10010, xb = 10010, yb = 10020;

Point get_center(Point p, Vector v, Point q, Vector w)
{
Vector u = p - q;
double t = (w ^ u) / (v ^ w);
return (p + (v * t));
}

int main()
{
//freopen("1002.in", "r", stdin);

stana.push(xa, ya);
stanb.push(xb, yb);
int t;
scanf("%d", &t);
while(t--)
{
int n;
double ang = 0.0;
scanf("%d", &n);
reala.push(xa, ya);
realb.push(xb, yb);
for(int i = 0; i < n; i++)
{
pp[i].in();
ang += pp[i].p;
}
ang = fmod(ang, 2.0 * pi);
for(int i = 0; i < n; i++)
{
reala = pp[i].rotate(reala);
realb = pp[i].rotate(realb);
}
mida = (stana + reala) / 2;
midb = (stanb + realb) / 2;

Vector va = Point(reala.y - stana.y, stana.x - reala.x);
Vector vb = Point(realb.y - stanb.y, stanb.x - realb.x);
Point c = get_center(mida, va, midb, vb);

if(ang)
{
c.out();
printf("%.10lf\n", ang);
}
else
printf("%.10lf %.10lf %.10lf\n", 0.0, 0.0, 0.0);
}
return 0;
}
```