zoukankan      html  css  js  c++  java
  • ZOJ 3598 Spherical Triangle球面几何公式应用

    #include <map>
    #include <set>
    #include <list>
    #include <cmath>
    #include <ctime>
    #include <deque>
    #include <stack>
    #include <queue>
    #include <cctype>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <climits>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #define LL long long
    #define PI 3.1415926535897932626
    using namespace std;
    int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}
    const double eps = 1e-8;
    //有这么个公式cosa=cosb*cosc+sinb*sinc*cosA
    //其中小写a,b,c表示球面三角形边长所对应的圆心角 大写A表示三角形内角
    struct node
    {
        double x,y;
    };
    //计算圆心角lat表示纬度,lng表示经度,-90 <= w <= 90;
    //计算两点所在大圆劣弧对应圆心角,0 <= angle <= pi;
    double angle(double lng1,double lat1,double lng2,double lat2)
    {
        double dlng = fabs(lng1 - lng2) * PI / 180;
        while(dlng + eps > PI + PI)
            dlng -= PI + PI;
        if (dlng > PI) dlng = 2 * PI - dlng;
        lat1 *= PI / 180; lat2 *= PI / 180;
        return acos(cos(lat1) * cos(lat2) * cos(dlng) + sin(lat1) * sin(lat2));
    }
    double get_A(double a,double b,double c)
    {
        return acos((cos(a) - cos(b) * cos(c)) / (sin(b) * sin(c)));
    }
    int main()
    {
        int T;
        scanf("%d",&T);
        while (T--)
        {
            node a,b,c;
            scanf("%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y);
            double ta = angle(a.x,a.y,b.x,b.y);
            double tb = angle(b.x,b.y,c.x,c.y);
            double tc = angle(a.x,a.y,c.x,c.y);
            double ans = 0;
            ans += get_A(ta,tb,tc);
            ans += get_A(tb,tc,ta);
            ans += get_A(tc,ta,tb);
            printf("%.2lf
    ",ans * 180.0 / PI);
        }
        return 0;
    }
  • 相关阅读:
    Spring 签名加密+xml数据交互
    Spring 使用 RestTemplate 模拟 电商网站+支付平台
    SSM 框架搭建
    SpringMVC 登录验证实例
    四.Mybatis 动态sql语句
    三.Mybatis 多对一与一对多
    二.Mybatis 增删改查
    一.Mybatis 入门
    SSH框架搭建
    二)Spring AOP编程思想与动态代理
  • 原文地址:https://www.cnblogs.com/Commence/p/4535271.html
Copyright © 2011-2022 走看看