2016-10-08 27 views
1

我试图用Boost.Geometry图书馆找方和线的交点的第二点,Boost.Geometry没有找到多边形线intersecion

model::ring<model::d2::point_xy<double>> ring { {0, 0}, {2, 0}, {2, 2}, {0, 2} }; 
model::polygon<model::d2::point_xy<double>> pol; 
pol.inners().push_back (ring); 

model::linestring<model::d2::point_xy<double>> line { {1, 3}, {-1, -1} }; 

model::multi_point<model::d2::point_xy<double>> out; 

intersection (pol, line, out); //out returns only {0.5, 2}, but not {0, 1} 

但它返回只有一个点, althougt居然有交集

enter image description here

我怎样才能找到交集的所有点的两个点?

回答

2

闭上你的戒指,并把它按预期的顺序(默认为顺时针,see default template parameters):

model::ring<model::d2::point_xy<double>> ring { 
    {0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0} 
}; 

戒指是无效的,即不是fullfilling指定模板参数的要求。

As per documentation (see under rules)使用一个无效的几何作为输入可能会给出错误的结果,并且有效性既没有被算法校验也没有被校正。

戒指在施工或第一次使用之前也不会自动关闭(它应该如何知道你不会追加更多分数?)。 Here是一个重复关闭点的示例结构。

然而有is_validcorrect来解决这个问题。

您也可能想要将点指向外环,即pol.outer()。你的多边形需要有一个外部环,内部环决定了孔。你可以直接构造没有内环的多边形:

model::polygon<model::d2::point_xy<double>> pol { 
    { {0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0} } 
}; 
+1

谢谢,这是工程。但环已经有参数闭合,这是默认情况下,我认为这只是针对这些情况。是否被交集算法忽略? – user3514538