【计算几何】 HDOJ 4998 Rotate

简单的计算几何。。选一个平面,模拟旋转,然后计算最后的圆心。。。选平面而不选线段的原因是怕线段可能平行造成最后的中垂线重合而解不出圆心。。。选三个不共线的点就可以了。。。

#include <iostream>  
#include <queue>  
#include <stack>  
#include <map>  
#include <set>  
#include <bitset>  
#include <cstdio>  
#include <algorithm>  
#include <cstring>  
#include <climits>  
#include <cstdlib>
#include <cmath>
#include <time.h>
#define maxn 1005
#define maxm 40005
#define eps 1e-10
#define mod 1000000007
#define INF 999999999
#define lowbit(x) (x&(-x))
#define mp mark_pair
#define ls o<<1
#define rs o<<1 | 1
#define lson o<<1, L, mid  
#define rson o<<1 | 1, mid+1, R  
typedef long long LL;
//typedef int LL;
using namespace std;
LL qpow(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base;base=base*base;b/=2;}return res;}
LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}
void scanf(int &__x){__x=0;char __ch=getchar();while(__ch==' '||__ch=='\n')__ch=getchar();while(__ch>='0'&&__ch<='9')__x=__x*10+__ch-'0',__ch = getchar();}
LL gcd(LL _a, LL _b){if(!_b) return _a;else return gcd(_b, _a%_b);}
// head

struct Point
{
	double x, y;
	Point(double x = 0, double y = 0) : x(x), y(y){}
};
typedef Point Vector;
Vector operator + (Vector A, Vector B)
{
	return Vector(A.x + B.x, A.y + B.y);
}
Vector operator - (Point A, Point B)
{
	return Vector(A.x - B.x, A.y - B.y);
}
Vector operator * (Vector A, double p)
{
	return Vector(A.x * p, A.y * p);
}
Vector operator / (Vector A, double p)
{
	return Vector(A.x / p, A.y / p);
}
int dcmp(double x)
{
	if(fabs(x) < eps) return 0;
	else return x < 0 ? -1 : 1;
}
bool operator == (const Point& a, const Point& b)
{
	return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
}
double Dot(Vector A, Vector B)
{
	return A.x * B.x + A.y * B.y;
}
double Length(Vector A)
{
	return sqrt(Dot(A, A));
}
double Angle(Vector A, Vector B)
{
	return acos(Dot(A, B) / Length(A) / Length(B));
}
double Cross(Vector A, Vector B)
{
	return A.x * B.y - A.y * B.x;
}
Vector Rotate(Vector A, double rad)
{
	return Vector(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad));
}
Vector Normal(Vector A)
{
	double L = Length(A);
	return Vector(-A.y / L, A.x / L);
}
Point getpoint(Point P, Vector v, Point Q, Vector w)
{
	Vector u = P - Q;
	double t = Cross(w, u) / Cross(v, w);
	return P + v * t;
}

struct Point a1, b1, c1, a2, b2, c2, tt, k1, k2, k3, ans;
Vector v, v1, v2, v3;
int n;
void work(void)
{
	double t1, t2, t, res;
	scanf("%d", &n);
	a1.x = 1, a1.y = 150;
	b1.x = 150, b1.y = 1;
	c1.x = 150, c1.y = 150;
	a2 = a1, b2 = b1, c2 = c1;
	for(int i = 1; i <= n; i++) {
		scanf("%lf%lf%lf", &t1, &t2, &t);
		tt.x = t1, tt.y = t2;
		v = a2 - tt;
		a2 = Rotate(v, t);
		a2 = a2 + tt;
		
		v = b2 - tt;
		b2 = Rotate(v, t);
		b2 = b2 + tt;
		
		v = c2 - tt;
		c2 = Rotate(v, t);
		c2 = c2 + tt;
	}
	k1 = (a1 + a2) / 2;
	k2 = (b1 + b2) / 2;
	k3 = (c1 + c2) / 2;
	v1 = a1 - a2;
	v2 = b1 - b2;
	v3 = c1 - c2;
	v1 = Normal(v1);
	v2 = Normal(v2);
	v3 = Normal(v3);
	if(v1 == v2) ans = getpoint(k1, v3, k3, v3);
	else ans = getpoint(k1, v1, k2, v2);
	res = (Length(a1 - ans) * Length(a1 - ans) + Length(a2 - ans) * Length(a2 - ans) - Length(a1 - a2) * Length(a1 - a2)) / (2.0 * Length(a1 - ans) * Length(a2 - ans));
	res = acos(res);
	if(Cross(a1 - ans, a2 - ans) < 0) res = 2.0 * acos(-1) - res;
	printf("%.10f %.10f %.10f\n", ans.x, ans.y, res);
}
int main(void)
{
	int _;
	while(scanf("%d", &_)!=EOF) while(_--) work();
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值