zoukankan      html  css  js  c++  java
  • UVA11817计算几何+经纬度坐标转化

      1 /*UVA11817
      2 
      3 计算几何:
      4 
      5 总结一下公式:
      6 
      7 1、给定圆上两点坐标
      8 
      9 设直线距离=d
     10 
     11 圆弧距离=2*asin(d/2/r)*r
     12 
     13 2、拓展到球体上
     14 
     15 设直线距离=d
     16 
     17 最短圆弧距离=和上面相同
     18 
     19 这里有个弯要转一下,最短弧的切面必过圆心
     20 
     21 3、地球上坐标点用经纬度表示
     22 
     23 from:摘录
     24 
     25 设第一点A的经纬度为(LonA, LatA),第二点B的经纬度为(LonB, LatB),
     26 
     27 按照0度经线的基准,东经北纬取经度的正值(Longitude),西经南纬取经度负值(-Longitude),
     28 
     29 由(lng,lat)求的的相对三维坐标
     30 
     31 x = R*cos(lat)*cos(lng);
     32 
     33 y = R*cos(lat)*sin(lng);
     34 
     35 z = R*sin(lat);
     36 
     37 //lat维度,lng经度
     38 
     39  
     40 
     41 ps:通过邮政编码查询经纬度...这也可以
     42 
     43  
     44 
     45 */
     46 
     47 #include <stdio.h>
     48 
     49 #include <stdlib.h>
     50 
     51 #include <string.h>
     52 
     53 #include <math.h>
     54 
     55 #include <ctype.h>
     56 
     57 #include <string>
     58 
     59 #include <iostream>
     60 
     61 #include <sstream>
     62 
     63 #include <vector>
     64 
     65 #include <queue>
     66 
     67 #include <stack>
     68 
     69 #include <map>
     70 
     71 #include <list>
     72 
     73 #include <set>
     74 
     75 #include <algorithm>
     76 
     77  
     78 
     79 using namespace std;
     80 
     81  
     82 
     83 int main()
     84 
     85 {
     86 
     87     int t;
     88 
     89     double r=6371009;
     90 
     91     double lat1,lng1,lat2,lng2,x1,x2,y1,y2,z1,z2,d,d2;
     92 
     93     cin>>t;
     94 
     95     while(t--)
     96 
     97     {//lat纬度,lng经度
     98 
     99         cin>>lat1>>lng1>>lat2>>lng2;
    100 
    101  
    102 
    103         lat1=lat1/180 * M_PI;
    104 
    105         lat2=lat2/180 * M_PI;
    106 
    107         lng1=lng1/180 * M_PI;
    108 
    109         lng2=lng2/180 * M_PI;
    110 
    111  
    112 
    113         x1 = r*cos(lat1)*cos(lng1);
    114 
    115         y1 = r*cos(lat1)*sin(lng1);
    116 
    117         z1 = r*sin(lat1);
    118 
    119         x2 = r*cos(lat2)*cos(lng2);
    120 
    121         y2 = r*cos(lat2)*sin(lng2);
    122 
    123         z2 = r*sin(lat2);
    124 
    125  
    126 
    127         d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
    128 
    129         d2 = 2*asin(d/2/r)*r;
    130 
    131  
    132 
    133         cout<<(long long)(d2-d+0.5)<<endl;
    134 
    135     }
    136 
    137 }
    138 
    139  
  • 相关阅读:
    jdbc-------JDBCUtil类 工具类
    jdbc --- javabean
    MapReduce 找出共同好友
    mapReducer 去重副的单词
    用户定义的java计数器
    mapReducer第一个例子WordCount
    win10 Java环境变量,hadoop 环境变量
    Writable序列化
    io 流操作hdfs
    [常用命令]OSX命令
  • 原文地址:https://www.cnblogs.com/little-w/p/3570187.html
Copyright © 2011-2022 走看看