阅读249 返回首页    go 阿里云 go 技术社区[云栖]


POJ 3407 求球面距离

题意:给出球面上两点的经纬度,注意分跟秒进制是60进制的,让求球面上的两点距离。

有公式  r*acos(sin(a1)*sin(a2)+cos(a1)*cos(a2)*cos(b1-b2)) 。

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
double Dis3D(double a1,double b1,double a2,double b2,double r)
{
    return r*acos(sin(a1)*sin(a2)+cos(a1)*cos(a2)*cos(b1-b2));
}
double geta(double x1,double x2,char *s)
{
    double a=x1+x2/60.0;
    if(s[0]=='W'||s[0]=='S')
        a=-a;
    a=a*acos(-1.0)/180;
    return a;
}
int main()
{
    double x1,x2,y1,y2;
    char s1[3],s2[3];
    while(~scanf("%lf%lf%s%lf%lf%s",&x1,&x2,s1,&y1,&y2,s2))
    {
        double a1=geta(x1,x2,s1),b1=geta(y1,y2,s2);
        scanf("%lf%lf%s%lf%lf%s",&x1,&x2,s1,&y1,&y2,s2);
        double a2=geta(x1,x2,s1),b2=geta(y1,y2,s2);
        printf("%.3f\n",Dis3D(a1,b1,a2,b2,6370));
    }
    return 0;
}


最后更新:2017-04-03 16:48:37

  上一篇:go 第6章 MSI和MSI-X中断机制
  下一篇:go 第2章 PCI总线的桥与配置