uva 11817(球面距离)

题意:假设地球是一个正球体,半径是6371009米,给出地球上起始点和终止点的经纬度,北纬和东经用正数表示,南纬和西经用负数表示,问沿着球面走的最短路和用隧道走直线路程相差多少。
题解:先把纬度加180,范围转化为0~360,然后把角度转化为弧度,再把经纬度位置转化为空间坐标。

x = r * cos(a) * cos(b)
y = r * cos(a) * sin(b)
z = r * sin(a)

(x,y,z)是空间坐标,a是纬度[0,2π],b是经度[-π/2,π/2]
那么直线距离就是弦长d
球面距离就是弧长l
l = 2r * arcsin(d/2r)

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const double r = 6371009;
const double PI = acos(-1);
struct Point3 {
    double x, y, z;
    Point3(double a = 0, double b = 0, double c = 0):x(a), y(b), z(c) {}
}S, E;

double torad(double deg) {
    return deg / 180 * PI;
}

int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        double Sew, Sns, Eew, Ens;
        scanf("%lf%lf%lf%lf", &Sns, &Sew, &Ens, &Eew);  
        Sns += 180;
        Ens += 180;
        Sew = torad(Sew);
        Sns = torad(Sns);
        Ens = torad(Ens);
        Eew = torad(Eew);
        S.z = r * sin(Sns);
        S.y = r * cos(Sns) * sin(Sew);
        S.x = r * cos(Sns) * cos(Sew);
        E.z = r * sin(Ens);
        E.y = r * cos(Ens) * sin(Eew);
        E.x = r * cos(Ens) * cos(Eew);
        double len1 = sqrt((S.x - E.x) * (S.x - E.x) + (S.y - E.y) * (S.y - E.y) + (S.z - E.z) * (S.z - E.z));
        double len2 = 2 * r * asin(len1 / (2 * r));
        printf("%lld\n", (long long)(len2 - len1 + 0.5));
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值