41 template <
int N,
typename Real>
86 template <
int N,
typename Real>
90 template <
typename Real>
93 template <
typename Real>
97 template <
int N,
typename Real>
99 DCPQuery<Real, Vector<N, Real>, Hyperellipsoid<N, Real>>::operator()(
101 Hyperellipsoid<N, Real>
const& hyperellipsoid)
108 for (
int i = 0; i < N; ++i)
110 y[i] =
Dot(diff, hyperellipsoid.axis[i]);
116 result.sqrDistance = SqrDistance(hyperellipsoid.extent, y, x);
117 result.distance = sqrt(result.sqrDistance);
120 result.closest = hyperellipsoid.center;
121 for (
int i = 0; i < N; ++i)
123 result.closest += x[i] * hyperellipsoid.axis[i];
129 template <
int N,
typename Real>
130 typename DCPQuery<Real, Vector<N, Real>, Hyperellipsoid<N, Real>>::Result
131 DCPQuery<Real, Vector<N, Real>, Hyperellipsoid<N, Real>>::operator()(
135 result.sqrDistance = SqrDistance(extent, point, result.closest);
136 result.distance = sqrt(result.sqrDistance);
140 template <
int N,
typename Real>
141 Real DCPQuery<Real, Vector<N, Real>, Hyperellipsoid<N, Real>>::SqrDistance(
145 std::array<bool, N> negate;
147 for (i = 0; i < N; ++i)
149 negate[i] = (y[i] < (Real)0);
153 std::array<std::pair<Real, int>, N> permute;
154 for (i = 0; i < N; ++i)
156 permute[i].first = -e[i];
157 permute[i].second = i;
159 std::sort(permute.begin(), permute.end());
161 std::array<int, N> invPermute;
162 for (i = 0; i < N; ++i)
164 invPermute[permute[i].second] = i;
168 for (i = 0; i < N; ++i)
170 j = permute[i].second;
176 Real sqrDistance = SqrDistanceSpecial(locE, locY, locX);
179 for (i = 0; i < N; ++i)
192 template <
int N,
typename Real>
193 Real DCPQuery<Real, Vector<N, Real>, Hyperellipsoid<N, Real>>::
197 Real sqrDistance = (Real)0;
202 for (i = 0; i < N; ++i)
216 if (y[N - 1] > (Real)0)
218 sqrDistance = Bisector(numPos, ePos, yPos, xPos);
222 Vector<N - 1, Real> numer, denom;
223 Real eNm1Sqr = e[N - 1] * e[N - 1];
224 for (i = 0; i < numPos; ++i)
226 numer[i] = ePos[i] * yPos[i];
227 denom[i] = ePos[i] * ePos[i] - eNm1Sqr;
230 bool inSubHyperbox =
true;
231 for (i = 0; i < numPos; ++i)
233 if (numer[i] >= denom[i])
235 inSubHyperbox =
false;
240 bool inSubHyperellipsoid =
false;
247 Real discr = (Real)1;
248 for (i = 0; i < numPos; ++i)
250 xde[i] = numer[i] / denom[i];
251 discr -= xde[i] * xde[i];
257 sqrDistance = (Real)0;
258 for (i = 0; i < numPos; ++i)
260 xPos[i] = ePos[i] * xde[i];
261 Real diff = xPos[i] - yPos[i];
262 sqrDistance += diff*diff;
264 x[N - 1] = e[N - 1] * sqrt(discr);
265 sqrDistance += x[N - 1] * x[N - 1];
266 inSubHyperellipsoid =
true;
270 if (!inSubHyperellipsoid)
276 sqrDistance = Bisector(numPos, ePos, yPos, xPos);
281 for (i = 0, numPos = 0; i < N; ++i)
293 template <
int N,
typename Real>
294 Real DCPQuery<Real, Vector<N, Real>, Hyperellipsoid<N, Real>>::Bisector(
299 Real sumZSqr = (Real)0;
301 for (i = 0; i < numComponents; ++i)
304 sumZSqr += z[i] * z[i];
307 if (sumZSqr == (Real)1)
310 for (i = 0; i < numComponents; ++i)
317 Real emin = e[numComponents - 1];
319 for (i = 0; i < numComponents; ++i)
321 Real
p = e[i] / emin;
323 numerator[i] = pSqr[i] * z[i];
326 Real
s = (Real)0, smin = z[numComponents - 1] - (Real)1, smax;
327 if (sumZSqr < (Real)1)
335 smax =
Length(numerator,
true) - (Real)1;
342 for (
unsigned int j = 0; j < jmax; ++j)
344 s = (smin + smax) * (Real)0.5;
345 if (s == smin || s == smax)
351 for (i = 0; i < numComponents; ++i)
353 Real ratio = numerator[i] / (s + pSqr[i]);
361 else if (g < (Real)0)
371 Real sqrDistance = (Real)0;
372 for (i = 0; i < numComponents; ++i)
374 x[i] = pSqr[i] * y[i] / (s + pSqr[i]);
375 Real diff = x[i] - y[i];
376 sqrDistance += diff*diff;
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
static unsigned int GetMaxBisections()
GLsizei GLsizei GLfloat distance
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
GLdouble GLdouble GLdouble z
DualQuaternion< Real > Length(DualQuaternion< Real > const &d, bool robust=false)
Vector< N, Real > closest