#include<bits/stdc++.h>
#define ll long long
#define IOS std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DEBUG cout<<",here\n";
#define Rep(i,l,r) for(int i=(l);i<=(r);i++)
using namespace std;
const double eps=1e-4;
const double PI=acos(-1.0);
int sgn(double x){return (x>eps)-(x<-eps);};
struct Point3 {double x, y, z;};
Point3 operator-(const Point3& a, const Point3& b) {return (Point3){a.x-b.x, a.y-b.y, a.z-b.z};}
Point3 operator+(const Point3& a, const Point3& b) {return (Point3){a.x+b.x, a.y+b.y, a.z+b.z};}
double Dot3(Point3 A, Point3 B){return A.x*B.x + A.y*B.y + A.z*B.z;}
double Length3(Point3 A){return sqrt(Dot3(A, A));}
double radians(double angle){return angle*PI/180;}
struct Sphere{
Point3 o={0,0,0};double r;
Point3 GetCoord(double latitude, double longitude){//纬度以北为正,经度以东为正
latitude=radians(latitude);
longitude=radians(longitude);
Point3 p;
p.x=r*cos(latitude)*cos(longitude);
p.y=r*cos(latitude)*sin(longitude);
p.z=r*sin(latitude);
p=p+o;
return p;
}
double GetDisAB(Point3 a, Point3 b){
double d=Length3(a-b);
double rad=2*asin(d/2/r);
return rad*r;
}
};
Sphere sphere={{0,0,0},6875.0/2.0};
int main()
{
string s;
Rep(i,1,3){getline(cin,s);}
double latitude,longitude,a,b,c;
char d;
scanf("%lf^%lf'%lf\" %cL ",&a,&b,&c,&d);
latitude=a+b/60+c/3600;
if(d=='S')latitude*=-1;
scanf("and %lf^%lf'%lf\" %cL.",&a,&b,&c,&d);
longitude=a+b/60+c/3600;
if(d=='W')longitude*=-1;
Point3 p1=sphere.GetCoord(latitude,longitude);
getchar();
getline(cin,s);
scanf("%lf^%lf'%lf\" %cL ",&a,&b,&c,&d);
latitude=a+b/60+c/3600;
if(d=='S')latitude*=-1;
scanf("and %lf^%lf'%lf\" %cL.",&a,&b,&c,&d);
longitude=a+b/60+c/3600;
if(d=='W')longitude*=-1;
Point3 p2=sphere.GetCoord(latitude,longitude);
getchar();
getline(cin,s);
double dis=sphere.GetDisAB(p1,p2);
printf("The distance to the iceberg: %.2lf miles.\n",dis);
if(floor(dis+0.005)<100){
printf("DANGER!\n");
}
return 0;
}
以经纬度求球上两点距离:经纬度板子
最新推荐文章于 2023-07-09 12:09:52 发布