• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 183,  comments - 10,  trackbacks - 0

            來自于《編程珠璣》

            計算球面的距離,輸入是球面上點的經度和緯度,得到一個原始點集,再得到另一個測量點集,輸出測量點集中的每個點到原始點集中的每個點的距離,這里的距離是兩個點的集合距離,即使在笛卡爾坐標系中的歐氏距離,根據經度和緯度,轉換為點在笛卡爾積中的 x, y, z 坐標

            測試數據:
            5
            E23 N35
            E150 N80
            W50 N20
            W175 N55
            E20 S35

            3
            E105 S70
            W40 S50
            W160 S85

              1 //
              2 //    goonyangxiaofang(at)163(dot)com
              3 //    QQ: 五九一二四七八七六
              4 //
              5 
              6 #include <iostream>
              7 #include <string>
              8 #include <vector>
              9 #include <cmath>
             10 
             11 class PointSet
             12 {
             13 public:
             14     struct Point
             15     {
             16         std::string longitude;
             17         std::string latitude;
             18         double longi;
             19         double lati;
             20         double x, y, z;
             21     private:
             22         void ajust()
             23         {
             24             if (longitude[0== 'E')
             25             {
             26                 longi = atof(longitude.c_str() + 1);
             27             }
             28             else if (longitude[0== 'W')
             29             {
             30                 longi = 360.0 - atof(longitude.c_str() + 1);
             31             }
             32             if (latitude[0== 'N')
             33             {
             34                 lati = atof(latitude.c_str() + 1);
             35             }
             36             else if (latitude[0== 'S')
             37             {
             38                 lati = -atof(latitude.c_str() + 1);
             39             }
             40             x = R * cos(lati * PI / 180.0* cos(longi * PI / 180.0);
             41             y = R * cos(lati * PI / 180.0* sin(longi * PI / 180.0);
             42             z = R * sin(lati  * PI / 180.0);
             43         }
             44     public:
             45         Point() : longitude(""), latitude(""), longi(0.0), lati(0.0), x(0.0), y(0.0), z(0.0) {}
             46         Point(const std::string& s1, const std::string& s2) : longitude(s1), latitude(s2)
             47         {
             48             ajust();
             49         }
             50         Point(const Point& p) : longitude(p.longitude), latitude(p.latitude), longi(p.longi), lati(p.lati), x(p.x), y(p.y), z(p.z) {};
             51         Point& operator=(const Point& p)
             52         {
             53             longitude = p.longitude;
             54             latitude  = p.latitude;
             55             longi     = p.longi;
             56             lati      = p.lati;
             57             x          = p.x;
             58             y          = p.y;
             59             z          = p.z;
             60             return *this;
             61         }
             62         bool operator==(const Point& p) const
             63         {
             64             return longitude == p.longitude && latitude == p.latitude;
             65         }
             66         double distance(const Point& p)
             67         {
             68             return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y) + (z - p.z) * (z - p.z));
             69         }
             70         friend std::istream& operator>>(std::istream& in, Point& p);
             71         friend std::ostream& operator<<(std::ostream& outconst Point& p);
             72     };
             73 private:
             74     std::vector<Point> m_set;
             75     static const double R;
             76     static const double PI;
             77 public:
             78     void insert(const std::string& s1, const std::string& s2)
             79     {
             80         Point p(s1, s2);
             81         m_set.push_back(p);
             82     }
             83     void insert(const Point& p)
             84     {
             85         m_set.push_back(p);
             86     }
             87     void print()
             88     {
             89         for (std::size_t i = 0; i < m_set.size(); ++i)
             90         {
             91             std::cout << "Point " << i + 1 << "";
             92             std::cout << m_set[i];
             93         }
             94     }
             95     std::size_t size()
             96     {
             97         return m_set.size();
             98     }
             99     Point& operator[](std::size_t i)
            100     {
            101         return m_set[i];
            102     }
            103     const Point& operator[](std::size_t i) const
            104     {
            105         return m_set[i];
            106     }
            107 };
            108 
            109 std::istream& operator>>(std::istream& in, PointSet::Point& p)
            110 {
            111     std::string s1, s2;
            112     in >> s1 >> s2;
            113     PointSet::Point p2(s1, s2);
            114     p = p2;
            115     return in;
            116 }
            117 
            118 std::ostream& operator<<(std::ostream& outconst PointSet::Point& p)
            119 {
            120     out << p.longitude << ' ';
            121     out << p.latitude  << ' ';
            122     out << p.longi << ' ';
            123     out << p.lati  << ' ';
            124     out << p.x << ' ';
            125     out << p.y << ' ';
            126     out << p.z << ' ';
            127     out << std::endl;
            128     return out;
            129 }
            130 
            131 const double PointSet::R = 6400.0;
            132 const double PointSet::PI = 3.1415926;
            133 
            134 int main()
            135 {
            136     PointSet ps;
            137     PointSet::Point p;
            138     long n;
            139     std::cin >> n;
            140     for (long i = 0; i < n; ++i)
            141     {
            142         std::cin >> p;
            143         ps.insert(p);
            144     }
            145     ps.print();
            146 
            147     PointSet measure_ps;
            148     std::cin >> n;
            149     for (long i = 0; i < n; ++i)
            150     {
            151         std::cin >> p;
            152         measure_ps.insert(p);
            153     }
            154     measure_ps.print();
            155     for (std::size_t i = 0; i < measure_ps.size(); ++i)
            156     {
            157         for (std::size_t j = 0; j < ps.size(); ++j)
            158         {
            159             std::cout << "From " << i + 1 << " to " << j + 1 << "" << ps[j].distance(measure_ps[i]) << std::endl;
            160         }
            161     }
            162     return 0;
            163 }
            164 
            posted on 2011-03-08 14:07 unixfy 閱讀(210) 評論(0)  編輯 收藏 引用
            久久人做人爽一区二区三区| 久久一本综合| 久久99精品国产自在现线小黄鸭| 久久天天躁狠狠躁夜夜avapp| 蜜臀av性久久久久蜜臀aⅴ麻豆 | 久久精品国产亚洲AV久| 精品久久无码中文字幕| 久久精品人妻一区二区三区| 中文字幕乱码久久午夜| 久久91精品国产91久久户| 伊人色综合久久天天网| 国产亚洲欧美成人久久片| 一级做a爰片久久毛片毛片| 久久99国产精一区二区三区 | 99精品国产综合久久久久五月天| 久久精品人人槡人妻人人玩AV| 91精品国产91久久久久久蜜臀| 久久91精品国产91久| 免费观看成人久久网免费观看| 久久久久噜噜噜亚洲熟女综合| 国产亚洲精品美女久久久| 久久久久黑人强伦姧人妻| 久久久精品国产sm调教网站| 无码人妻少妇久久中文字幕| 91精品国产综合久久香蕉 | 99久久777色| 亚洲中文久久精品无码ww16 | 久久久久亚洲av成人无码电影| 久久精品国产亚洲av日韩| 久久久国产99久久国产一| 久久天天日天天操综合伊人av| 免费国产99久久久香蕉| 国产美女久久精品香蕉69| 久久99精品久久久久子伦| 久久丫精品国产亚洲av| 人人狠狠综合久久88成人| 偷窥少妇久久久久久久久| 久久综合久久美利坚合众国 | 久久伊人影视| 久久精品一本到99热免费| 久久亚洲精品无码播放|