22 template <
typename Real>
36 template <
typename Real>
62 template <
typename Real>
67 LogAssert(cylinder.height != std::numeric_limits<Real>::max(),
68 "Cylinder height must be finite for TIQuery.");
77 Real
distance = vpQuery(cylinder.axis.origin, plane).distance;
78 Real absNdW =
std::abs(
Dot(plane.normal, cylinder.axis.direction));
79 Real root = sqrt(std::max((Real)1 - absNdW*absNdW, (Real)0));
80 Real term = cylinder.radius*root + ((Real)0.5)*cylinder.height*absNdW;
83 result.intersect = (distance <= term);
87 template <
typename Real>
92 LogAssert(cylinder.height == std::numeric_limits<Real>::max(),
93 "Cylinder height must be infinite for FIQuery.");
98 Real sdistance = vpQuery(cylinder.axis.origin, plane).signedDistance;
99 Vector3<Real> center = cylinder.axis.origin - sdistance*plane.normal;
100 Real cosTheta =
Dot(cylinder.axis.direction, plane.normal);
101 Real absCosTheta =
std::abs(cosTheta);
103 if (absCosTheta > (Real)0)
106 result.intersect =
true;
107 if (absCosTheta < (Real)1)
110 result.ellipse.normal = plane.normal;
111 result.ellipse.center = cylinder.axis.origin -
112 (sdistance / cosTheta)*cylinder.axis.direction;
113 result.ellipse.axis[0] = cylinder.axis.direction -
114 cosTheta*plane.normal;
116 result.ellipse.axis[1] =
UnitCross(plane.normal,
117 result.ellipse.axis[0]);
118 result.ellipse.extent[0] = cylinder.radius / absCosTheta;
119 result.ellipse.extent[1] = cylinder.radius;
124 result.circle.normal = plane.normal;
125 result.circle.center = center;
126 result.circle.radius = cylinder.radius;
133 if (distance < cylinder.radius)
135 result.intersect =
true;
140 Real extent = sqrt(cylinder.radius*cylinder.radius -
141 sdistance*sdistance);
143 result.line[0].origin = center - extent*
offset;
144 result.line[0].direction = cylinder.axis.direction;
145 result.line[1].origin = center + extent*
offset;
146 result.line[1].direction = cylinder.axis.direction;
148 else if (distance == cylinder.radius)
150 result.intersect =
true;
152 result.line[0].origin = center;
153 result.line[0].direction = cylinder.axis.direction;
157 result.intersect =
false;
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
#define LogAssert(condition, message)
Vector< N, Real > UnitCross(Vector< N, Real > const &v0, Vector< N, Real > const &v1, bool robust=false)
GLsizei GLsizei GLfloat distance
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)
Result operator()(Type0 const &primitive0, Type1 const &primitive1)