Skip to content
Snippets Groups Projects
Commit ce4911e3 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[GL] Use exact predicate for 2D orientation.

The predicate is correct but slower than the homegrown solution.
parent 52e4d1bc
No related branches found
No related tags found
No related merge requests found
......@@ -44,25 +44,15 @@ double getOrientation2d(MathLib::Point3d const& a,
namespace GeoLib
{
Orientation getOrientation(const double& p0_x, const double& p0_y, const double& p1_x,
const double& p1_y, const double& p2_x, const double& p2_y)
{
double h1((p1_x - p0_x) * (p2_y - p0_y));
double h2((p2_x - p0_x) * (p1_y - p0_y));
double tol(std::numeric_limits<double>::epsilon());
if (fabs(h1 - h2) <= tol * std::max(fabs(h1), fabs(h2)))
return COLLINEAR;
if (h1 - h2 > 0.0)
return CCW;
return CW;
}
Orientation getOrientation(const GeoLib::Point* p0, const GeoLib::Point* p1,
const GeoLib::Point* p2)
{
return getOrientation((*p0)[0], (*p0)[1], (*p1)[0], (*p1)[1], (*p2)[0], (*p2)[1]);
double const orientation = ExactPredicates::getOrientation2d(*p0, *p1, *p2);
if (orientation > 0)
return CCW;
if (orientation < 0)
return CW;
return COLLINEAR;
}
bool parallel(MathLib::Vector3 v, MathLib::Vector3 w)
......@@ -380,8 +370,8 @@ std::vector<MathLib::Point3d> lineSegmentIntersect2d(
GeoLib::Point const& c{cd.getBeginPoint()};
GeoLib::Point const& d{cd.getEndPoint()};
double const orient_abc(ExactPredicates::getOrientation2d(a, b, c));
double const orient_abd(ExactPredicates::getOrientation2d(a, b, d));
double const orient_abc(getOrientation(a, b, c));
double const orient_abd(getOrientation(a, b, d));
// check if the segment (cd) lies on the left or on the right of (ab)
if ((orient_abc > 0 && orient_abd > 0) || (orient_abc < 0 && orient_abd < 0)) {
......@@ -497,8 +487,8 @@ std::vector<MathLib::Point3d> lineSegmentIntersect2d(
}
// check if the segment (ab) lies on the left or on the right of (cd)
double const orient_cda(ExactPredicates::getOrientation2d(c, d, a));
double const orient_cdb(ExactPredicates::getOrientation2d(c, d, b));
double const orient_cda(getOrientation(c, d, a));
double const orient_cdb(getOrientation(c, d, b));
if ((orient_cda > 0 && orient_cdb > 0) || (orient_cda < 0 && orient_cdb < 0)) {
return std::vector<MathLib::Point3d>();
}
......
......@@ -37,20 +37,13 @@ enum Orientation
};
/**
* computes the orientation of the three 2D-Points given by their coordinates
* p0_x, p0_y, p1_x, p1_y, p2_x and p2_y
* \returns CW (clockwise), CCW (counterclockwise) or COLLINEAR (points are on a line)
* Computes the orientation of the three 2D-Points.
* \returns CW (clockwise), CCW (counterclockwise) or COLLINEAR (points are on a
* line)
*/
Orientation getOrientation (const double& p0_x, const double& p0_y,
const double& p1_x, const double& p1_y,
const double& p2_x, const double& p2_y);
/**
* wrapper for getOrientation ()
*/
Orientation getOrientation (const GeoLib::Point* p0,
const GeoLib::Point* p1,
const GeoLib::Point* p2);
Orientation getOrientation(const GeoLib::Point* p0,
const GeoLib::Point* p1,
const GeoLib::Point* p2);
/**
* compute a supporting plane (represented by plane_normal and the value d) for the polygon
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment