20 template <
typename Real>
29 std::array<Vector3<Real>, 2>
point;
42 template <
typename Real>
48 DoQuery(line.origin, line.direction, cylinder, result);
49 for (
int i = 0; i < result.numIntersections; ++i)
51 result.point[i] = line.origin + result.parameter[i] * line.direction;
56 template <
typename Real>
63 result.intersect =
false;
64 result.numIntersections = 0;
73 basis[0] = cylinder.
axis.direction;
75 Real halfHeight = ((Real)0.5) * cylinder.
height;
81 Dot(basis[0], diff) };
85 Real dz =
Dot(basis[0], lineDirection);
90 Real radialSqrDist = rSqr - P[0] * P[0] - P[1] * P[1];
91 if (radialSqrDist >= (Real)0)
94 result.intersect =
true;
95 result.numIntersections = 2;
98 result.parameter[0] = -P[2] - halfHeight;
99 result.parameter[1] = -P[2] + halfHeight;
103 result.parameter[0] = P[2] - halfHeight;
104 result.parameter[1] = P[2] + halfHeight;
114 Dot(basis[2], lineDirection), dz };
116 Real a0, a1, a2, discr, root, inv, tValue;
128 a0 = P[0] * P[0] + P[1] * P[1] - rSqr;
129 a1 = P[0] * D[0] + P[1] * D[1];
130 a2 = D[0] * D[0] + D[1] * D[1];
131 discr = a1 * a1 - a0 * a2;
135 result.intersect =
true;
136 result.numIntersections = 2;
138 inv = ((Real)1) / a2;
139 result.parameter[0] = (-a1 - root) * inv;
140 result.parameter[1] = (-a1 + root) * inv;
142 else if (discr == (Real)0)
145 result.intersect =
true;
146 result.numIntersections = 1;
147 result.parameter[0] = -a1 / a2;
149 result.parameter[1] = result.parameter[0];
158 inv = ((Real)1) / D[2];
160 Real
t0 = (-halfHeight - P[2]) * inv;
161 Real xTmp = P[0] + t0 * D[0];
162 Real yTmp = P[1] + t0 * D[1];
163 if (xTmp * xTmp + yTmp * yTmp <= rSqr)
166 result.parameter[result.numIntersections++] =
t0;
169 Real
t1 = (+halfHeight - P[2]) * inv;
170 xTmp = P[0] + t1 * D[0];
171 yTmp = P[1] + t1 * D[1];
172 if (xTmp * xTmp + yTmp * yTmp <= rSqr)
175 result.parameter[result.numIntersections++] =
t1;
178 if (result.numIntersections < 2)
181 a0 = P[0] * P[0] + P[1] * P[1] - rSqr;
182 a1 = P[0] * D[0] + P[1] * D[1];
183 a2 = D[0] * D[0] + D[1] * D[1];
184 discr = a1 * a1 - a0 * a2;
188 inv = ((Real)1) / a2;
189 tValue = (-a1 - root) * inv;
192 if (t0 <= tValue && tValue <= t1)
194 result.parameter[result.numIntersections++] = tValue;
199 if (t1 <= tValue && tValue <= t0)
201 result.parameter[result.numIntersections++] = tValue;
205 if (result.numIntersections < 2)
207 tValue = (-a1 + root) * inv;
210 if (t0 <= tValue && tValue <= t1)
212 result.parameter[result.numIntersections++] = tValue;
217 if (t1 <= tValue && tValue <= t0)
219 result.parameter[result.numIntersections++] = tValue;
225 else if (discr == (Real)0)
230 if (t0 <= tValue && tValue <= t1)
232 result.parameter[result.numIntersections++] = tValue;
237 if (t1 <= tValue && tValue <= t0)
239 result.parameter[result.numIntersections++] = tValue;
247 if (result.numIntersections == 2)
249 result.intersect =
true;
250 if (result.parameter[0] > result.parameter[1])
252 std::swap(result.parameter[0], result.parameter[1]);
255 else if (result.numIntersections == 1)
257 result.intersect =
true;
259 result.parameter[1] = result.parameter[0];
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
std::array< Real, 2 > parameter
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
std::array< Vector3< Real >, 2 > point
Real ComputeOrthogonalComplement(int numInputs, Vector2< Real > *v, bool robust=false)