Title Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4682
As everybody knows, the sum of the interior angles of a triangle on a plane are always the degree. But that's not true when the triangle are on spherical surface. Given a triangle on a spherical surface, which is asked to calculate the sum of the interior angles of the triangle.
Formally, given the 3 vertex of the triangle. They is 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 are not degenerate, i.e. the 3 vertices won't lie on one great circle and no, vert Ices collide. The interior of the triangle is defined as the smaller part, the triangle is divide into.
Input
There is 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, and each of the which contains at most 2 digits after the decimal point, indicating the Longitud E and the latitude of the vertex. The longitude and the latitude is measured in degree. The longitude'll is in ( -180, latitude) while the-the-and-be is 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
10 090 00 90
Sample Output
270.00
References
- Http://en.wikipedia.org/wiki/Spherical_trigonometry
Baidu Encyclopedia: Spherical triangle
The code is as follows:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include < malloc.h> #include <ctype.h> #include <math.h> #include <string> #include <iostream># Include <algorithm>using namespace std, #include <stack> #include <queue> #include <vector># Include <deque> #include <set> #include <map> #define PI ACOs ( -1.0) Double line_dist (double r,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 r*sqrt (2-2* (cos (LAT1) *cos (LAT2) *cos (DLNG) +sin (LAT1) *sin (LAT2)));} 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;}
ZOJ 3598 Spherical Triangle (Calculate geometry spherical triangle inner angles and)