diff --git a/visilib/math_geometry.h b/visilib/math_geometry.h index fd87899..542c5f3 100644 --- a/visilib/math_geometry.h +++ b/visilib/math_geometry.h @@ -132,7 +132,8 @@ namespace visilib intersection point: t = - (a * aBegin.x + b * aBegin.y + c * aBegin.z + d)/(a * aDirection.x + b* aDirection.y + z * aDirection.z); = - (myPlaneDirection.dotProduct(myDir) + w) / (myPlaneDirection.dotProduct(myDir)); */ - static bool getPlaneIntersection(const MathPlane3_& plane, const MathVector3_& aBegin, const MathVector3_& aDirection, MathVector3_& anIntersection, double epsilon); + template + static bool getPlaneIntersection(const MathPlane3_& plane, const MathVector3_& aBegin, const MathVector3_& aDirection, MathVector3_& anIntersection, double epsilon); /** @brief Compute if a polygon is intersected by a plane */ static bool intersect(const GeometryConvexPolygon& polygon, const MathPlane3d& aPlane); @@ -738,20 +739,21 @@ namespace visilib return getBackTo3D(aPoint, plane1, plane2); } - inline bool MathGeometry::getPlaneIntersection(const MathPlane3_ & plane, const MathVector3_ & aBegin, const MathVector3_ & aDirection, MathVector3_ & anIntersection, double tolerance) + template + inline bool MathGeometry::getPlaneIntersection(const MathPlane3_ & plane, const MathVector3_ & aBegin, const MathVector3_ & aDirection, MathVector3_ & anIntersection, double tolerance) { anIntersection = aBegin; - MathVector3_ myDir(aDirection); + MathVector3_ myDir(aDirection); - double lambda = -(plane.dot(aBegin)); - double div = plane.mNormal.dot(myDir); + S lambda = -(plane.dot(aBegin)); + S div = plane.mNormal.dot(myDir); - if (MathArithmetic::getAbs(div) > tolerance) + if (MathArithmetic::getAbs(div) > tolerance) { lambda /= div; myDir *= lambda; anIntersection += myDir; - V_ASSERT(MathArithmetic::getAbs(plane.dot(anIntersection)) <= tolerance); + V_ASSERT(MathArithmetic::getAbs(plane.dot(anIntersection)) <= tolerance); return true; }