37 #ifndef FCL_NARROWPHASE_DETAIL_SPHERECYLINDER_INL_H
38 #define FCL_NARROWPHASE_DETAIL_SPHERECYLINDER_INL_H
45 extern template FCL_EXPORT
bool
47 const Transform3<double>& X_FS,
49 const Transform3<double>& X_FC,
50 std::vector<ContactPoint<double>>* contacts);
54 extern template FCL_EXPORT
bool
56 const Transform3<double>& X_FS,
58 const Transform3<double>& X_FC,
59 double*
distance, Vector3<double>* p_FSc,
60 Vector3<double>* p_FCs);
81 assert(p_CN_ptr !=
nullptr);
88 const S half_height = height / 2;
89 if (p_CQ(2) > half_height) {
91 p_CN(2) = half_height;
92 }
else if (p_CQ(2) < -half_height) {
94 p_CN(2) = -half_height;
99 S squared_distance = r_CQ.dot(r_CQ);
100 if (squared_distance > radius * radius) {
103 r_CQ *= radius / sqrt(squared_distance);
113 template <
typename S>
133 const S p_SN_squared_dist = p_SN_C.squaredNorm();
136 if (p_SN_squared_dist >
r_s *
r_s)
141 if (contacts !=
nullptr) {
159 if (S_is_outside && p_SN_squared_dist > eps * eps) {
168 const S d_NS = sqrt(p_SN_squared_dist);
169 n_SC_C = p_SN_C / d_NS;
171 p_CP = p_CN + n_SC_C * (depth * 0.5);
175 const S& h = cylinder.
lz;
176 const S face_distance = p_CS(2) >= 0 ? h / 2 - p_CS(2) : p_CS(2) + h / 2;
183 const S d_CS_xy = n_SB_xy.norm();
184 const S barrel_distance = cylinder.
radius - d_CS_xy;
191 if (barrel_distance < face_distance - eps) {
195 n_SC_C << -n_SB_xy(0) / d_CS_xy, -n_SB_xy(1) / d_CS_xy, 0;
196 depth =
r_s + barrel_distance;
197 p_CP = p_CS + n_SC_C * ((
r_s - barrel_distance) / 2);
204 p_CP = p_CS + n_SC_C * ((
r_s - barrel_distance) / 2);
213 n_SC_C(2) = p_CS(2) >= 0 ? -1 : 1;
214 depth = face_distance +
r_s;
215 p_CP = p_CS + n_SC_C * ((
r_s - face_distance) / 2);
218 contacts->emplace_back(X_FC.linear() * n_SC_C, X_FC * p_CP, depth);
225 template <
typename S>
249 const S p_NS_squared_dist = p_NS_C.squaredNorm();
250 if (p_NS_squared_dist >
r_s *
r_s) {
255 d = sqrt(p_NS_squared_dist);
258 if (p_FCs !=
nullptr)
259 *p_FCs = X_FC * p_CN;
260 if (p_FSc !=
nullptr) {
262 *p_FSc = X_FC * p_CSc;
276 #endif // FCL_NARROWPHASE_DETAIL_SPHERECYLINDER_INL_H