ContinuousTriangleIntersection.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef SOFA_COMPONENT_COLLISION_CONTINUOUSTRIANGLEINTERSECTION_H
00026 #define SOFA_COMPONENT_COLLISION_CONTINUOUSTRIANGLEINTERSECTION_H
00027 #include <sofa/component/collision/Triangle.h>
00028 #include <sofa/core/componentmodel/collision/DetectionOutput.h>
00029 #include <math.h>
00030
00031 #define cbrt(x) ((x) > (SReal)0.0 ? pow((SReal)(x), (SReal)1.0/(SReal)3.0) : \
00032 ((x) < (SReal)0.0 ? -pow((SReal)-(x), (SReal)1.0/(SReal)3.0) : (SReal)0.0))
00033 #define EPSILON 0.000001
00034
00035 #define EQN_EPS 1e-9
00036 #define IsZero(x) ((x) > -EQN_EPS && (x) < EQN_EPS)
00037
00038 namespace sofa
00039 {
00040
00041 namespace component
00042 {
00043
00044 namespace collision
00045 {
00046
00047 using namespace collision;
00048
00049 class ContinuousTriangleIntersection
00050 {
00051 private:
00052 Triangle &tr1, &tr2;
00053 SReal m_tolerance, m_tolmin, m_tolmax;
00054
00055 int intersectPointTriangle (SReal& t, SReal& u, SReal& v,
00056 const Vector3& p0, const Vector3& v0,
00057 const Vector3& p1, const Vector3& v1,
00058 const Vector3& p2, const Vector3& v2,
00059 const Vector3& p3, const Vector3& v3,
00060 double dt);
00061
00062 int intersectEdgeEdge(SReal& t, SReal& u, SReal& v,
00063 const Vector3& p1, const Vector3& p2,
00064 const Vector3& v1, const Vector3& v2,
00065 const Vector3& p3, const Vector3& p4,
00066 const Vector3& v3, const Vector3& v4,
00067 double dt);
00068
00069 int solveCubic(Vector3& s, SReal c[4]);
00070
00071 int solveQuadratic (SReal& t1, SReal& t2,
00072 const SReal& a,
00073 const SReal& b,
00074 const SReal& c);
00075
00076 bool checkValidRoots (SReal& validRoot,
00077 const int& numRoots,
00078 const Vector3& roots,
00079 const SReal& rootMin,
00080 const SReal& rootMax);
00081
00084 bool checkRange (const SReal& val,
00085 const SReal& min,
00086 const SReal& max)
00087 {
00088 return ((val >= min) && (val <= max));
00089 };
00090
00093 inline SReal getMinVal (const SReal& val0, const SReal& val1)
00094 {
00095 return (val0 < val1) ? val0 : val1;
00096 };
00097
00100 SReal getMinVal(const SReal &val0,
00101 const SReal &val1,
00102 const SReal &val2)
00103 {
00104 if (val0 < val1)
00105 {
00106 return (val0 < val2) ? val0 : val2;
00107 }
00108 else
00109 {
00110 return (val1 < val2) ? val1 : val2;
00111 }
00112 };
00113
00116 void setTolerance(const SReal &tol)
00117 {
00118 m_tolerance = tol;
00119 m_tolmin = -m_tolerance;
00120 m_tolmax = (SReal)1.0 + m_tolerance;
00121 };
00122
00123 public:
00124 ContinuousTriangleIntersection (Triangle& t1, Triangle& t2);
00125 ~ContinuousTriangleIntersection(void);
00126 core::componentmodel::collision::DetectionOutput* computeDetectionOutput (void);
00127 bool isCollision(void);
00128 };
00129
00130 }
00131
00132 }
00133
00134 }
00135
00136
00137 #endif