zoj 3598 Spherical Triangle 一道很纯的公式题,经纬线计算球面内角和

Spherical Triangle Time Limit: 2 Seconds       Memory Limit: 65536 KB

As everybody knows, the sum of the interior angles of a triangle on a plane is always 180 degree. But this is not true when the triangle is on spherical surface. Given a triangle on a spherical surface, you are asked to calculate the sum of the interior angles of the triangle.

Formally, you are given the 3 vertex of the triangle. They are connected by the arcs of the great circles, i.e. circles whose centers coincide with the center of the sphere. It is guaranteed that the triangle is not degenerate, i.e. the 3 vertices will not lie on one great circle and no two vertices collide. The interior of the triangle is defined as the smaller part that the triangle is divide into.

Input

There are multiple test cases. The first line of input contains an integer T (0 < T ≤ 2012) indicating the number of test cases. Then T test cases follow.

Each test case contains 3 lines, indicating the position of the 3 vertices. Each line contains 2 real number, each of which contains at most 2 digits after the decimal point, indicating the longitude and the latitude of the vertex. The longitude and the latitude are measured in degree. The longitude will be in (-180, 180] while the latitude will be in [-90, 90].

Output

For each test case, output the sum of the interior angles of the triangle measured in degree, accurate to 0.01.

Sample Input

1
0 0
90 0
0 90

Sample Output

270.00

链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3598



给你三个点的经纬度,计算在球面上的三个内角和。

计算两点各自距离,用数学公式计算下内角。
#define pi acos(-1.0)

//lat weidu   lng jingdu

double angle(double lng1,double lat1,double lng2,double lat2)
{
	double dlng=fabs(lng1-lng2)*pi/180;
	while (dlng>=pi+pi)
		dlng-=pi+pi;
	if (dlng>pi)
		dlng=pi+pi-dlng;
	lat1*=pi/180,lat2*=pi/180;
	return acos(cos(lat1)*cos(lat2)*cos(dlng)+sin(lat1)*sin(lat2));
}

inline double sphere_dist(double r,double lng1,double lat1,double lng2,double lat2)
{
	return r*angle(lng1,lat1,lng2,lat2);
}
double lng[5],lat[5],len[5];

int main()
{
	int t;
	cin>>t;
	double r=1;
	while(t--)
	{
		for(int i=0;i<3;i++)
		{
			cin>>lng[i]>>lat[i];
		}

		for(int i=0;i<3;i++)
		{
			len[i]=sphere_dist(r,lng[i],lat[i],lng[(i+1)%3],lat[(i+1)%3]);  
		}

		double p=0;
		for(int i=0;i<3;i++)
			p+=len[i];
		p/=2.0;
		//cout<<'p'<<p<<endl;
		double m=sqrt((sin(p-len[0])*sin(p-len[1])*sin(p-len[2]))/sin(p));

		//cout<<m<<endl;
		double ctg[5];
		double sum=0;
		for(int i=0;i<3;i++)
		{
			ctg[i]=sin(p-len[i])/m;
			ctg[i]=1.0/ctg[i];
			ctg[i]=atan(ctg[i])*2.0;
			sum+=ctg[i];
		} 
		printf("%.2lf\n",sum/pi*180); 
	}
	return 0; 
}


你可能感兴趣的:(几何)