Is it possible to introduce some tolerance with the intersection algorithm, such that close points or almost colinear lines are considered parallel? To be concrete:
I have two line segments that should be considered parallel, however, due to some accuracy problems while doing floating point calculations, the line segments are not entirely parallel, the error is 3.78e-14 which should - by all means - be considered parallel in my case: so boost's intersection should give me two points. However this is not the case and intersection regards those lines as not parallel. Example:
This is very similar to this question. This post is old and doesn't seem to satisfy me needs though. I'm confused as to how the intersection algorithm works in boost, too. I tried to find the code in boosts library but without success. Boosts code base is terrifying.
struct Point {
double x, y;
Point(double x_, double y_) : x(x_), y(y_) {};
}
BOOST_GEOMETRY_REGISTER_POINT_2D(Point, double, boost::geometry::cs::cartesian, x, y);
typedef boost::geometry::model::segment<Point> Segment;
Segment seg1({ -1012600, 9641189 }, { -935132, 9595186.14285714179277420043945 });
Segment seg2({ -1012600, 9641189 }, { -877031, 9560684 });
std::vector<Point> out;
boost::geometry::intersection(seg1, seg2, out);
Since I consider both segments as parallel, the expected output should be:
{ -1012600, 9641189 }, { -935132, 9595186.14285714179277420043945 }
Intersection indeed gives two points in a parallel case: See for example:
Segment seg1({0, 0}, {6, 6});
Segment seg2({2, 2}, {3, 3});
boost::geometry::intersection(seg1, seg2, out);
Will give:
{2, 2}, {3, 3}