22 template <
typename Real>
24 Capsule3<Real>& capsule);
27 template <
typename Real>
28 bool InContainer(Vector3<Real>
const& point, Capsule3<Real>
const& capsule);
31 template <
typename Real>
32 bool InContainer(Sphere3<Real>
const& sphere, Capsule3<Real>
const& capsule);
35 template <
typename Real>
37 Capsule3<Real>
const& capsule);
41 template <
typename Real>
43 Capsule3<Real>
const& capsule1, Capsule3<Real>& merge);
46 template <
typename Real>
51 fitter.
Fit(numPoints, points);
55 Real maxRadiusSqr = (Real)0;
56 for (
int i = 0; i < numPoints; ++i)
58 auto result = plQuery(points[i], line);
59 if (
result.sqrDistance > maxRadiusSqr)
61 maxRadiusSqr =
result.sqrDistance;
69 Real minValue = std::numeric_limits<Real>::max();
70 Real maxValue = -std::numeric_limits<Real>::max();
71 for (
int i = 0; i < numPoints; ++i)
74 Real uDotDiff =
Dot(diff, basis[1]);
75 Real vDotDiff =
Dot(diff, basis[2]);
76 Real wDotDiff =
Dot(diff, basis[0]);
77 Real discr = maxRadiusSqr - (uDotDiff*uDotDiff + vDotDiff*vDotDiff);
78 Real radical = sqrt(std::max(discr, (Real)0));
80 Real test = wDotDiff + radical;
86 test = wDotDiff - radical;
94 (((Real)0.5)*(minValue + maxValue))*line.
direction;
97 if (maxValue > minValue)
100 extent = ((Real)0.5)*(maxValue - minValue);
109 capsule.
radius = sqrt(maxRadiusSqr);
113 template <
typename Real>
121 template <
typename Real>
125 if (rDiff >= (Real)0)
129 return result.distance <= rDiff;
134 template <
typename Real>
140 return InContainer<Real>(spherePosEnd, capsule)
141 && InContainer<Real>(sphereNegEnd, capsule);
144 template <
typename Real>
148 if (InContainer<Real>(capsule0, capsule1))
154 if (InContainer<Real>(capsule1, capsule0))
161 Real extent0, extent1;
162 capsule0.
segment.GetCenteredForm(P0, D0, extent0);
163 capsule1.
segment.GetCenteredForm(P1, D1, extent1);
169 line.
origin = ((Real)0.5)*(P0 + P1);
172 if (
Dot(D0, D1) >= (Real)0)
186 Real radius = plQuery(posEnd0, line).distance + capsule0.
radius;
189 Real tmp = plQuery(negEnd0, line).distance + capsule0.
radius;
192 tmp = plQuery(posEnd1, line).distance + capsule1.
radius;
199 tmp = plQuery(negEnd1, line).distance + capsule1.
radius;
206 Real rDiff = radius - capsule0.
radius;
207 Real rDiffSqr = rDiff*rDiff;
209 Real k0 =
Dot(diff, diff) - rDiffSqr;
211 Real discr = k1*k1 - k0;
212 Real root = sqrt(std::max(discr, (Real)0));
213 Real tPos = -k1 - root;
214 Real tNeg = -k1 + root;
217 diff = line.
origin - negEnd0;
218 k0 =
Dot(diff, diff) - rDiffSqr;
221 root = sqrt(std::max(discr, (Real)0));
234 rDiff = radius - capsule1.
radius;
235 rDiffSqr = rDiff*rDiff;
236 diff = line.
origin - posEnd1;
237 k0 =
Dot(diff, diff) - rDiffSqr;
240 root = sqrt(std::max(discr, (Real)0));
253 diff = line.
origin - negEnd1;
254 k0 =
Dot(diff, diff) - rDiffSqr;
257 root = sqrt(std::max(discr, (Real)0));
270 ((Real)0.5)*(tPos + tNeg)*line.
direction;
276 extent = ((Real)0.5)*(tPos - tNeg);
bool GetContainer(int numPoints, Vector3< Real > const *points, Capsule3< Real > &capsule)
bool MergeContainers(Capsule3< Real > const &capsule0, Capsule3< Real > const &capsule1, Capsule3< Real > &merge)
bool InContainer(Vector3< Real > const &point, Capsule3< Real > const &capsule)
Vector< N, Real > direction
GLfixed GLfixed GLint GLint GLfixed points
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
Segment< N, Real > segment
Real Normalize(GVector< Real > &v, bool robust=false)
bool Fit(int numPoints, Vector3< Real > const *points)
Real ComputeOrthogonalComplement(int numInputs, Vector2< Real > *v, bool robust=false)
Line3< Real > const & GetParameters() const