24 template <
typename Real>
44 SCPolynomial(Real oneTerm, Real cosTerm, Real sinTerm);
49 SCPolynomial
operator+(SCPolynomial
const&
object)
const;
50 SCPolynomial
operator-(SCPolynomial
const&
object)
const;
51 SCPolynomial
operator*(SCPolynomial
const&
object)
const;
52 SCPolynomial
operator*(Real scalar)
const;
64 bool operator< (ClosestInfo
const& info)
const 66 return sqrDistance < info.sqrDistance;
77 template <
typename Real>
84 Real
const zero = (Real)0;
87 Real r0 = circle0.radius, r1 = circle1.radius;
94 Real
const one = (Real)1, two = (Real)2;
95 Real r0sqr = r0 * r0, r1sqr = r1 * r1;
99 basis[0] = circle1.normal;
106 Real a0 = r1 *
Dot(D, U1), a1 = r1 *
Dot(D, V1);
107 Real a2 =
Dot(N0xD, N0xD), a3 = r1 *
Dot(N0xD, N0xU1);
108 Real a4 = r1 *
Dot(N0xD, N0xV1), a5 = r1sqr *
Dot(N0xU1, N0xU1);
109 Real a6 = r1sqr *
Dot(N0xU1, N0xV1), a7 = r1sqr *
Dot(N0xV1, N0xV1);
127 unsigned int const maxIterations =
129 Real roots[8], sn, temp;
130 int i, degree, numRoots;
134 std::set<Real> uniqueRoots;
136 std::array<std::pair<Real, Real>, 16> pairs;
142 degree =
static_cast<int>(phi.
GetDegree());
143 LogAssert(degree > 0,
"Unexpected degree for phi.");
145 maxIterations, roots);
146 for (i = 0; i < numRoots; ++i)
148 uniqueRoots.insert(roots[i]);
151 for (
auto cs : uniqueRoots)
159 pairs[numPairs++] = std::make_pair(cs, sn);
163 temp = std::max(one - cs * cs, zero);
165 pairs[numPairs++] = std::make_pair(cs, sn);
168 pairs[numPairs++] = std::make_pair(cs, -sn);
177 degree =
static_cast<int>(p6.
GetDegree());
178 LogAssert(degree > 0,
"Unexpected degree for p6.");
180 maxIterations, roots);
181 for (i = 0; i < numRoots; ++i)
183 uniqueRoots.insert(roots[i]);
186 for (
auto cs : uniqueRoots)
190 temp = std::max(one - cs * cs, zero);
192 pairs[numPairs++] = std::make_pair(cs, sn);
195 pairs[numPairs++] = std::make_pair(cs, -sn);
201 std::array<ClosestInfo, 16> candidates;
202 for (i = 0; i < numPairs; ++i)
204 ClosestInfo& info = candidates[i];
206 D + r1 * (pairs[i].first * U1 + pairs[i].second * V1);
207 info.circle1Closest = circle0.center + delta;
208 Real N0dDelta =
Dot(N0, delta);
212 Real diff = lenN0xDelta - r0;
213 info.sqrDistance = N0dDelta * N0dDelta + diff * diff;
214 delta -= N0dDelta * circle0.normal;
216 info.circle0Closest = circle0.center + r0 * delta;
217 info.equidistant =
false;
223 info.sqrDistance =
Dot(diff, diff);
224 info.circle0Closest = circle0.center + r0U0;
225 info.equidistant =
true;
229 std::sort(candidates.begin(), candidates.begin() + numPairs);
231 result.numClosestPairs = 1;
232 result.sqrDistance = candidates[0].sqrDistance;
233 result.circle0Closest[0] = candidates[0].circle0Closest;
234 result.circle1Closest[0] = candidates[0].circle1Closest;
235 result.equidistant = candidates[0].equidistant;
237 && candidates[1].sqrDistance == candidates[0].sqrDistance)
239 result.numClosestPairs = 2;
240 result.circle0Closest[1] = candidates[1].circle0Closest;
241 result.circle1Closest[1] = candidates[1].circle1Closest;
251 DoQueryParallelPlanes(circle0, circle1, D, result);
258 template <
typename Real>
279 distance = dmr1 - r0;
280 result.numClosestPairs = 1;
281 result.circle0Closest[0] = circle0.
center + r0 * U;
282 result.circle1Closest[0] = circle1.
center - r1 * U;
283 result.equidistant =
false;
292 distance = r0 - dpr1;
293 result.numClosestPairs = 1;
296 result.circle0Closest[0] = circle0.
center + r0 * U;
297 result.circle1Closest[0] = circle1.
center + r1 * U;
298 result.equidistant =
false;
305 result.circle0Closest[0] = circle0.
center + r0 * U;
306 result.circle1Closest[0] = circle1.
center + r1 * U;
307 result.equidistant =
true;
310 else if (dmr1 <= -r0)
313 distance = -r0 - dmr1;
314 result.numClosestPairs = 1;
317 result.circle0Closest[0] = circle0.
center - r0 * U;
318 result.circle1Closest[0] = circle1.
center - r1 * U;
319 result.equidistant =
false;
326 result.circle0Closest[0] = circle0.
center + r0 * U;
327 result.circle1Closest[0] = circle1.
center + r1 * U;
328 result.equidistant =
true;
336 Real r0sqr = r0 * r0, r1sqr = r1 * r1, dsqr = d * d;
337 Real
s = ((Real)1 + (r0sqr - r1sqr) / dsqr) / (Real)2;
338 Real arg = std::max(r0sqr - dsqr * s * s, (Real)0);
343 result.numClosestPairs = 2;
344 result.circle0Closest[0] = midpoint + hNxU;
345 result.circle0Closest[1] = midpoint - hNxU;
346 result.circle1Closest[0] = result.circle0Closest[0] + normProj;
347 result.circle1Closest[1] = result.circle0Closest[1] + normProj;
348 result.equidistant =
false;
352 result.sqrDistance = distance * distance + N0dD * N0dD;
355 template <
typename Real>
360 template <
typename Real>
362 Real oneTerm, Real cosTerm, Real sinTerm)
368 template <
typename Real>
inline 371 unsigned int i)
const 376 template <
typename Real>
inline 384 template <
typename Real>
385 typename DCPQuery<Real, Circle3<Real>,
Circle3<Real>>::SCPolynomial
387 SCPolynomial
const&
object)
const 390 result.mPoly[0] = mPoly[0] +
object.mPoly[0];
391 result.mPoly[1] = mPoly[1] +
object.mPoly[1];
395 template <
typename Real>
396 typename DCPQuery<Real, Circle3<Real>,
Circle3<Real>>::SCPolynomial
398 SCPolynomial
const&
object)
const 401 result.mPoly[0] = mPoly[0] -
object.mPoly[0];
402 result.mPoly[1] = mPoly[1] -
object.mPoly[1];
406 template <
typename Real>
407 typename DCPQuery<Real, Circle3<Real>,
Circle3<Real>>::SCPolynomial
409 SCPolynomial
const&
object)
const 413 result.mPoly[0] = mPoly[0] *
object.mPoly[0] +
414 omcsqr * mPoly[1] *
object.mPoly[1];
415 result.mPoly[1] = mPoly[0] *
object.mPoly[1] + mPoly[1] *
object.mPoly[0];
419 template <
typename Real>
420 typename DCPQuery<Real, Circle3<Real>,
Circle3<Real>>::SCPolynomial
425 result.mPoly[0] = scalar * mPoly[0];
426 result.mPoly[1] = scalar * mPoly[1];
unsigned int GetDegree() const
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
#define LogAssert(condition, message)
static unsigned int GetMaxBisections()
GLsizei GLsizei GLfloat distance
static Real Sqrt(Real const &x)
Vector< N, Real > GetOrthogonal(Vector< N, Real > const &v, bool unitLength)
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
DualQuaternion< Real > operator+(DualQuaternion< Real > const &d)
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
Real Normalize(GVector< Real > &v, bool robust=false)
DualQuaternion< Real > Cross(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
GLfloat GLfloat GLfloat GLfloat h
DualQuaternion< Real > Length(DualQuaternion< Real > const &d, bool robust=false)
DualQuaternion< Real > operator-(DualQuaternion< Real > const &d)
Real ComputeOrthogonalComplement(int numInputs, Vector2< Real > *v, bool robust=false)
Vector4< float > operator*(Transform const &M, Vector4< float > const &V)
Vector3< Real > circle1Closest
static int Find(int degree, Real const *c, unsigned int maxIterations, Real *roots)