Elmi
Elmi

Reputation: 6193

Rearrange single lines to form closed polygon?

assumed I have a rectangle:

A------B
|      |
|      |
D------C

Normally this rectangle is formed by an array of coordinates A-B-C-D-A which describe a closed polygon.

Now I do not have such an array but a bunch of separate lines B-A, D-A, B-C-D. When drawing both, the result is always the same rectangle but in second case much more data are used for it. So I want to rearrange and optimise the second case in order to get one single array of coordinates as in first case.

My question: is this possible somehow with boost::geometry or boost::polygon? If yes, how can this be done? If no: any other possibilities?

Thanks!

Upvotes: 1

Views: 135

Answers (1)

Adam Wulkiewicz
Adam Wulkiewicz

Reputation: 2098

No, there is no algorithm for this in Boost.Geometry.

However there are things that might help you with writing your own:

  • boost::geometry::equals() - check if a point is equal to another one, this is done WRT machine epsilon so you may consider using your own version strictly comparing coordinates
  • boost::geometry::intersects() - check if a linestring intersects some other one
  • boost::geometry::index::rtree<> - speed up the searching process
    • store the endpoints with the ids of the linestrings and search for equal points
    • store bounding boxes of linestrings and search for the corresponding linestrings
  • boost::geometry::envelope() - calculate a bounding box of a linestring
  • boost::geometry::correct() - check the orientation of a polygon/ring and reverse to match the type definition
  • boost::geometry::is_valid() - verify if the polygon/ring is valid (e.g. the edges don't cross other edges)

Upvotes: 1

Related Questions