Thanks Adam. I did use bg::reverse to reverse when necessary.
Sorry that I still encounter a problem with the intesection() function. It got me weird results when the line just right across the vertices of the polygon.
Here is what I did, trying to make it clear.
1. In my program, the intersection between line and polygon is zero. So I print out the polygon and the linestring. (Actually from my visualization, it should has one intersection at (9.29497, 2.29204))
terminal printout:
Linestring: ((10, 3.43403), (8.4973, 1))
Polygon: (((7, 1.52705), (2.06343, 3.17257), (5.16667, 5.5), (7.69098, 5.5), (9.29497, 2.29204), (7, 1.52705)))
2. I reconstruct polygon and linestring using the above printout value, and redo the intersection(), weird thing happened, it got me two same intersection points.
terminal printout:
Intersections: ((9.29497, 2.29204), (9.29497, 2.29204))
3. I compare the polygon/linestring in my program and the reconstructed polygon/linestring, it says these two are not even equal.
code:
std::cout << "Polygons are spatially " << (boost::geometry::equals(poly1, poly2) ? "equal" : "not equal") << std::endl;
std::cout << "Lines are spatially " << (boost::geometry::equals(line1, line2) ? "equal" : "not equal") << std::endl;
terminal printout:
Polygons are spatially not equal
Lines are spatially not equal
It really got me here. How come the geometry I re-constructed from the printout is not equal to the original? The code I used to re-construct is as follows:
bgPolygon poly2{{{7, 1.52705},
{2.06343, 3.17257},
{5.16667, 5.5},
{7.69098, 5.5},
{9.29497, 2.29204},
{7, 1.52705}}}; // C++11 initialization list support
bg::correct(poly2); // make it clockwise and closed polygon
bgLinestring line2{{10, 3.43403}, {8.4973, 1.0}};
Could you help me on this issue?