标签:计算几何
BCA‘
,我们可以知道,这个三角形的三条边分别为BC,AD,2*EF
,也就是说这个三角形是确定的。我们从这里入手,先确定BC
两点的坐标(任意即可),然后以B
为圆心做一个半径为2EF
的圆,以C
为圆心做一个长度为DA
的圆。这样我们就确定了A‘
。再根据A‘
来确定G
点的坐标。然后以G
为圆心,做一个半径为AB
的圆,以C
为圆心,确定长度为CD
的圆。这两圆的交点为D
。然后A
也可以求出来了。HDU5295
/*************************************************************************
> File Name: main.cpp
> Author: znl1087
> Mail: loveCJNforever@gmail.com
> Created Time: 日 8/ 9 13:33:25 2015
************************************************************************/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1.5e-6;
struct Point{
double x,y;
Point(){}
Point(double x,double y):x(x),y(y){}
};
typedef Point Vec;
int dcmp(double x){
if(fabs(x) < EPS) return 0; else return x < 0 ? -1: 1;
}
Vec operator + (Vec a,Vec b){return Vec(a.x + b.x, a.y + b.y);}
Vec operator - (Vec a,Vec b){return Vec(a.x - b.x, a.y - b.y);}
Vec operator * (Vec a,double p){return Vec(a.x * p,a.y * p);}
Vec operator / (Vec a,double p){return Vec(a.x / p,a.y / p);}
bool operator == (const Point& a,const Point& b){
return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y)==0;
}
double angle(Vec v){return atan2(v.y,v.x);}
double Dot(Vec a,Vec b){return a.x * b.x + a.y * b.y;}
double Length(Vec a){return sqrt(Dot(a,a));}
double Angle(Vec a,Vec b){return acos(Dot(a,b)/Length(a)/Length(b));}
double Cross(Vec a,Vec b){return a.x * b.y - a.y * b.x;}
struct Circle{
Point c;
double r;
Circle(){}
Circle(Point c,double r):c(c),r(r){}
Point point(double a){
return Point(c.x + cos(a) * r , c.y + sin(a) * r);
}
};
int getCircleCircleIntersection(Circle C1,Circle C2,vector<Point>& sol){
double d = Length(C1.c - C2.c);
if( dcmp(C1.r - C2.r)>0)
swap(C1,C2);
if(dcmp(d) == 0){
if(dcmp(C1.r - C2.r)==0){
sol.push_back(C1.c + Vec(0,C1.r));
sol.push_back(C1.c - Vec(0,C1.r));
return 2;
}
return 0;
}
if(dcmp(C1.r + C2.r - d) < 0) return 0;
if(dcmp(fabs(C1.r - C2.r)-d) > 0)return 0;
if(dcmp(C1.r + C2.r - d) == 0 || dcmp(fabs(C1.r - C2.r)-d) == 0){
Vec p = C1.c-C2.c;
sol.push_back(C2.c + p / Length(p) * C2.r);
return 1;
}
double a = angle(C2.c - C1.c);
double da = acos((C1.r * C1.r + d * d - C2.r * C2.r) / (2 * C1.r * d));
Point p1 = C1.point(a-da),p2 = C1.point(a+da);
sol.push_back(p1);
if(p1 == p2)return 1;
sol.push_back(p2);
return 2;
}
double AB,BC,CD,DA,EF;
int main(){
int T;
cin>>T;
for(int cas = 1;cas <= T;cas++){
scanf("%lf%lf%lf%lf%lf",&AB,&BC,&CD,&DA,&EF);
Circle B = Circle(Point(0,0),2*EF),C = Circle(Point(0,BC),DA),G,D;
Point A,A2;
vector<Point> ans;
int ok = getCircleCircleIntersection(B, C,ans);
for(int ook = 0;ook<ok;ook++){
A2 = ans[ook];
G = Circle(A2 + (B.c - C.c),AB);
C.r = CD;
ans.clear();
int flag = getCircleCircleIntersection(C, G, ans);
if(flag == 0)continue;
D = Circle(ans[0],DA);
//printf("GD:%lf\n",Length(G.c-D.c));
A = B.c + (D.c-G.c);
printf("Case #%d:\n",cas);
printf("%.6f %.6f\n",A.x,A.y);
printf("%.6f %.6f\n",B.c.x,B.c.y);
printf("%.6f %.6f\n",C.c.x,C.c.y);
printf("%.6f %.6f\n",D.c.x,D.c.y);
Point E = (A + B.c)/2.0,F = (C.c + D.c)/2.0;
/*printf("AB:%lf BC:%lf CD:%lf DA:%lf EF:%lf\n",
Length(A-B.c),Length(B.c-C.c),Length(C.c-D.c),
Length(D.c-A),Length(E-F));*/
break;
}
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:计算几何
原文地址:http://blog.csdn.net/zava_1087/article/details/47395335