{"id":1125,"date":"2018-12-02T19:56:59","date_gmt":"2018-12-02T11:56:59","guid":{"rendered":"http:\/\/www.whudj.cn\/?p=1125"},"modified":"2018-12-03T16:09:41","modified_gmt":"2018-12-03T08:09:41","slug":"%e7%82%b9%e5%9c%a8%e5%a4%9a%e8%be%b9%e5%bd%a2%e5%86%85%e5%88%a4%e6%96%adpoint-in-polygon","status":"publish","type":"post","link":"http:\/\/www.whudj.cn\/?p=1125","title":{"rendered":"\u70b9\u5728\u591a\u8fb9\u5f62\u5185\u5224\u65ad(point in polygon)"},"content":{"rendered":"<p>\u7ed9\u5b9a2D\u5e73\u9762\u4e0a\u70b9\\(c(x,y)\\)\u786e\u5b9a\u5176\u662f\u5426\u5728\u591a\u8fb9\u5f62p\u5185\u90e8\uff0c\u662f\u6bd4\u8f83\u5e38\u89c1\u7684\u51e0\u4f55\u67e5\u8be2\u95ee\u9898\u4e4b\u4e00\u3002\u672c\u6587\u7684\u5185\u5bb9\u662f\u9610\u8ff0\u5c04\u7ebf\u6cd5(Ray Casting Algorithm)\u6c42\u89e3\u666e\u901a\u591a\u8fb9\u5f62(simple polygon) PIP(point in polygon)\u95ee\u9898\u7684\u601d\u8def\u4e0e\u5b9e\u73b0\u3002\u76ee\u524d\u7f51\u4e0a\u7c7b\u4f3c\u6587\u7ae0\u4e0d\u5c11\uff0c\u4f46\u662f\u5176\u4e2d\u90e8\u5206\u6587\u7ae0\u7f3a\u4e4f\u5bf9\u7279\u6b8a\u60c5\u51b5\u7684\u8ba8\u8bba\uff0c\u5728\u5e94\u7528\u65f6\u5bb9\u6613\u5728\u7279\u4f8b\u6570\u636e\u4e0a\u5931\u8d25\u3002<!--more--><\/p>\n<p><span style=\"text-decoration: underline;\"><strong>\u7b97\u6cd5\u601d\u8def\uff1a<\/strong><\/span><\/p>\n<p>ray casting \u7b97\u6cd5\u4e5f\u79f0\u4e4b\u4e3a crossing number \u7b97\u6cd5\u6216\u8005 even-odd rule \u7b97\u6cd5\uff0c\u4e3b\u8981\u5b9e\u73b0\u601d\u8def\u57fa\u4e8e\u8fd9\u6837\u7684\u89c2\u5bdf\uff0c\u5982\u679c\u4ece \u70b9\u00a0 c \u51fa\u53d1\u505a\u4e00\u6761\u4efb\u610f\u65b9\u5411\u7684\u5c04\u7ebf\uff0c\u5c04\u7ebf\u5c06\u4e0e\u591a\u8fb9\u5f62 p \u76f8\u4ea4\u4e8e\u82e5\u5e72\u4ea4\u70b9 \\(p_0,p_1,&#8230;,p_n\\)\u3002\u4ea4\u70b9\u7684\u4e2a\u6570\u4e3a\u5947\u6570\u65f6\u70b9\u5728\u591a\u8fb9\u5f62\u5185\uff08\u70b9\u5728\u591a\u8fb9\u5f62\u4e0a\u4e5f\u7b97\u591a\u8fb9\u5f62\u5185\uff09\uff1b\u53cd\u4e4b\u70b9\u5728\u591a\u8fb9\u5f62\u5916\u3002\u524d\u63d0\u662f\u591a\u8fb9\u5f62\u5fc5\u987b\u4e3a\u666e\u901a\u591a\u8fb9\u5f62(<a href=\"https:\/\/en.wikipedia.org\/wiki\/Simple_polygon\">simple polygon<\/a>)\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1219\" src=\"http:\/\/www.whudj.cn\/wp-content\/uploads\/2018\/12\/cn1.gif\" alt=\"\" width=\"300\" height=\"219\" \/><\/p>\n<p>\u4e3a\u4e86\u8ba1\u7b97\u7b80\u4fbf\uff0c\u901a\u5e38\u91c7\u7528\u7684\u5c04\u7ebf\u4e3a\u81ea\u70b9c\u6c34\u5e73\u5411\u53f3\u7684\u5c04\u7ebf\u3002<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>\u7279\u6b8a\u60c5\u51b5\u7684\u8ba8\u8bba\uff1a<\/strong><\/span><\/p>\n<p>\u5f53\u5c04\u7ebf\u7ecf\u8fc7\u591a\u8fb9\u5f62\u7684\u8fb9\u65f6\uff0c\u4f1a\u51fa\u73b0\u5982\u4e0b\u60c5\u51b5\uff08\u5982\u56fe\u6240\u793a\uff09\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1221\" src=\"http:\/\/www.whudj.cn\/wp-content\/uploads\/2018\/12\/ray_crossing_algorithm.jpg\" alt=\"\" width=\"334\" height=\"229\" \/><\/p>\n<p>1.\u70b9a \u6240\u5728\u5c04\u7ebf\u7ecf\u8fc7\u591a\u8fb9\u5f62\u7684\u975e\u7aef\u70b9\uff0c\u4ea4\u70b9\u6709\u6548\uff0c\u8ba1\u6570\u4e3a1\u3002<\/p>\n<p>2.\u70b9b\u6240\u5728\u5c04\u7ebf\u7ecf\u8fc7\u591a\u8fb9\u5f62\u4e0a\u8fb9\u7684\u7aef\u70b9\uff0c\u4ea4\u70b9\u6709\u6548\uff0c\u8ba1\u6570\u5e94\u8be5\u4e3a<strong>1<\/strong>\u3002<\/p>\n<p>3.\u70b9c\u6240\u5728\u5c04\u7ebf\u7ecf\u8fc7\u591a\u8fb9\u5f62\u4e0a\u8fb9\u7684\u7aef\u70b9\uff0c\u4f46\u6b64\u7aef\u70b9\u5e94\u8ba1\u4e3a\u65e0\u6548\u4ea4\u70b9\uff0c\u8ba1\u6570\u4e3a<strong>0<\/strong>\u3002<\/p>\n<p>4.\u70b9d\u6240\u5728\u5c04\u7ebf\u7ecf\u8fc7\u591a\u8fb9\u5f62\u4e0a\u7684\u6c34\u5e73\u8fb9(horizontal line),\u65e0\u6548\u7aef\u70b9\uff0c\u8ba1\u6570\u4e3a<strong>0<\/strong>\u3002<\/p>\n<p>\u5982\u4f55\u533a\u52062.3.\u4e24\u79cd\u60c5\u51b5\uff1f \u4e0d\u59a8\u5b9a\u4e49\u5c04\u7ebf\u4e0e\u7aef\u70b9\u76f8\u4ea4\u7684\u89c4\u5219\u5982\u4e0b\uff1a<\/p>\n<p>\u5f53\u76f8\u4ea4\u7aef\u70b9\u662f \u6240\u5728\u8fb9\u7684 \u4e0b\u7aef\u70b9\uff08y\u503c\u8f83\u5c0f\uff09\u65f6\u8bb0\u5f55\u4e3a\u6709\u6548\u4ea4\u70b9\uff0c\u8ba1\u6570\u4e3a1\uff0c\u5f53\u76f8\u4ea4\u7aef\u70b9\u662f\u6240\u5728\u8fb9\u7684\u4e0a\u7aef\u70b9\uff08y\u503c\u8f83\u5927\uff09\u65f6\u8bb0\u5f55\u4e3a\u65e0\u6548\u7aef\u70b9\uff0c\u8ba1\u6570\u4e3a0\u3002\u53cd\u4e4b\u4ea6\u53ef\u3002<\/p>\n<p>\u56e0\u6b64\u70b9b\u5bf9\u5e94\u7684\u60c5\u51b5\u4e3a\u4e0e\u8fb94\u5b58\u5728\u4ea4\u70b9\uff0c\u4e0e\u8fb93\u4e0d\u5b58\u5728\u4ea4\u70b9\uff0c\u603b\u4ea4\u70b9\u6570\u4e3a 1\u3002<\/p>\n<p>\u70b9c\u5bf9\u5e94\u7684\u60c5\u51b5\u4e3a\u70b9c\u4e0e\u8fb91\u8fb92 \u7684\u4ea4\u70b9\u5747\u4e3a\u4e0a\u7aef\u70b9\uff0c\u603b\u4ea4\u70b9\u6570\u4e3a0\u3002<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>c++\u5b9e\u73b0\uff1a<\/strong><\/span><\/p>\n<p>\u6211\u7684\u4ee3\u7801\u5730\u5740\uff1a<a href=\"https:\/\/github.com\/whudongjian\/spatial_overlay\/blob\/master\/algorithm\/gemetry_util.cpp\">https:\/\/github.com\/whudongjian\/spatial_overlay\/blob\/master\/algorithm\/gemetry_util.cpp<\/a><\/p>\n<p><span class=\"lang:c++ decode:true crayon-inline \">bool GeometryUtil::point_in_polygon(const overlay::geometry::Coordinate &amp;c, overlay::geometry::LineString *ring)<\/span><\/p>\n<p><span style=\"text-decoration: underline;\"><strong>\u53c2\u8003\u6587\u732e\uff1a<\/strong><\/span><\/p>\n<p>1.inclusion of a point in polygon .<a href=\"http:\/\/geomalgorithms.com\/a03-_inclusion.html\">geomalgorithms.com<\/a><\/p>\n<p>2.simple polygon .<a href=\"https:\/\/en.wikipedia.org\/wiki\/Simple_polygon\"> wikipedia<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a2D\u5e73\u9762\u4e0a\u70b9\\(c(x,y)\\)\u786e\u5b9a\u5176\u662f\u5426\u5728\u591a\u8fb9\u5f62p\u5185\u90e8\uff0c\u662f\u6bd4\u8f83\u5e38\u89c1\u7684\u51e0\u4f55\u67e5 &hellip; <a href=\"http:\/\/www.whudj.cn\/?p=1125\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"_links":{"self":[{"href":"http:\/\/www.whudj.cn\/index.php?rest_route=\/wp\/v2\/posts\/1125"}],"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=1125"}],"version-history":[{"count":6,"href":"http:\/\/www.whudj.cn\/index.php?rest_route=\/wp\/v2\/posts\/1125\/revisions"}],"predecessor-version":[{"id":1227,"href":"http:\/\/www.whudj.cn\/index.php?rest_route=\/wp\/v2\/posts\/1125\/revisions\/1227"}],"wp:attachment":[{"href":"http:\/\/www.whudj.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.whudj.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1125"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.whudj.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}