18 template <
typename Real>
25 Real lineParameter, triangleParameter[3];
34 template <
typename Real>
45 Real NdD =
Dot(normal, line.direction);
52 basis[0] = line.direction;
53 ComputeOrthogonalComplement<Real>(1, basis);
54 Real UdE0 =
Dot(basis[1], edge0);
55 Real UdE1 =
Dot(basis[1], edge1);
56 Real UdDiff =
Dot(basis[1], diff);
57 Real VdE0 =
Dot(basis[2], edge0);
58 Real VdE1 =
Dot(basis[2], edge1);
59 Real VdDiff =
Dot(basis[2], diff);
60 Real invDet = ((Real)1) / (UdE0*VdE1 - UdE1*VdE0);
63 Real b1 = (VdE1*UdDiff - UdE1*VdDiff)*invDet;
64 Real b2 = (UdE0*VdDiff - VdE0*UdDiff)*invDet;
65 Real b0 = (Real)1 - b1 - b2;
67 if (b0 >= (Real)0 && b1 >= (Real)0 && b2 >= (Real)0)
70 Real DdE0 =
Dot(line.direction, edge0);
71 Real DdE1 =
Dot(line.direction, edge1);
72 Real DdDiff =
Dot(line.direction, diff);
73 result.lineParameter = b1*DdE0 + b2*DdE1 - DdDiff;
76 result.triangleParameter[0] = b0;
77 result.triangleParameter[1] = b1;
78 result.triangleParameter[2] = b2;
81 result.closestPoint[0] = line.origin +
82 result.lineParameter*line.direction;
83 result.closestPoint[1] = triangle.v[0] + b1*edge0 + b2*edge1;
85 result.distance = (Real)0;
86 result.sqrDistance = (Real)0;
96 result.distance = std::numeric_limits<Real>::max();
97 result.sqrDistance = std::numeric_limits<Real>::max();
98 for (
int i0 = 2, i1 = 0; i1 < 3; i0 = i1++)
102 Vector3<Real> segDirection = triangle.v[i1] - triangle.v[i0];
103 Real segExtent = ((Real)0.5)*
Normalize(segDirection);
107 auto lsResult =
query(line, segment);
108 if (lsResult.sqrDistance < result.sqrDistance)
110 result.sqrDistance = lsResult.sqrDistance;
111 result.distance = lsResult.distance;
112 result.lineParameter = lsResult.parameter[0];
113 result.triangleParameter[i0] = ((Real)0.5)*((Real)1 -
114 lsResult.parameter[0] / segExtent);
115 result.triangleParameter[i1] = (Real)1 -
116 result.triangleParameter[i0];
117 result.triangleParameter[3 - i0 - i1] = (Real)0;
118 result.closestPoint[0] = lsResult.closestPoint[0];
119 result.closestPoint[1] = lsResult.closestPoint[1];
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
Vector< N, Real > UnitCross(Vector< N, Real > const &v0, Vector< N, Real > const &v1, bool robust=false)
GLsizei GLsizei GLfloat distance
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
Real Normalize(GVector< Real > &v, bool robust=false)