15 template <
typename Real>
22 Real triangle0Parameter[3], triangle1Parameter[3];
31 template <
typename Real>
41 result.sqrDistance = std::numeric_limits<Real>::max();
44 for (
int i0 = 2, i1 = 0; i1 < 3; i0 = i1++)
48 Vector3<Real> segDirection = triangle0.v[i1] - triangle0.v[i0];
49 Real segExtent = ((Real)0.5)*
Normalize(segDirection);
52 stResult = stQuery(edge, triangle1);
53 if (stResult.sqrDistance < result.sqrDistance)
55 result.distance = stResult.distance;
56 result.sqrDistance = stResult.sqrDistance;
57 Real ratio = stResult.segmentParameter / segExtent;
58 result.triangle0Parameter[i0] = ((Real)0.5)*((Real)1 - ratio);
59 result.triangle0Parameter[i1] =
60 (Real)1 - result.triangle0Parameter[i0];
61 result.triangle0Parameter[3 - i0 - i1] = (Real)0;
62 result.triangle1Parameter[0] = stResult.triangleParameter[0];
63 result.triangle1Parameter[1] = stResult.triangleParameter[1];
64 result.triangle1Parameter[2] = stResult.triangleParameter[2];
65 result.closestPoint[0] = stResult.closestPoint[0];
66 result.closestPoint[1] = stResult.closestPoint[1];
71 for (
int i0 = 2, i1 = 0; i1 < 3; i0 = i1++)
75 Vector3<Real> segDirection = triangle1.v[i1] - triangle1.v[i0];
76 Real segExtent = ((Real)0.5)*
Normalize(segDirection);
79 stResult = stQuery(edge, triangle0);
80 if (stResult.sqrDistance < result.sqrDistance)
82 result.distance = stResult.distance;
83 result.sqrDistance = stResult.sqrDistance;
84 Real ratio = stResult.segmentParameter / segExtent;
85 result.triangle0Parameter[0] = stResult.triangleParameter[0];
86 result.triangle0Parameter[1] = stResult.triangleParameter[1];
87 result.triangle0Parameter[2] = stResult.triangleParameter[2];
88 result.triangle1Parameter[i0] = ((Real)0.5)*((Real)1 - ratio);
89 result.triangle1Parameter[i1] =
90 (Real)1 - result.triangle0Parameter[i0];
91 result.triangle1Parameter[3 - i0 - i1] = (Real)0;
92 result.closestPoint[0] = stResult.closestPoint[0];
93 result.closestPoint[1] = stResult.closestPoint[1];
GLsizei GLsizei GLfloat distance
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
Real Normalize(GVector< Real > &v, bool robust=false)