• <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 閱讀(212) 評論(0)  編輯 收藏 引用
            亚洲中文字幕无码一久久区| 久久久久久久波多野结衣高潮| 国产成人精品综合久久久久| 久久久久久综合网天天| 亚洲精品乱码久久久久久久久久久久| 国产综合久久久久| 久久久久久无码国产精品中文字幕 | 亚洲人成网亚洲欧洲无码久久 | 日日噜噜夜夜狠狠久久丁香五月| 91精品国产综合久久婷婷| A级毛片无码久久精品免费| 久久综合九色综合网站| 日本精品久久久久中文字幕| 国产精品久久久久久久人人看 | 色噜噜狠狠先锋影音久久| 青青青青久久精品国产h久久精品五福影院1421 | 亚洲国产一成人久久精品| 久久播电影网| 韩国免费A级毛片久久| 久久亚洲AV无码精品色午夜麻豆| 99久久精品国产免看国产一区| 亚洲欧美成人久久综合中文网 | 久久不射电影网| 漂亮人妻被中出中文字幕久久| 青青热久久综合网伊人| 久久久久亚洲Av无码专| 久久99精品国产麻豆宅宅| 四虎影视久久久免费观看| 久久精品亚洲福利| 91精品无码久久久久久五月天| 久久久精品人妻一区二区三区蜜桃 | 三级三级久久三级久久| 久久亚洲AV无码西西人体| 久久97久久97精品免视看| 国产欧美一区二区久久| 精品久久久久久亚洲| 久久久久女人精品毛片| 久久久久成人精品无码中文字幕| 亚洲综合伊人久久大杳蕉| 蜜臀av性久久久久蜜臀aⅴ| 狼狼综合久久久久综合网|