37 #ifndef HPP_FCL_CONTACT_PATCH_SOLVER_HXX
38 #define HPP_FCL_CONTACT_PATCH_SOLVER_HXX
76 template <
typename ShapeType1,
typename ShapeType2>
86 contact_patch.
points().clear();
111 this->
reset(s1, tf1, s2, tf2, contact_patch);
127 this->support_set_shape2.size() <= 1) {
133 const FCL_REAL eps = Eigen::NumTraits<FCL_REAL>::dummy_precision();
137 (this->support_set_shape2.size() == 2)) {
142 const Vec2f& a = pts1[0];
143 const Vec2f& b = pts1[1];
146 const Vec2f& c = pts2[0];
147 const Vec2f& d = pts2[1];
150 (b(0) - a(0)) * (d(1) - c(1)) >= (b(1) - a(1)) * (d(0) - c(0));
151 if ((std::abs(det) > eps) || ((c - d).squaredNorm() < eps) ||
152 ((b - a).squaredNorm() < eps)) {
157 const Vec2f cd = (d - c);
158 const FCL_REAL l = cd.squaredNorm();
159 Polygon& patch = contact_patch.
points();
163 t1 = (t1 >= l) ? 1.0 : ((t1 <= 0) ? 0.0 : (t1 / l));
164 const Vec2f p1 = c + t1 * cd;
165 patch.emplace_back(p1);
169 t2 = (t2 >= l) ? 1.0 : ((t2 <= 0) ? 0.0 : (t2 / l));
170 const Vec2f p2 = c + t2 * cd;
171 if ((p1 - p2).squaredNorm() >= eps) {
172 patch.emplace_back(p2);
192 const size_t max_result_size =
198 const Polygon* clipper_ptr =
nullptr;
199 Polygon* current_ptr =
nullptr;
212 const Polygon& clipper = *(clipper_ptr);
213 const size_t clipper_size = clipper.size();
214 for (
size_t i = 0; i < clipper_size; ++i) {
218 Polygon* tmp_ptr = previous_ptr;
219 previous_ptr = current_ptr;
220 current_ptr = tmp_ptr;
222 const Polygon& previous = *(previous_ptr);
223 Polygon& current = *(current_ptr);
226 const Vec2f& a = clipper[i];
227 const Vec2f& b = clipper[(i + 1) % clipper_size];
228 const Vec2f ab = b - a;
230 if (previous.size() == 2) {
234 const Vec2f& p1 = previous[0];
235 const Vec2f& p2 = previous[1];
237 const Vec2f ap1 = p1 - a;
238 const Vec2f ap2 = p2 - a;
240 const FCL_REAL det1 = ab(0) * ap1(1) - ab(1) * ap1(0);
241 const FCL_REAL det2 = ab(0) * ap2(1) - ab(1) * ap2(0);
243 if (det1 < 0 && det2 < 0) {
249 if (det1 >= 0 && det2 >= 0) {
261 current.emplace_back(p1);
262 current.emplace_back(p);
267 current.emplace_back(p1);
273 current.emplace_back(p2);
274 current.emplace_back(p);
279 current.emplace_back(p2);
288 this->added_to_patch.end(),
291 const size_t previous_size = previous.size();
292 for (
size_t j = 0; j < previous_size; ++j) {
293 const Vec2f& p1 = previous[j];
294 const Vec2f& p2 = previous[(j + 1) % previous_size];
296 const Vec2f ap1 = p1 - a;
297 const Vec2f ap2 = p2 - a;
299 const FCL_REAL det1 = ab(0) * ap1(1) - ab(1) * ap1(0);
300 const FCL_REAL det2 = ab(0) * ap2(1) - ab(1) * ap2(0);
302 if (det1 < 0 && det2 < 0) {
307 if (det1 >= 0 && det2 >= 0) {
311 current.emplace_back(p1);
321 current.emplace_back(p1);
325 current.emplace_back(p);
329 current.emplace_back(p1);
336 current.emplace_back(p);
339 current.emplace_back(p2);
348 if (current.size() <= 1) {
356 this->
getResult(contact, current_ptr, contact_patch);
363 if (result_ptr->size() <= 1) {
374 template <
typename ShapeType1,
typename ShapeType2>
377 const ShapeType2& shape2,
412 const Vec2f ab = b - a;
413 const Vec2f n(-ab(1), ab(0));
414 const FCL_REAL denominator = n.dot(c - d);
415 if (std::abs(denominator) < std::numeric_limits<double>::epsilon()) {
418 const FCL_REAL nominator = n.dot(a - d);
419 FCL_REAL alpha = nominator / denominator;
420 alpha = std::min<double>(1.0, std::max<FCL_REAL>(0.0, alpha));
421 return alpha * c + (1 - alpha) * d;
Eigen::Matrix< FCL_REAL, 2, 1 > Vec2f
Definition: data_types.h:68
void constructContactPatchFrameFromContact(const Contact &contact, ContactPatch &contact_patch)
Construct a frame from a Contact's position and normal. Because both Contact's position and normal ar...
Definition: collision_data.h:706
double FCL_REAL
Definition: data_types.h:66
Main namespace.
Definition: broadphase_bruteforce.h:44
Definition: geometric_shapes_traits.h:56