23 template <
typename Real>
35 template <
typename Real>
44 std::array<Vector3<Real>, 2>
point;
56 template <
typename Real>
63 auto lsResult = lsQuery(line, capsule.segment);
64 result.intersect = (lsResult.distance <= capsule.radius);
68 template <
typename Real>
74 DoQuery(line.origin, line.direction, capsule, result);
75 for (
int i = 0; i < result.numIntersections; ++i)
77 result.point[i] = line.origin + result.parameter[i] * line.direction;
82 template <
typename Real>
89 result.intersect =
false;
90 result.numIntersections = 0;
104 capsule.
segment.GetCenteredForm(segOrigin, segDirection, segExtent);
106 basis[0] = segDirection;
113 Dot(basis[0], diff) };
117 Real dz =
Dot(basis[0], lineDirection);
122 Real radialSqrDist = rSqr - P[0] * P[0] - P[1] * P[1];
123 if (radialSqrDist >= (Real)0)
126 result.intersect =
true;
127 result.numIntersections = 2;
128 Real zOffset = sqrt(radialSqrDist) + segExtent;
131 result.parameter[0] = -P[2] - zOffset;
132 result.parameter[1] = -P[2] + zOffset;
136 result.parameter[0] = P[2] - zOffset;
137 result.parameter[1] = P[2] + zOffset;
146 Dot(basis[2], lineDirection), dz };
152 Real a0 = P[0] * P[0] + P[1] * P[1] - rSqr;
153 Real a1 = P[0] * D[0] + P[1] * D[1];
154 Real a2 = D[0] * D[0] + D[1] * D[1];
155 Real discr = a1 * a1 - a0 * a2;
163 Real root, inv, tValue, zValue;
168 inv = ((Real)1) / a2;
169 tValue = (-a1 - root) * inv;
170 zValue = P[2] + tValue * D[2];
173 result.intersect =
true;
174 result.parameter[result.numIntersections++] = tValue;
177 tValue = (-a1 + root) * inv;
178 zValue = P[2] + tValue * D[2];
181 result.intersect =
true;
182 result.parameter[result.numIntersections++] = tValue;
185 if (result.numIntersections == 2)
196 zValue = P[2] + tValue * D[2];
199 result.intersect =
true;
200 result.numIntersections = 1;
201 result.parameter[0] = tValue;
203 result.parameter[1] = result.parameter[0];
213 Real PZpE = P[2] + segExtent;
216 discr = a1 * a1 - a0;
221 zValue = P[2] + tValue * D[2];
222 if (zValue <= -segExtent)
224 result.parameter[result.numIntersections++] = tValue;
225 if (result.numIntersections == 2)
227 result.intersect =
true;
228 if (result.parameter[0] > result.parameter[1])
230 std::swap(result.parameter[0], result.parameter[1]);
237 zValue = P[2] + tValue * D[2];
238 if (zValue <= -segExtent)
240 result.parameter[result.numIntersections++] = tValue;
241 if (result.numIntersections == 2)
243 result.intersect =
true;
244 if (result.parameter[0] > result.parameter[1])
246 std::swap(result.parameter[0], result.parameter[1]);
252 else if (discr == (Real)0)
255 zValue = P[2] + tValue * D[2];
256 if (zValue <= -segExtent)
258 result.parameter[result.numIntersections++] = tValue;
259 if (result.numIntersections == 2)
261 result.intersect =
true;
262 if (result.parameter[0] > result.parameter[1])
264 std::swap(result.parameter[0], result.parameter[1]);
276 a1 -= ((Real)2) * segExtent * D[2];
277 a0 -= ((Real)4) * segExtent * P[2];
278 discr = a1 * a1 - a0;
283 zValue = P[2] + tValue * D[2];
284 if (zValue >= segExtent)
286 result.parameter[result.numIntersections++] = tValue;
287 if (result.numIntersections == 2)
289 result.intersect =
true;
290 if (result.parameter[0] > result.parameter[1])
292 std::swap(result.parameter[0], result.parameter[1]);
299 zValue = P[2] + tValue * D[2];
300 if (zValue >= segExtent)
302 result.parameter[result.numIntersections++] = tValue;
303 if (result.numIntersections == 2)
305 result.intersect =
true;
306 if (result.parameter[0] > result.parameter[1])
308 std::swap(result.parameter[0], result.parameter[1]);
314 else if (discr == (Real)0)
317 zValue = P[2] + tValue * D[2];
318 if (zValue >= segExtent)
320 result.parameter[result.numIntersections++] = tValue;
321 if (result.numIntersections == 2)
323 result.intersect =
true;
324 if (result.parameter[0] > result.parameter[1])
326 std::swap(result.parameter[0], result.parameter[1]);
333 if (result.numIntersections == 1)
336 result.parameter[1] = result.parameter[0];
std::array< Vector3< Real >, 2 > point
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
Segment< N, Real > segment
Real ComputeOrthogonalComplement(int numInputs, Vector2< Real > *v, bool robust=false)
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
std::array< Real, 2 > parameter