38 #ifndef FCL_NARROWPHASE_DETAIL_CAPSULECAPSULE_INL_H 39 #define FCL_NARROWPHASE_DETAIL_CAPSULECAPSULE_INL_H 41 #include "fcl/narrowphase/detail/primitive_shape_algorithm/capsule_capsule.h" 51 double clamp(
double n,
double min,
double max);
55 double closestPtSegmentSegment(
56 Vector3d p1, Vector3d q1, Vector3d p2, Vector3d q2,
57 double &s,
double& t, Vector3d &c1, Vector3d &c2);
61 bool capsuleCapsuleDistance(
62 const Capsule<double>& s1,
const Transform3<double>& tf1,
63 const Capsule<double>& s2,
const Transform3<double>& tf2,
64 double* dist, Vector3d* p1_res, Vector3d* p2_res);
68 S clamp(S n, S min, S max)
70 if (n < min)
return min;
71 if (n > max)
return max;
77 S closestPtSegmentSegment(
78 Vector3<S> p1, Vector3<S> q1, Vector3<S> p2, Vector3<S> q2,
79 S &s, S &t, Vector3<S> &c1, Vector3<S> &c2)
81 const S EPSILON = 0.001;
82 Vector3<S> d1 = q1 - p1;
83 Vector3<S> d2 = q2 - p2;
84 Vector3<S> r = p1 - p2;
90 if (a <= EPSILON && e <= EPSILON) {
95 Vector3<S> diff = c1-c2;
96 S res = diff.dot(diff);
103 t = clamp(t, (S)0.0, (S)1.0);
109 s = clamp(-c / a, (S)0.0, (S)1.0);
117 std::cerr <<
"denominator equals zero, using 0 as reference" << std::endl;
118 s = clamp((b*f - c*e) / denom, (S)0.0, (S)1.0);
130 s = clamp(-c / a, (S)0.0, (S)1.0);
131 }
else if (t > 1.0) {
133 s = clamp((b - c) / a, (S)0.0, (S)1.0);
139 Vector3<S> diff = c1-c2;
140 S res = diff.dot(diff);
145 template <
typename S>
146 bool capsuleCapsuleDistance(
const Capsule<S>& s1,
const Transform3<S>& tf1,
147 const Capsule<S>& s2,
const Transform3<S>& tf2,
148 S* dist, Vector3<S>* p1_res, Vector3<S>* p2_res)
151 Vector3<S> p1(tf1.translation());
152 Vector3<S> p2(tf2.translation());
156 Transform3<S> transformQ1 = tf1 * Translation3<S>(Vector3<S>(0,0,s1.lz));
157 Vector3<S> q1 = transformQ1.translation();
159 Transform3<S> transformQ2 = tf2 * Translation3<S>(Vector3<S>(0,0,s2.lz));
160 Vector3<S> q2 = transformQ2.translation();
166 S result = closestPtSegmentSegment(p1, q1, p2, q2, s, t, c1, c2);
167 *dist = sqrt(result)-s1.radius-s2.radius;
170 Vector3<S> distVec = c2 -c1;
175 *p1_res = c1 + distVec*s1.radius;
180 *p2_res = c2 + distVec*s2.radius;
Main namespace.
Definition: broadphase_bruteforce-inl.h:45