我有一個大的列表來定義一些(不一定是凸起的)形狀的邊界。然後我有一些查詢點(x, y)
,我想確定(x, y)
是否在我的邊界點定義的區域內。如何確定(x,y)點是否在由邊界點列表定義的多邊形內
所以,很簡單的問題。如何確定查詢點是否位於由我的邊界點組成的形狀內部?有沒有一個很好的提升模塊?我正在查看boost::geometry
,但還沒有發現任何東西。
我有一個大的列表來定義一些(不一定是凸起的)形狀的邊界。然後我有一些查詢點(x, y)
,我想確定(x, y)
是否在我的邊界點定義的區域內。如何確定(x,y)點是否在由邊界點列表定義的多邊形內
所以,很簡單的問題。如何確定查詢點是否位於由我的邊界點組成的形狀內部?有沒有一個很好的提升模塊?我正在查看boost::geometry
,但還沒有發現任何東西。
似乎您在尋找within
,不是嗎?
http://www.boost.org/libs/geometry/doc/html/geometry/reference/algorithms/within/within_2.html
他們給出的頁面,其實點在多邊形上的例子:
#include <iostream>
#include <list>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/domains/gis/io/wkt/wkt.hpp>
int main()
{
typedef boost::geometry::model::d2::point_xy<double> point_type;
typedef boost::geometry::model::polygon<point_type> polygon_type;
polygon_type poly;
boost::geometry::read_wkt(
"POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)"
"(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))", poly);
point_type p(4, 1);
std::cout << "within: " << (boost::geometry::within(p, poly) ? "yes" : "no") << std::endl;
return 0;
}
UPDATE:爲@ildjarn指出的那樣,你可能寧願使用covered_by
如果你想要位於多邊形邊緣本身的點數:
within
w.r.t.的行爲邊緣「依賴」,所以請注意文檔中的細微差別。
是否有專門的矩形?多邊形可能會/可能不會有額外的假設,哪些矩形將免費.. –
我敢打賭,這是一個重複的 – BlackBear
強制性維基百科鏈接:[點多邊形](http://en.wikipedia.org/wiki/Point_in_polygon) – Kevin
對於Boost.Geometry,具體來說,你想要['內'](http ://www.boost.org/libs/geometry/doc/html/geometry/reference/algorithms/within/within_2.html)或['covered_by'](http://www.boost.org/libs/geometry/ DOC/HTML /幾何/參考/算法/ covered_by/covered_by_2.html)。 – ildjarn