简体   繁体   English

增强几何:使用开放间隔的交集

[英]Boost geometry : intersection using an open interval

I have a polyline and a line segment. 我有一条折线和一条线段。 One of the endpoints of the line segment is always also a point of the polyline. 线段的端点之一始终也是折线的点。

Example: line segment: (1,2),(3,3) polyline: (3,3),(10,10),(15,30) 示例:线段:(1,2),(3,3)折线:(3,3),(10,10),(15,30)

I want to use boost geometry in order to find whether the line segment and the polyline have an intersection. 我想使用升压几何来确定线段和折线是否有交点。 However, it is okay for them to intersect at the connected point. 但是,它们在连接点相交是可以的。 In this case, (3,3). 在这种情况下,(3,3)。

boost::geometry::intersects will always return true in this case. 在这种情况下, boost::geometry::intersects将始终返回true I would like to make an exception for the common point, but still have it return true if there is an intersection at any other point. 我想对公共点做一个例外,但是如果在其他任何点有交集,仍然让它返回true Is there a clever way to go about this? 有聪明的方法可以解决这个问题吗? Or do I have to use boost::geometry::intersection and iterate over the results? 还是我必须使用boost::geometry::intersection并遍历结果?

If I understood you correctly, you want to check if the segment intersects with polyline in point other than its connected point. 如果我对您的理解正确,则要检查线段是否在其连接点以外的点与折线相交。

So you need to check only segments that do not have shared endpoint with red segment (see picture). 因此,您只需要检查没有与红色段共享端点的段(请参见图片)。 You may skip those who do have same endpoint with red segment or you may want to handle them in a different way, for example, check if entire segments coincide. 您可以跳过那些具有相同端点的红色段的用户,或者您可能希望以不同的方式处理它们,例如,检查整个段是否重合。

I didn't work with c++ for a long time so I write pseudo code: 我很长时间没有使用c ++,所以我写了伪代码:

foreach (segment in polyline) {
    if (
        segment.A != redSegment.A &&
        segment.A != redSegment.B &&
        segment.B != redSegment.A &&
        segment.B != redSegment.B &&
        intersect (segment, redSegment)
    ) {
        return true;
    }
}
return false;

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM