1 3 0 0 1 1 1 1 2 2 1
1.8088715944 0.1911284056 3.0000000000
#include <cstdio>
#include <cstring>
#include <cmath>
#define PI 4.0 * atan(1.0)
using namespace std;
struct Move
{
double x, y, p;
}move[15];
int n;
double Dist(double x1, double y1, double x2, double y2) //求两点间距离
{
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
double calx(double x, double y) //求逆时针旋转后的x坐标
{
double x1, y1;
for(int i = 0; i < n; i++)
{
x1 = (x - move[i].x) * cos(move[i].p) - (y - move[i].y) * sin(move[i].p) + move[i].x;
y1 = (x - move[i].x) * sin(move[i].p) + (y - move[i].y) * cos(move[i].p) + move[i].y;
x = x1;
y = y1;
}
return x1;
}
double caly(double x, double y) //求逆时针旋转后的y坐标
{
double x1, y1;
for(int i = 0; i < n; i++)
{
x1 = (x - move[i].x) * cos(move[i].p) - (y - move[i].y) * sin(move[i].p) + move[i].x;
y1 = (x - move[i].x) * sin(move[i].p) + (y - move[i].y) * cos(move[i].p) + move[i].y;
x = x1;
y = y1;
}
return y1;
}
int main()
{
int ca;
scanf("%d", &ca);
while(ca--)
{
scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%lf %lf %lf", &move[i].x, &move[i].y, &move[i].p);
//任意取两个点
double x1 = 34.11111111;
double y1 = 1.4211111111;
double x3 = 42.3111111111;
double y3 = 2.32111111111;
//求出这两个点逆时针旋转后的两个点
double x2 = calx(x1, y1);
double y2 = caly(x1, y1);
double x4 = calx(x3, y3);
double y4 = caly(x3, y3);
//通过y = kx + b;联立解得两垂直平分线的交点
double x = ((y1 + y2 - y3 - y4) * (y1 - y2) * (y3 - y4) + (x4 * x4 - x3 * x3) * (y1 - y2) - (x2 * x2 - x1 * x1) * (y3 - y4))
/ (2 * (x4 - x3) * (y1 - y2) - 2 * (x2 - x1) * (y3 - y4));
double y = (((x2 - x1) / (y1 - y2)) * (x - (x1 + x2) / 2) + (y1 + y2) / 2);
//圆的半径
double r = Dist(x, y, x1, y1);
//某两个对应点的距离
double dist = Dist(x1, y1, x2, y2);
//通过三角函数关系求出弧度
double angel = 2 * asin(dist / (2 * r));
//通过向量叉乘确定方向
double d1 = (x1 - x) * (y2 - y) - (x2 - x) * (y1 - y);
//方向判定
if(d1 < 0)
angel = 2 * PI - angel;
//精度特判
if(fabs(x) < 1e-10)
x = 0;
if(fabs(y) < 1e-10)
y = 0;
printf("%.10f %.10f %.10f\n", x, y, angel);
}
}原文:http://blog.csdn.net/tc_to_top/article/details/39257247