#include<iostream>
#include<cmath>
#define PI acos(-1)
#define R 6371.01
using namespace std;
/*
* AUTHOR : liuchialun
* DATE : 2012/3/1
* PROBLEM: calculate the shortest arch distance between 2 nodes on the sphere
* SOLUTION: turn the angle coordinate to the x,y,z coordinate A,B
* use cosine theorem to calculate the angle of OA and OB
* the answer is theta*R
*/
struct cor
{
double a,b;
double c;
double d,e;
double f;
char ch[2];
};
double arch(struct cor *c);
double dist(double *x,double *y,double *z);
int main()
{
int cas;
cin>>cas;
while(cas--)
{
struct cor c[2];
for(int i = 0 ;i < 2 ; i++)
cin>>c[i].a>>c[i].b>>c[i].c>>c[i].ch[0]>>c[i].d>>c[i].e>>c[i].f>>c[i].ch[1];
printf("%.2lf\n",arch(c));
}
return 0;
}
double arch(struct cor *c)
{
// turn angle to coordinate
double x[2],y[2],z[2];
double ag[2],d,theta;
for(int i = 0 ;i < 2 ; i++)
{
ag[0] = (PI/(180.0*3600))*(c[i].a*3600+c[i].b*60.0+c[i].c);
if(c[i].ch[0]=='S')ag[0] = -ag[0];
ag[1] = (PI/(3600*180.0))*(c[i].d*3600+c[i].e*60+c[i].f);
if(c[i].ch[1]=='W')ag[1] = -ag[1];
x[i] = R*sin(ag[0]);
y[i] = R*cos(ag[0])*cos(ag[1]);
z[i] = R*cos(ag[0])*sin(ag[1]);
}
d = dist(x,y,z);
theta = acos(( 2*R*R-d*d)/(2*R*R));
return R*theta;
}
double dist(double *x,double *y,double *z)
{
double v[3];
v[0] = x[0] - x[1];
v[1] = y[0] - y[1];
v[2] = z[0] - z[1];
return sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
}
- 3月 03 週四 201100:49
uva 10897
文章標籤
全站熱搜
