您的位置:首页 > 其它

ZOJ 3598 Spherical Triangle球面几何公式应用

2015-05-28 10:34 399 查看
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}
const double eps = 1e-8;
//有这么个公式cosa=cosb*cosc+sinb*sinc*cosA
//其中小写a,b,c表示球面三角形边长所对应的圆心角 大写A表示三角形内角
struct node
{
double x,y;
};
//计算圆心角lat表示纬度,lng表示经度,-90 <= w <= 90;
//计算两点所在大圆劣弧对应圆心角,0 <= angle <= pi;
double angle(double lng1,double lat1,double lng2,double lat2)
{
double dlng = fabs(lng1 - lng2) * PI / 180;
while(dlng + eps > PI + PI)
dlng -= PI + PI;
if (dlng > PI) dlng = 2 * PI - dlng;
lat1 *= PI / 180; lat2 *= PI / 180;
return acos(cos(lat1) * cos(lat2) * cos(dlng) + sin(lat1) * sin(lat2));
}
double get_A(double a,double b,double c)
{
return acos((cos(a) - cos(b) * cos(c)) / (sin(b) * sin(c)));
}
int main()
{
int T;
scanf("%d",&T);
while (T--)
{
node a,b,c;
scanf("%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y);
double ta = angle(a.x,a.y,b.x,b.y);
double tb = angle(b.x,b.y,c.x,c.y);
double tc = angle(a.x,a.y,c.x,c.y);
double ans = 0;
ans += get_A(ta,tb,tc);
ans += get_A(tb,tc,ta);
ans += get_A(tc,ta,tb);
printf("%.2lf\n",ans * 180.0 / PI);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: