简体   繁体   English

相交线Poly Boost几何

[英]Intersection Line Poly boost geometry

I want to calculate the intersection point between a line: 我想计算一条线之间的交点:

l := direction * x + origin for x e R or x e [0,R+)

and a default Boost polygon. 和默认的Boost多边形。 In the documentation I only found the possibility to get the intersection with a line Segment (fixed start and end point) 在文档中,我仅发现有可能与线段相交(固定的起点和终点)

At the moment I am using boost geometry and for intersection : http://www.boost.org/doc/libs/1_57_0/libs/geometry/doc/html/geometry/reference/algorithms/intersection.html 目前,我正在使用Boost几何并用于交集: http : //www.boost.org/doc/libs/1_57_0/libs/geometry/doc/html/geometry/reference/algorithms/intersection.html

Did I miss anything? 我有想念吗? Or do you know some boost function which I can use to solve my Problem. 还是您知道我可以用来解决我的问题的一些升压功能。


I tried a workaround with: 我尝试了一种解决方法:

  typedef boost::geometry::model::d2::point_xy<double> Point;
  typedef boost::geometry::model::segment<Point> Segment;
  Segment AB( Point{1,1*std::numeric_limits<double>::lowest()},Point{0,1*std::numeric_limits<double>::max()});
  boost::geometry::model::polygon<Point> poly;
  poly.outer().push_back(Point{0,0});
  poly.outer().push_back(Point{10,0});
  poly.outer().push_back(Point{10,10});
  poly.outer().push_back(Point{0,10});
  poly.outer().push_back(Point{0,0});
  std::vector<Segment> result;
  boost::geometry::intersection(AB,poly,result);

I am using boost 1.56 and get the error that this is not implemented yet. 我正在使用boost 1.56,并得到尚未实现的错误。 Do you know where I can found a list of which intersection are implemented? 您知道在哪里可以找到实施了哪些路口的列表吗? Or do know have some new idea? 还是知道有一些新想法?

Boost.Geometry doesn't have an intinite Line or Ray concept. Boost.Geometry没有无限线或射线概念。 So indeed you need to use a Segment or Linestring for this. 因此,确实需要为此使用细分或线串。 Using Segment indeed looks as the best way but it just may be not supported by intersection() now. 确实,使用Segment看起来是最好的方法,但是,交集()现在可能不支持它。 You can create a ticket with a feature request if you need it badly. 如果非常需要,可以使用功能请求创建故障单。 For now you could use Linestring instead of a Segment to define a line. 现在,您可以使用Linestring而不是Segment来定义线。 To store a result you could either use MultiLinestring or a vector of Points. 要存储结果,可以使用MultiLinestring或Points向量。 In the second case you'll get the intersection points so AFAIU exactly what you need: 在第二种情况下,您将获得相交点,因此AFAIU正是您需要的:

typedef boost::geometry::model::d2::point_xy<double> Point;
typedef boost::geometry::model::linestring<Point> Linestring;
typedef boost::geometry::model::polygon<Point> Polygon;

Linestring ls;
Polygon poly;
std::vector<Point> result;
boost::geometry::intersection(ls,poly,result);

If the above didn't compile you should use more recent version of Boost. 如果以上方法无法编译,则应使用最新版本的Boost。

You probably shouldn't create a Linestring containing double's lowest/max. 您可能不应该创建包含double的最低/最高值的Linestring。 It's because you'd get massive numeric errors. 这是因为您会收到大量的数字错误。 The closer the points of a segment the better. 段的点越近越好。 You could for instance manually calculate points of the segment being an intersection of a line and Polgon's bounding box or bounding sphere, etc. 例如,您可以手动计算线段与Polgon的边界框或边界球的交点等线段的点。

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

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