• <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

            來(lái)自于《編程珠璣》

            計(jì)算球面的距離,輸入是球面上點(diǎn)的經(jīng)度和緯度,得到一個(gè)原始點(diǎn)集,再得到另一個(gè)測(cè)量點(diǎn)集,輸出測(cè)量點(diǎn)集中的每個(gè)點(diǎn)到原始點(diǎn)集中的每個(gè)點(diǎn)的距離,這里的距離是兩個(gè)點(diǎn)的集合距離,即使在笛卡爾坐標(biāo)系中的歐氏距離,根據(jù)經(jīng)度和緯度,轉(zhuǎn)換為點(diǎn)在笛卡爾積中的 x, y, z 坐標(biāo)

            測(cè)試數(shù)據(jù):
            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) 評(píng)論(0)  編輯 收藏 引用

            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            久久精品视频一| 国产精品久久久久久久久| 99久久夜色精品国产网站| 国产欧美久久一区二区| 精品久久久久久久久久中文字幕 | 久久亚洲综合色一区二区三区| 99久久精品免费看国产| 亚洲精品无码久久久久sm| 一本久久久久久久| 日韩av无码久久精品免费| 久久精品亚洲男人的天堂| 99久久婷婷国产综合亚洲| 亚洲精品乱码久久久久久不卡| 国产精品久久久久天天影视| 超级碰碰碰碰97久久久久| 99久久精品免费| 91精品国产高清久久久久久io| 亚洲精品乱码久久久久久不卡| 韩国无遮挡三级久久| 成人午夜精品无码区久久| 欧美色综合久久久久久| 久久免费小视频| 国产精品久久久久久久久| 人妻无码αv中文字幕久久琪琪布 人妻无码久久一区二区三区免费 人妻无码中文久久久久专区 | 无码人妻久久一区二区三区免费丨| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 久久青青草原精品国产| 亚洲午夜精品久久久久久浪潮| 丁香久久婷婷国产午夜视频| 久久久久高潮毛片免费全部播放| 久久综合久久美利坚合众国| 亚洲а∨天堂久久精品9966| 久久电影网| 久久久网中文字幕| 久久精品国产99久久久香蕉| 国产激情久久久久影院老熟女免费| 久久精品无码一区二区三区| 久久久无码一区二区三区| 婷婷五月深深久久精品| 久久精品午夜一区二区福利 | 久久97久久97精品免视看秋霞|