Question

I've been trying to code an algorithm using the Boost geometry library (trying to code a box counting algorithm if that matters) and part of it consists in handling a polygon. Though I'd like to compute the intersection of the boundary of the polygon with a large number of boxes (a meshing), its exterior ring if you prefer. Strangely the functions intersects(box[i], polygon) intersects(box[i], exterior_ring(polygon)) and within(box[i],polygon) give me the same result. For a box completely inside the polygon I should get true, false, true for example. For one on the boundary true, true, false. How come it doesn't compute it the way I think it should?

Was it helpful?

Solution

Your question is about 3 functions:

  1. intersects (box, polygon)
  2. intersects (box, ring)
  3. within (box, ring)

Let me start from #3. The function within only supports box-box and box-point input. It means ring is implicitly converted to its bounding box, and the answers you get are correct (when one box is within another they are considered as intersecting as geometric shapes).

For #2 it seems you want to get "false" even if box is within a ring. It means you want to consider ring (contour) as a polyline (aka "linestring"). You should explain to Boost.Geometry to consider a ring as a linestring.

To do so, you can probably "wrap" your contour (or ring) point container into some class and then register this class as a linestring (or as multi-linestring). The class itself could be very light-weight, simply keeping a pointer to the container and providing proper const-access. You register this class as a linestring using a macro BOOST_GEOMETRY_REGISTER_LINESTRING or BOOST_GEOMETRY_REGISTER_MULTI_LINESTRING.

After that you pass it to "intersects" roughly as intersects(my_linestring_wrapper(polygon), box_view(box[i])). Here the code box_view(box[i]) will return a light-weight object which behaves as a "ring" (a contour).

For #1 you can get box-box or ring-ring intersection. To force the latter, you need to consider the box as a ring. Standard way to achieve this in Boost.Geometry is to apply a proper "view" to the box.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top