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;
    }
  • 相关阅读:
    POJ 1066 Treasure Hunt (线段相交)
    玲珑杯 第4次 String cut(暴力字符串)
    POJ 2653 Pick-up sticks (线段相交)
    HDU 3535 AreYouBusy (混合背包)
    HDU 1712 ACboy needs your help(分组背包)
    HDU 1074 Doing Homework (状压dp)
    POJ 1635 Subway tree systems (树的最小表示法)
    HDU 汉诺塔系列
    HYSBZ 1500 维修数列(伸展树模板)
    photoshop 快速切图
  • 原文地址:https://www.cnblogs.com/Commence/p/4535271.html
Copyright © 2011-2022 走看看