I'm trying to determine the point of intersection between two 3d linestring using Boost, but in certain cases I'm not getting the expected result.
From my understanding [1], Boost should be calculating the intersection using Map geometry - that is, the Z coordinate is not considered. This is the functionality I'm after.
However, my testing shows if one linestring is always above the other (case 1 in the code listing below), then I get no intersections.
But, if the second line crosses the plane containing the first line - case 2 - then an intersection is found - even though the two lines don't intersect in 3d space.
Is my understanding wrong? Or, is there a way to make case 1 work?
My workaround has been to ensure the first linestring will always cross the plane of the second... But it seems hacky.
Thanks
#include <iostream>
#include <vector>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/algorithms/intersection.hpp>
namespace bg = boost::geometry;
int main()
{
typedef bg::model::point<double, 3, bg::cs::cartesian> point_t;
typedef bg::model::linestring<point_t> linestring_t;
linestring_t ls1{{0, 0, 1}, {1, 1, 1}};
linestring_t ls2{{0, 1, 0}, {1, 0, 0}};
linestring_t ls3{{0, 1, 0}, {1, 0, 1}};
std::vector<point_t> intersections;
bg::intersection(ls1, ls2, intersections);
std::cout << "Case 1: Intersection between l1 and l2? " << (intersections.size() > 0 ? "Yes" : "No") << std::endl;
bg::intersection(ls1, ls3, intersections);
std::cout << "Case 2: Intersection between l1 and l3? " << (intersections.size() > 0 ? "Yes" : "No") << std::endl;
return 0;
}
output:
Case 1: Intersection between l1 and l2? No
Case 2: Intersection between l1 and l3? Yes
References:
[1] "How to intersection to 3D polygons by Boost C++ library?", https://stackoverflow.com/a/49012544/338230