{"id":1010,"date":"2018-05-16T18:13:13","date_gmt":"2018-05-16T10:13:13","guid":{"rendered":"http:\/\/www.whudj.cn\/?p=1010"},"modified":"2022-01-18T09:33:43","modified_gmt":"2022-01-18T01:33:43","slug":"%e5%a4%9a%e8%be%b9%e5%bd%a2%e9%9d%a2%e7%a7%af%e4%bb%a5%e5%8f%8a%e9%a1%ba%e9%80%86%e6%97%b6%e9%92%88%e9%a1%ba%e5%ba%8f%e5%88%a4%e6%96%ad","status":"publish","type":"post","link":"http:\/\/www.whudj.cn\/?p=1010","title":{"rendered":"\u591a\u8fb9\u5f62\u9762\u79ef\u4ee5\u53ca\u987a\u9006\u65f6\u9488\u987a\u5e8f\u5224\u65ad"},"content":{"rendered":"<p>\u672c\u6587\u4ecb\u7ecd\u4e24\u79cd\u591a\u8fb9\u5f62\uff08\u7b80\u5355\u591a\u8fb9\u5f62\uff09\u7684\u987a\u9006\u65f6\u9488\u987a\u5e8f\u5224\u65ad\u7b97\u6cd5\uff0c\u5176\u4e2d\u4e00\u79cd\u7b97\u6cd5\u5c31\u662f\u901a\u8fc7\u8ba1\u7b97\u591a\u8fb9\u884c\u7684\u9762\u79ef(\u5e26\u7b26\u53f7)\u6765\u5224\u65ad\u3002\u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u6839\u636e\u6700\u5de6\u4fa7\u70b9\u524d\u540e\u8fb9\u7684\u8f6c\u5411(\u53c9\u79ef)\u5224\u65ad\u3002\u6709\u610f\u601d\u7684\u662f\uff0c\u7f51\u4e0a\u6709\u4e00\u4e9b\u6587\u7ae0\u5e76\u6ca1\u6709\u5c31\u8fd9\u79cd\u65b9\u6cd5\u7684\u7279\u6b8a\u60c5\u51b5\u8fdb\u884c\u8ba8\u8bba\u3002<!--more--><\/p>\n<p><span style=\"text-decoration: underline;\"><strong>1.\u591a\u8fb9\u5f62\u7684\u9762\u79ef\u7b97\u6cd5<\/strong><\/span><\/p>\n<p>\u591a\u8fb9\u5f62\u7684\u9762\u79ef\u7b97\u6cd5\u53ef\u4ee5\u7531\u4e09\u89d2\u5f62\u7684\u9762\u79ef\u7b97\u6cd5\u5f15\u51fa\u3002\u5148\u770b\u4e09\u89d2\u5f62\u7684\u9762\u79ef\u8ba1\u7b97<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1012\" src=\"http:\/\/www.whudj.cn\/wp-content\/uploads\/2018\/05\/area_triangle.png\" alt=\"\" width=\"210\" height=\"200\" \/><\/p>\n<p>$$Area(\\Delta) = \\frac {\\vec v_0 \\times \\vec v_1}{2}$$<\/p>\n<p>\u5b9e\u9645\u4e0a\uff0c\u5411\u91cf\u7684\u53c9\u79ef\u4e3a\u5411\u91cf\uff0c\u5728\u4e8c\u7ef4\u51e0\u4f55\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5c06\u5176\u5f53\u505a\u6807\u91cf\u65f6\uff0c\u6307\u7684\u662f\u5411\u91cf\u7684Z\u7ef4\u3002\u53c9\u79ef\u662f\u7531\u7b26\u53f7\u7684\uff0c\u5f53\u4e09\u89d2\u5f62\u4f4d\u4e8e\u5411\u91cf\u7684\u5de6\u4fa7\u65f6\uff0c\u4efb\u610f\u4e24\u8fb9\u6c42\u89e3\u7684\u9762\u79ef\u5747\u4e3a\u6b63\u53f7\u3002<\/p>\n<p>\u591a\u8fb9\u5f62\u7684\u9762\u79ef\u5373\u5c06\u591a\u53d8\u5f62\u5206\u89e3\u4e3a\u82e5\u5e72\u4e09\u89d2\u5f62\u7684\u9762\u79ef\u52a0\u548c: $$\\begin{equation*}<br \/>\ns = \\sum_{i=1}^{n-3}{Area(\\Delta c_0c_ic_{i+1})}<br \/>\n\\end{equation*}$$<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1016\" src=\"http:\/\/www.whudj.cn\/wp-content\/uploads\/2018\/05\/polygon_area.png\" alt=\"\" width=\"206\" height=\"200\" \/><\/p>\n<p>\u5176\u4e2d\uff0cn\u503c\u591a\u8fb9\u5f62boundary\u8282\u70b9\u4e2a\u6570\uff0c\u6309\u7167\u60ef\u4f8b\u5c3e\u70b9\u4e0e\u9996\u70b9\u91cd\u590d\uff0c\u5373\u4e09\u89d2\u5f62\u67094\u4e2a\u8282\u70b9\u3002\u5f53\u591a\u8fb9\u5f62\u73af\u5e8f\u4e3a\u9006\u65f6\u9488\u987a\u5e8f\u65f6\uff0c\u9762\u79ef\u4e3a\u6b63\uff0c\u53cd\u4e4b\u4e3a\u8d1f\u53f7\u3002\u56e0\u6b64\uff0c\u5f53\u591a\u8fb9\u5f62\u5b58\u5728\u201c\u6d1e\u201d\u65f6\uff0c\u9762\u79ef\u516c\u5f0f\u53ea\u9700\u8981\u5c06\u6d1e\u7684\u73af\u6784\u6210\u7684\u9762\u79ef\u52a0\u5165\u5373\u53ef\u3002\u6d1e\u7684\u987a\u5e8f\u4e0e\u5916\u73af\u987a\u5e8f\u662f\u60f3\u53cd\u7684\uff0c\u56e0\u6b64\u5f62\u6210\u7684\u9762\u79ef\u4f1a\u76f8\u51cf\u3002<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>1.1\u5bf9\u6bd4\uff1a<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1017\" src=\"http:\/\/www.whudj.cn\/wp-content\/uploads\/2018\/05\/polygon_not_good.png\" alt=\"\" width=\"240\" height=\"200\" \/><\/p>\n<p>\u4e00\u79cd\u76f8\u4f3c\u7684\u65b9\u6848\u5982\u4e0a\u56fe\u6240\u793a\u3002$$\\begin{equation*}<br \/>\ns = \\sum_{i=0}^{n-2}{Area(\\Delta c_0c_ic_{i+1})}<br \/>\n\\end{equation*}$$ \u4f60\u80fd\u77e5\u9053\u8fd9\u4e2a\u65b9\u6cd5\u6700\u5927\u7684\u95ee\u9898\u4e48\uff1f\u5176\u5b9e\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u7684\u95ee\u9898\u5728\u4e8e\uff0c\u5982\u679c\u591a\u8fb9\u5f62\u4f4d\u4e8e\u539f\u70b9\u4f4d\u7f6e\u8f83\u8fdc\uff0c\u800c\u5750\u6807\u5b58\u50a8\u7cbe\u5ea6\u4e0d\u591f\u5927\u7684\u60c5\u51b5\u4e0b(\u5982\u4f7f\u7528float\u4fdd\u5b58)\uff0c\u5bb9\u6613\u51fa\u73b0\u6bd4\u8f83\u5927\u7684\u6444\u5165\u8bef\u5dee\uff0c\u56e0\u4e3a\u7531\u539f\u70b9\u4e0e\u8fb9\u6784\u6210\u7684\u591a\u8fb9\u5f62\u9762\u79ef\u8fc7\u5927\uff0c\u8ba1\u7b97\u53c9\u79ef\u7684\u65f6\u5019\u8fd8\u6709\u53ef\u80fd\u56e0\u4e3a\u6ea2\u51fa\u800c\u8ba1\u7b97\u4e0d\u6b63\u786e\u3002\u6240\u4ee5\u4e0d\u63a8\u8350\u4f7f\u7528\u3002\u5176\u5b9e\u7b2c\u4e00\u79cd\u65b9\u6cd5\u5c31\u662f\u4e3a\u4e86\u907f\u514d\u8fd9\u6837\u7684\u60c5\u51b5\u53d1\u751f\uff0c\u4ece\u800c\u5c06\u539f\u70b9\u79fb\u52a8\u5230\u4e86\u591a\u8fb9\u5f62\u7b2c\u4e00\u4e2a\u8282\u70b9\u5904\u3002<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>1.2 \u5b9e\u73b0\u4ee3\u7801<\/strong><\/span><\/p>\n<pre class=\"lang:c++ decode:true\">double Algorithm::LineRingArea(const std::vector&lt;Coordinate&gt;&amp; input)\r\n{\r\n\tif (input.size() &lt; 4)\r\n\t\treturn 0.0;\r\n\tdouble area = 0.0;\r\n\tconst Coordinate&amp; c0 = input.front();\r\n\tfor (int i = 1, n = input.size(); i &lt; n - 2;++i)\r\n\t{\r\n\t\tVector v0 = input[i] - c0;\r\n\t\tVector v1 = input[i + 1] - input[i];\r\n\t\tarea += v0.CrossProduct(v1).z;\r\n\t}\r\n\treturn area\/2.0;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>2 \u591a\u8fb9\u5f62\u7684\u987a\u9006\u65f6\u9488\u987a\u5e8f\u5224\u65ad<\/strong><\/span><\/p>\n<p><strong><span style=\"text-decoration: underline;\">2.1 \u9762\u79ef\u6cd5<\/span><\/strong><\/p>\n<p>\u6839\u636e\u7b2c\u4e00\u8282\u63cf\u8ff0\uff0c\u5982\u679c\u591a\u8fb9\u5f62\u4e3a\u9006\u65f6\u9488\u987a\u5e8f\uff0c\u9762\u79ef\u4e3a\u6b63\uff1b\u53cd\u6b63\u9762\u79ef\u4e3a\u8d1f\uff1b<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>2.2 \u6839\u636e\u6700\u5de6\u4fa7\u70b9\u4e0a\u4e0b\u8fb9\u7684\u8d70\u5411\u5224\u65ad<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1020\" src=\"http:\/\/www.whudj.cn\/wp-content\/uploads\/2018\/05\/orientation_clockwise.png\" alt=\"\" width=\"273\" height=\"200\" \/><\/p>\n<p>\u636e\u4e0a\u56fe\uff0c\u5982\u679c\u4ece\u6700\u5de6\u4fa7\u70b9(leftmost)\u770b\uff0c\u5176\u524d\u4e00\u6761\u8fb9\u4e0e\u540e\u4e00\u6761\u8fb9\u7684\u8f6c\u5411\u5173\u7cfb\u4e3a\u53f3\u8f6c\uff0c\u90a3\u4e48\u591a\u8fb9\u5f62\u4e3a\u987a\u65f6\u9488\u987a\u5e8f\u3002\u53cd\u4e4b\uff0c\u5982\u679c\u8f6c\u5411\u5173\u7cfb\u4e3a\u5de6\u8f6c\uff0c\u5219\u591a\u8fb9\u5f62\u4e3a\u9006\u65f6\u9488\u987a\u5e8f\u3002\u8f6c\u5411\u5173\u7cfb\u53ef\u4ee5\u7528\u4e24\u6761\u8fb9\u7684\u5411\u91cf\u7684\u53c9\u79ef\u5224\u65ad\u3002<\/p>\n<p>wait a minute\u2026\u2026\u00a0 \u6211\u4eec\u8fd8\u6f0f\u6389\u4e86\u67d0\u79cd\u7279\u6b8a\u60c5\u51b5\uff0c\u5982\u679c\u8bf4\u9762\u7684\u6700\u5de6\u4fa7\u70b9\u7684x\u5750\u6807\u4e0eprev\uff0cnext \u70b9\u7684\u5750\u6807\u76f8\u540c\uff0c\u5373\u4e24\u6761\u8fb9\u5171\u7ebf\u5462\uff1f \u8fd9\u79cd\u60c5\u51b5\u662f\u4e00\u79cd\u7279\u6b8a\u60c5\u51b5(&#8220;degenerate case&#8221;)\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1021\" src=\"http:\/\/www.whudj.cn\/wp-content\/uploads\/2018\/05\/orientation_degenerate_case.png\" alt=\"\" width=\"259\" height=\"200\" \/><\/p>\n<p>\u56e0\u4e3a\u4e09\u4e2a\u70b9\u7684x\u503c\u662f\u76f8\u540c\u7684\uff0c\u56e0\u6b64\u5b8c\u5168\u6709\u53ef\u80fd\u51fa\u73b0 \u4e2d\u95f4\u7684\u70b9\u88ab\u9009\u4e3aleftmost point\u4ece\u800c\u5f15\u53d1\u5224\u65ad\u95ee\u9898\u7684\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6848\u5c31\u662f\u5224\u65ad prev ,next \u70b9\u7684\u4e0a\u4e0b\u5173\u7cfb(y\u503c)\u3002\u82e5 \\(y_{prev} &lt; y_{next}\\)\u5219\u591a\u8fb9\u5f62\u4e3a\u987a\u65f6\u9488\u987a\u5e8f\u3002\u53cd\u6b63\u4e3a\u9006\u65f6\u9488\u987a\u5e8f\u3002<\/p>\n<p>\u7efc\u4e0a\uff0c\u4f9d\u636e\u6700\u5de6\u4fa7\u4e0a\u4e0b\u8fb9\u8d70\u5411\u5224\u65ad\u591a\u8fb9\u5f62\u987a\u5e8f\u7684\u7b97\u6cd5\u662f\uff1a<\/p>\n<p>\u627e\u5230\u6700\u5de6\u4fa7\u70b9\\(P_i\\)\u3002<\/p>\n<p>\u8ba1\u7b97 \u5411\u91cf\u53c9\u79ef \\(\\vec{P_{i-1}P_{i}} \\times \\vec {P_iP_{i+1}}\\)\u3002\u82e5 \u53c9\u79ef&lt;0,\u591a\u8fb9\u5f62\u4e3a\u987a\u65f6\u9488\u987a\u5e8f\uff1b\u82e5\u53c9\u79ef&gt;0 \uff0c\u591a\u8fb9\u5f62\u4e3a\u9006\u65f6\u9488\u987a\u5e8f\uff1b<\/p>\n<p>\u82e5\u53c9\u79ef\u7b49\u4e8e0: \u82e5 \\(P_{i-1}.y &lt; P_{i+1}.y \\) \u5219 \u591a\u8fb9\u5f62\u4e3a\u987a\u65f6\u9488\u987a\u5e8f\uff0c\u5426\u5219\u591a\u8fb9\u5f62\u4e3a\u9006\u65f6\u9488\u987a\u5e8f\u3002<\/p>\n<p>\u5b9e\u73b0\u4ee3\u7801\uff1a<\/p>\n<pre class=\"lang:c++ decode:true\">bool compare_x(const Coordinate&amp; p0, const Coordinate&amp; p1)\r\n{\r\n\treturn p0.x &lt; p1.x;\r\n}\r\nbool Algorithm::IsCCW(const std::vector&lt;Coordinate&gt;&amp; input)\r\n{\r\n\tint n = input.size();\r\n\tint leftmost = std::distance(input.begin(), std::min_element(input.begin(), input.end(), compare_x));\r\n\tint prev = leftmost - 1;\r\n\tif (prev &lt; 0) prev = n-2; \/\/\u5012\u6570\u7b2c\u4e8c\u4e2a\u70b9\r\n\tint next = leftmost + 1;\r\n\tif (next &gt;= n) next =1; \/\/\u6b63\u6570\u7b2c\u4e8c\u4e2a\u70b9\r\n\r\n\tVector v0 = input[leftmost] - input[prev];\r\n\tVector v1 = input[next] - input[leftmost];\r\n\tdouble orientation = v0.CrossProduct(v1).z;\r\n\tif (orientation == 0)\r\n\t{\r\n\t\treturn input[prev].y &gt; input[next].y;\r\n\t}\r\n\telse\r\n\t{\r\n\t\treturn orientation &gt; 0;\r\n\t}\r\n\treturn true;\r\n}<\/pre>\n<p><strong><span style=\"text-decoration: underline;\">3.\u53c2\u8003\u6587\u732e\uff1a<\/span><\/strong><\/p>\n<p>1.Berg M D, Cheong O, Kreveld M V, et al. Computational Geometry: Algorithms and Applications[M]. Springer Publishing Company, Incorporated, 2000. \u7b2c\u4e09\u7248 \u7b2c36\u9875<\/p>\n<p>2.geos \u4e2d<span class=\"lang:c++ decode:true crayon-inline\">geos::algorithm::CGAlgorithms::IsCCW(.)<\/span>\u51fd\u6570\u7684\u5b9e\u73b0\uff1b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u4ecb\u7ecd\u4e24\u79cd\u591a\u8fb9\u5f62\uff08\u7b80\u5355\u591a\u8fb9\u5f62\uff09\u7684\u987a\u9006\u65f6\u9488\u987a\u5e8f\u5224\u65ad\u7b97\u6cd5\uff0c\u5176\u4e2d\u4e00\u79cd\u7b97\u6cd5\u5c31\u662f\u901a\u8fc7\u8ba1\u7b97 &hellip; <a href=\"http:\/\/www.whudj.cn\/?p=1010\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"_links":{"self":[{"href":"http:\/\/www.whudj.cn\/index.php?rest_route=\/wp\/v2\/posts\/1010"}],"collection":[{"href":"http:\/\/www.whudj.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.whudj.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.whudj.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.whudj.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1010"}],"version-history":[{"count":13,"href":"http:\/\/www.whudj.cn\/index.php?rest_route=\/wp\/v2\/posts\/1010\/revisions"}],"predecessor-version":[{"id":1330,"href":"http:\/\/www.whudj.cn\/index.php?rest_route=\/wp\/v2\/posts\/1010\/revisions\/1330"}],"wp:attachment":[{"href":"http:\/\/www.whudj.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1010"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.whudj.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1010"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.whudj.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1010"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}