18 #include <boost/math/special_functions/fpclassify.hpp>
36 OPlan::OPlan(
double a,
double b,
double c,
double d) : _a(a), _b(b), _c(
c), _d(d)
109 pt3.
_x * (pt1.
_y * pt2.
_z - pt2.
_y * pt1.
_z));
124 return _a == 0 &&
_b == 0 &&
_c == 0;
129 return (boost::math::isnan(
_a) || boost::math::isnan(
_b) || boost::math::isnan(
_c) ||
130 boost::math::isnan(
_d));
138 #define ___XBH_VERSION
139 #ifdef ___XBH_VERSION
145 double xSeg = pt2.
_x - pt1.
_x;
146 double ySeg = pt2.
_y - pt1.
_y;
147 double zSeg = pt2.
_z - pt1.
_z;
149 double ps = xSeg *
_a + ySeg *
_b + zSeg *
_c;
156 t = -(ps1 +
_d) / ps;
159 if ((t >= 0) && (t <= 1))
161 ptIntersec.
_x = pt1.
_x + t * (pt2.
_x - pt1.
_x);
162 ptIntersec.
_y = pt1.
_y + t * (pt2.
_y - pt1.
_y);
163 ptIntersec.
_z = pt1.
_z + t * (pt2.
_z - pt1.
_z);
165 ptIntersec.
_x =
ABS(ptIntersec.
_x) > 1E-6 ? ptIntersec.
_x : 0.00;
166 ptIntersec.
_y =
ABS(ptIntersec.
_y) > 1E-6 ? ptIntersec.
_y : 0.00;
167 ptIntersec.
_z =
ABS(ptIntersec.
_z) > 1E-6 ? ptIntersec.
_z : 0.00;
198 double ps = vecSeg.
scalar(n);
204 t = -(vecPt1.scalar(n) +
_d) / ps;
207 if ((t >= 0) && (t <= 1))
209 ptIntersec.
_x = pt1.
_x + t * (pt2.
_x - pt1.
_x);
210 ptIntersec.
_y = pt1.
_y + t * (pt2.
_y - pt1.
_y);
211 ptIntersec.
_z = pt1.
_z + t * (pt2.
_z - pt1.
_z);
213 ptIntersec.
_x =
ABS(ptIntersec.
_x) > 1E-6 ? ptIntersec.
_x : 0.00;
214 ptIntersec.
_y =
ABS(ptIntersec.
_y) > 1E-6 ? ptIntersec.
_y : 0.00;
215 ptIntersec.
_z =
ABS(ptIntersec.
_z) > 1E-6 ? ptIntersec.
_z : 0.00;
223 double z = vecPt1.scalar(n) +
_d;
263 double t = -(vecPt.
scalar(n) +
_d) / ps;
265 ptIntersec.
_x = pt.
_x + t * vector.
_x;
266 ptIntersec.
_y = pt.
_y + t * vector.
_y;
267 ptIntersec.
_z = pt.
_z + t * vector.
_z;
279 double Dxy =
_a * plan.
_b - plan.
_a *
_b;
280 double Dyz =
_b * plan.
_c - plan.
_b *
_c;
281 double Dzx =
_c * plan.
_a - plan.
_c *
_a;
285 vectorIntersec.
_x = Dyz / Dxy;
286 vectorIntersec.
_y = Dzx / Dxy;
287 vectorIntersec.
_z = 1.0;
291 vectorIntersec.
_x = 1.0;
292 vectorIntersec.
_y = Dzx / Dyz;
293 vectorIntersec.
_z = Dxy / Dyz;
297 vectorIntersec.
_x = Dyz / Dzx;
298 vectorIntersec.
_y = 1.0;
299 vectorIntersec.
_z = Dxy / Dzx;
303 vectorIntersec.
_x = vectorIntersec.
_y = vectorIntersec.
_z = 0;
310 double norme = vectorIntersec.
norme();
314 vectorIntersec.
_x /= norme;
315 vectorIntersec.
_y /= norme;
316 vectorIntersec.
_z /= norme;
326 bool ptAFind =
false, ptBFind =
false;
330 size_t nbPts = contour.size();
333 for (
size_t i = 0; i < nbPts; i++)
340 seg.
_ptA = ptIntersec;
346 if (ptIntersec == seg.
_ptA)
350 seg.
_ptB = ptIntersec;
365 double cosAngle = (
_a * plan.
_a +
_b * plan.
_b +
_c * plan.
_c) /
368 return acos(cosAngle);
384 double x1 = K *
_a + pt.
_x;
385 double y1 = K *
_b + pt.
_y;
386 double z1 = K *
_c + pt.
_z;
389 ptSym.
_x = 2 * x1 - pt.
_x;
390 ptSym.
_y = 2 * y1 - pt.
_y;
391 ptSym.
_z = 2 * z1 - pt.
_z;
403 ptProj.
_x = K *
_a + pt.
_x;
404 ptProj.
_y = K *
_b + pt.
_y;
405 ptProj.
_z = K *
_c + pt.
_z;
429 if (((
_a / plan.
_a) == (
_b / plan.
_b)) && ((
_b / plan.
_b) == (
_c / plan.
_c)))
439 if (((
_a * plan.
_a) + (
_b * plan.
_b) + (
_c * plan.
_c)) == 0)
451 assert(!
is_NaN() &&
"Trying to build a plane from NaN values !");
462 if (N.
dot(hint) > 0.9)
465 if (N.
dot(hint) > 0.9)
474 double h = hint.
dot(N);
477 assert(fabs(N.
dot(U)) < 0.001);
479 assert(fabs(V.
norme() - 1.0) < 0.01);
485 return os <<
"OPlan(" << p.
_a <<
", " << p.
_b <<
", " << p.
_c <<
", " << p.
_d <<
")";
All base classes related to 3D manipulation.
#define INTERS_CONFONDU
The elements match.
#define INTERS_OUI
The intersection exists.
double ABS(double a)
Return the absolute value.
std::vector< OPoint3D > TabPoint3D
#define INTERS_NULLE
No intersection.
double _y
y coordinate of OCoord3D
double _z
z coordinate of OCoord3D
double _x
x coordinate of OCoord3D
Plan defined by its equation : ax+by+cz+d=0.
int intersectsSegment(const OPoint3D &pt1, const OPoint3D &pt2, OPoint3D &ptIntersec) const
Calculate the intersection of this plane with a segment defined by two points.
double _a
The a parameter in the equation ax+by+cz+d=0.
double distance(const OPoint3D &pt)
Calculation of the minimal distance between a point and this plane.
double _c
The c parameter in the equation ax+by+cz+d=0.
bool operator!=(const OPlan &plan) const
The inequality operator.
double _d
The d parameter in the equation ax+by+cz+d=0.
bool isInPlan(const OPoint3D &pt)
Check if a point belongs to a plane.
virtual ~OPlan()
Destructor.
bool operator==(const OPlan &plan) const
The equality operator.
void update_explicit_repr(OVector3D hint=OVector3D(1, 1, 1))
updates the implicit representation of the plane
bool isOrthogonal(const OPlan &plan)
Check if this plan is perpendicular to another plan.
OPlan()
Default constructor With a=b=c=d=0.
double _b
The b parameter in the equation ax+by+cz+d=0.
double angle(const OPlan &plan)
Calculation of the angle between this plane and another plane.
OPoint3D projPtPlan(const OPoint3D &pt)
Calculate the projection of a point on the plane.
bool isParallel(const OPlan &plan)
Check if this plane is parallel with another plane.
void set(double a, double b, double c, double d)
Sets a, b, c and d parameters directly.
bool distancePlanParallel(const OPlan &plan, double &distance)
Calculate the distance between this plan and another parallel plane.
int intersectsSurface(const TabPoint3D &contour, OSegment3D &segment) const
Compute intersection between a plan and a surface defined by his bounds.
int intersectsPlan(const OPlan &plan, OVector3D &vectorIntersec)
Calculate the intersection of this plane with another plane.
int intersectsDroite(const OPoint3D &pt, const OVector3D &vector, OPoint3D &ptIntersec)
Calculate the intersection of this plane with a line defined by a point and a vector.
bool is_valid()
Check whether the plane is valid.
OPlan & operator=(const OPlan &plan)
Assignment operator.
OPoint3D symPtPlan(const OPoint3D &pt)
Calculate the symmetrical of a point relative to the plane.
void set(const OPoint3D &origin, const OVector3D &vecI, const OVector3D &vecJ, const OVector3D &vecK)
Sets with a point and 3 vectors.
Class to define a segment.
OPoint3D _ptA
Point A of the segment.
OPoint3D _ptB
Point B of the segment.
double norme() const
Computes the length of this vector.
void normalize()
Normalizes this vector.
double scalar(const OVector3D &vector) const
Performs the scalar product between this object and another vector.
OVector3D cross(const OVector3D &vector) const
Cross product.
double dot(const OVector3D &v)
dot product (assuming an orthonormal reference frame)
::std::ostream & operator<<(::std::ostream &os, const OPlan &p)