zoukankan      html  css  js  c++  java
  • ZOJ 3598 Spherical Triangle (三角关系)

    ZOJ Problem Set - 3598
    Spherical Triangle

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    As everybody knows, the sum of the interior angles of a triangle on a plane is always 180 degree. But this is not true when the triangle is on spherical surface. Given a triangle on a spherical surface, you are asked to calculate the sum of the interior angles of the triangle.

    picture

    Formally, you are given the 3 vertex of the triangle. They are connected by the arcs of the great circles, i.e. circles whose centers coincide with the center of the sphere. It is guaranteed that the triangle is not degenerate, i.e. the 3 vertices will not lie on one great circle and no two vertices collide. The interior of the triangle is defined as the smaller part that the triangle is divide into.

    Input

    There are multiple test cases. The first line of input contains an integer T (0 < T ≤ 2012) indicating the number of test cases. Then T test cases follow.

    Each test case contains 3 lines, indicating the position of the 3 vertices. Each line contains 2 real number, each of which contains at most 2 digits after the decimal point, indicating the longitude and the latitude of the vertex. The longitude and the latitude are measured in degree. The longitude will be in (-180, 180] while the latitude will be in [-90, 90].

    Output

    For each test case, output the sum of the interior angles of the triangle measured in degree, accurate to 0.01.

    Sample Input

    1
    0 0
    90 0
    0 90
    

    Sample Output

    270.00
    

    References


    Author: GUAN, Yao
    Contest: The 12th Zhejiang University Programming Contest
     
    题意:给出三个点的经度和纬度,求球面三角形的内角和。
    分析:根据题目给出的链接的提示结合三角函数计算推出公式就行。
    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<cmath>
    #include<stdlib.h>
    #include<vector>
    #include<queue>
    #include<stack>
    #include<algorithm>
    using namespace std;
    const double PI=acos(-1.0);
    struct node
    {
        double x;
        double y;
        double z;
    }A,B,C;
    
    void change(double j,double w,node &P)
    {
        P.x=cos(w*PI/180)*cos(j*PI/180);
        P.y=cos(w*PI/180)*sin(j*PI/180);
        P.z=sin(w*PI/180);
    }
    
    double calc(node PA,node PB)
    {
        return (PA.x*PB.x)+(PA.y*PB.y)+(PA.z*PB.z);
    }
    
    int main()
    {
        int kase;
        scanf("%d",&kase);
        while(kase--)
        {
            double ax,ay,bx,by,cx,cy;
            scanf("%lf %lf %lf %lf %lf %lf",&ax,&ay,&bx,&by,&cx,&cy);
            change(ax,ay,A);
            change(bx,by,B);
            change(cx,cy,C);
            //printf("%lf %lf %lf
    ",A.x,A.y,A.z);
            double a,b,c;
            a=acos(calc(B,C));
            b=acos(calc(A,C));
            c=acos(calc(A,B));
            //printf("a=%lf b=%lf c=%lf
    ",a,b,c);
    
            double biga,bigb,bigc;
            biga=acos( ( cos(a)-cos(b)*cos(c) )/ ( sin(b)*sin(c) ) );
            bigb=acos( ( cos(b)-cos(a)*cos(c) )/ ( sin(a)*sin(c) ) );
            bigc=acos( ( cos(c)-cos(a)*cos(b) )/ ( sin(a)*sin(b) ) );
    
            double ans=biga+bigb+bigc;
            //printf("%.2lf
    ",ans);
            ans=ans*(180/PI);
            printf("%.2lf
    ",ans);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    Linux高级篇--Linux防火墙
    一、华为模拟器eNSP下载与安装教程
    中继器,集线器,网桥,交换机,路由器有什么区别?//联网用到的硬件简介
    Web前端调试技巧
    疯狂HTML5-CSS3-JavaScript讲义-光盘源码-李刚
    HTML5从入门到精通-电子书和随书光盘
    案例学Web前端开发-电子书和随书光盘
    [转]OpenLayer4地图全屏的实现
    网页开发中使用javascript语言时浏览器操作时弹出错误:Uncaught TypeError: Cannot set property 'onClick' of null。
    java.lang.ClassCastException: org.apache.hadoop.io.Text cannot be cast to org.apache.h...
  • 原文地址:https://www.cnblogs.com/clliff/p/4486073.html
Copyright © 2011-2022 走看看