38 #ifndef FCL_NARROWPHASE_DETAIL_SPHERECAPSULE_INL_H 39 #define FCL_NARROWPHASE_DETAIL_SPHERECAPSULE_INL_H 41 #include "fcl/narrowphase/detail/primitive_shape_algorithm/sphere_capsule.h" 51 void lineSegmentPointClosestToPoint(
52 const Vector3<double> &p,
53 const Vector3<double> &s1,
54 const Vector3<double> &s2,
59 bool sphereCapsuleIntersect(
const Sphere<double>& s1,
const Transform3<double>& tf1,
60 const Capsule<double>& s2,
const Transform3<double>& tf2,
61 std::vector<ContactPoint<double>>* contacts);
65 bool sphereCapsuleDistance(
const Sphere<double>& s1,
const Transform3<double>& tf1,
66 const Capsule<double>& s2,
const Transform3<double>& tf2,
67 double* dist, Vector3<double>* p1, Vector3<double>* p2);
71 void lineSegmentPointClosestToPoint (
const Vector3<S> &p,
const Vector3<S> &s1,
const Vector3<S> &s2, Vector3<S> &sp) {
72 Vector3<S> v = s2 - s1;
73 Vector3<S> w = p - s1;
80 }
else if (c2 <= c1) {
84 Vector3<S> Pb = s1 + v * b;
91 bool sphereCapsuleIntersect(
const Sphere<S>& s1,
const Transform3<S>& tf1,
92 const Capsule<S>& s2,
const Transform3<S>& tf2,
93 std::vector<ContactPoint<S>>* contacts)
95 const Vector3<S> pos1(0., 0., 0.5 * s2.lz);
96 const Vector3<S> pos2(0., 0., -0.5 * s2.lz);
97 const Vector3<S> s_c = tf2.inverse(Eigen::Isometry) * tf1.translation();
99 Vector3<S> segment_point;
101 lineSegmentPointClosestToPoint (s_c, pos1, pos2, segment_point);
102 Vector3<S> diff = s_c - segment_point;
104 const S
distance = diff.norm() - s1.radius - s2.radius;
109 const Vector3<S> local_normal = -diff.normalized();
113 const Vector3<S> normal = tf2.linear() * local_normal;
114 const Vector3<S>
point = tf2 * (segment_point + local_normal *
distance);
115 const S penetration_depth = -
distance;
117 contacts->emplace_back(normal, point, penetration_depth);
124 template <
typename S>
125 bool sphereCapsuleDistance(
const Sphere<S>& s1,
const Transform3<S>& tf1,
126 const Capsule<S>& s2,
const Transform3<S>& tf2,
127 S* dist, Vector3<S>* p1, Vector3<S>* p2)
129 Vector3<S> pos1(0., 0., 0.5 * s2.lz);
130 Vector3<S> pos2(0., 0., -0.5 * s2.lz);
131 Vector3<S> s_c = tf2.inverse(Eigen::Isometry) * tf1.translation();
133 Vector3<S> segment_point;
135 lineSegmentPointClosestToPoint (s_c, pos1, pos2, segment_point);
136 Vector3<S> diff = s_c - segment_point;
138 S distance = diff.norm() - s1.radius - s2.radius;
145 if(p1 || p2) diff.normalize();
148 *p1 = s_c - diff * s1.radius;
149 *p1 = tf1.inverse(Eigen::Isometry) * tf2 * (*p1);
152 if(p2) *p2 = segment_point + diff * s1.radius;
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
std::chrono::system_clock::time_point point
Representation of a point in time.
Definition: time.h:51
S distance(const Eigen::MatrixBase< DerivedA > &R0, const Eigen::MatrixBase< DerivedB > &T0, const kIOS< S > &b1, const kIOS< S > &b2, Vector3< S > *P, Vector3< S > *Q)
Approximate distance between two kIOS bounding volumes.
Definition: kIOS-inl.h:266