38 #ifndef FCL_NARROWPHASE_GJKSOLVERLIBCCD_INL_H 39 #define FCL_NARROWPHASE_GJKSOLVERLIBCCD_INL_H 41 #include "fcl/narrowphase/detail/gjk_solver_libccd.h" 45 #include "fcl/narrowphase/detail/convexity_based_algorithm/gjk_libccd.h" 46 #include "fcl/narrowphase/detail/primitive_shape_algorithm/capsule_capsule.h" 47 #include "fcl/narrowphase/detail/primitive_shape_algorithm/sphere_capsule.h" 48 #include "fcl/narrowphase/detail/primitive_shape_algorithm/sphere_sphere.h" 49 #include "fcl/narrowphase/detail/primitive_shape_algorithm/sphere_triangle.h" 50 #include "fcl/narrowphase/detail/primitive_shape_algorithm/box_box.h" 51 #include "fcl/narrowphase/detail/primitive_shape_algorithm/halfspace.h" 52 #include "fcl/narrowphase/detail/primitive_shape_algorithm/plane.h" 62 struct GJKSolver_libccd<double>;
66 template<
typename Shape1,
typename Shape2>
68 const Shape1& s1,
const Transform3<S>& tf1,
69 const Shape2& s2,
const Transform3<S>& tf2,
70 Vector3<S>* contact_points,
72 Vector3<S>* normal)
const 76 if (contact_points || penetration_depth || normal)
78 std::vector<ContactPoint<S>> contacts;
80 res = shapeIntersect(s1, tf1, s2, tf2, &contacts);
82 if (!contacts.empty())
85 const ContactPoint<S>& maxDepthContact = *std::max_element(contacts.begin(), contacts.end(), comparePenDepth<S>);
88 *contact_points = maxDepthContact.pos;
90 if (penetration_depth)
91 *penetration_depth = maxDepthContact.penetration_depth;
94 *normal = maxDepthContact.normal;
99 res = shapeIntersect(s1, tf1, s2, tf2,
nullptr);
106 template<
typename S,
typename Shape1,
typename Shape2>
111 const Shape1& s1,
const Transform3<S>& tf1,
112 const Shape2& s2,
const Transform3<S>& tf2,
125 res = detail::GJKCollide<S>(
136 contacts->emplace_back(normal, point, depth);
140 res = detail::GJKCollide<S>(
163 template<
typename Shape1,
typename Shape2>
165 const Shape1& s1,
const Transform3<S>& tf1,
166 const Shape2& s2,
const Transform3<S>& tf2,
170 *
this, s1, tf1, s2, tf2, contacts);
197 #define FCL_GJK_LIBCCD_SHAPE_SHAPE_INTERSECT_REG(SHAPE1, SHAPE2, ALG)\ 198 template <typename S>\ 199 struct ShapeIntersectLibccdImpl<S, SHAPE1<S>, SHAPE2<S>>\ 202 const GJKSolver_libccd<S>& ,\ 203 const SHAPE1<S>& s1,\ 204 const Transform3<S>& tf1,\ 205 const SHAPE2<S>& s2,\ 206 const Transform3<S>& tf2,\ 207 std::vector<ContactPoint<S>>* contacts)\ 209 return ALG(s1, tf1, s2, tf2, contacts);\ 213 #define FCL_GJK_LIBCCD_SHAPE_SHAPE_INTERSECT_INV(SHAPE1, SHAPE2, ALG)\ 214 template <typename S>\ 215 struct ShapeIntersectLibccdImpl<S, SHAPE2<S>, SHAPE1<S>>\ 218 const GJKSolver_libccd<S>& ,\ 219 const SHAPE2<S>& s1,\ 220 const Transform3<S>& tf1,\ 221 const SHAPE1<S>& s2,\ 222 const Transform3<S>& tf2,\ 223 std::vector<ContactPoint<S>>* contacts)\ 225 const bool res = ALG(s2, tf2, s1, tf1, contacts);\ 226 if (contacts) flipNormal(*contacts);\ 231 #define FCL_GJK_LIBCCD_SHAPE_INTERSECT(SHAPE, ALG)\ 232 FCL_GJK_LIBCCD_SHAPE_SHAPE_INTERSECT_REG(SHAPE, SHAPE, ALG) 234 #define FCL_GJK_LIBCCD_SHAPE_SHAPE_INTERSECT(SHAPE1, SHAPE2, ALG)\ 235 FCL_GJK_LIBCCD_SHAPE_SHAPE_INTERSECT_REG(SHAPE1, SHAPE2, ALG)\ 236 FCL_GJK_LIBCCD_SHAPE_SHAPE_INTERSECT_INV(SHAPE1, SHAPE2, ALG) 238 FCL_GJK_LIBCCD_SHAPE_INTERSECT(
Sphere, detail::sphereSphereIntersect)
239 FCL_GJK_LIBCCD_SHAPE_INTERSECT(
Box, detail::boxBoxIntersect)
241 FCL_GJK_LIBCCD_SHAPE_SHAPE_INTERSECT(
Sphere,
Capsule, detail::sphereCapsuleIntersect)
243 FCL_GJK_LIBCCD_SHAPE_SHAPE_INTERSECT(
Sphere,
Halfspace, detail::sphereHalfspaceIntersect)
244 FCL_GJK_LIBCCD_SHAPE_SHAPE_INTERSECT(
Ellipsoid,
Halfspace, detail::ellipsoidHalfspaceIntersect)
245 FCL_GJK_LIBCCD_SHAPE_SHAPE_INTERSECT(
Box,
Halfspace, detail::boxHalfspaceIntersect)
246 FCL_GJK_LIBCCD_SHAPE_SHAPE_INTERSECT(
Capsule,
Halfspace, detail::capsuleHalfspaceIntersect)
247 FCL_GJK_LIBCCD_SHAPE_SHAPE_INTERSECT(
Cylinder,
Halfspace, detail::cylinderHalfspaceIntersect)
248 FCL_GJK_LIBCCD_SHAPE_SHAPE_INTERSECT(
Cone,
Halfspace, detail::coneHalfspaceIntersect)
250 FCL_GJK_LIBCCD_SHAPE_SHAPE_INTERSECT(
Sphere,
Plane, detail::spherePlaneIntersect)
251 FCL_GJK_LIBCCD_SHAPE_SHAPE_INTERSECT(
Ellipsoid,
Plane, detail::ellipsoidPlaneIntersect)
252 FCL_GJK_LIBCCD_SHAPE_SHAPE_INTERSECT(
Box,
Plane, detail::boxPlaneIntersect)
253 FCL_GJK_LIBCCD_SHAPE_SHAPE_INTERSECT(
Capsule,
Plane, detail::capsulePlaneIntersect)
254 FCL_GJK_LIBCCD_SHAPE_SHAPE_INTERSECT(
Cylinder,
Plane, detail::cylinderPlaneIntersect)
255 FCL_GJK_LIBCCD_SHAPE_SHAPE_INTERSECT(
Cone,
Plane, detail::conePlaneIntersect)
257 template <
typename S>
263 const Transform3<S>& tf1,
265 const Transform3<S>& tf2,
272 return detail::halfspaceIntersect(s1, tf1, s2, tf2, p, d, s, depth, ret);
276 template <
typename S>
282 const Transform3<S>& tf1,
284 const Transform3<S>& tf2,
287 return detail::planeIntersect(s1, tf1, s2, tf2, contacts);
291 template <
typename S>
297 const Transform3<S>& tf1,
299 const Transform3<S>& tf2,
306 return detail::planeHalfspaceIntersect(s1, tf1, s2, tf2, pl, p, d, depth, ret);
310 template <
typename S>
316 const Transform3<S>& tf1,
318 const Transform3<S>& tf2,
325 return detail::halfspacePlaneIntersect(s1, tf1, s2, tf2, pl, p, d, depth, ret);
330 template<
typename S,
typename Shape>
336 const Transform3<S>& tf,
337 const Vector3<S>& P1,
338 const Vector3<S>& P2,
339 const Vector3<S>& P3,
340 Vector3<S>* contact_points,
341 S* penetration_depth,
345 void* o2 = detail::triCreateGJKObject(P1, P2, P3);
347 bool res = detail::GJKCollide<S>(
352 detail::triGetSupportFunction(),
353 detail::triGetCenterFunction(),
361 detail::triDeleteGJKObject(o2);
368 template<
typename Shape>
371 const Transform3<S>& tf,
372 const Vector3<S>& P1,
373 const Vector3<S>& P2,
374 const Vector3<S>& P3,
375 Vector3<S>* contact_points,
376 S* penetration_depth,
377 Vector3<S>* normal)
const 380 *
this, s, tf, P1, P2, P3, contact_points, penetration_depth, normal);
390 const Transform3<S>& tf,
391 const Vector3<S>& P1,
392 const Vector3<S>& P2,
393 const Vector3<S>& P3,
394 Vector3<S>* contact_points,
395 S* penetration_depth,
398 return detail::sphereTriangleIntersect(
399 s, tf, P1, P2, P3, contact_points, penetration_depth, normal);
404 template<
typename S,
typename Shape>
410 const Transform3<S>& tf1,
411 const Vector3<S>& P1,
412 const Vector3<S>& P2,
413 const Vector3<S>& P3,
414 const Transform3<S>& tf2,
415 Vector3<S>* contact_points,
416 S* penetration_depth,
420 void* o2 = detail::triCreateGJKObject(P1, P2, P3, tf2);
422 bool res = detail::GJKCollide<S>(
427 detail::triGetSupportFunction(),
428 detail::triGetCenterFunction(),
436 detail::triDeleteGJKObject(o2);
443 template<
typename Shape>
446 const Transform3<S>& tf1,
447 const Vector3<S>& P1,
448 const Vector3<S>& P2,
449 const Vector3<S>& P3,
450 const Transform3<S>& tf2,
451 Vector3<S>* contact_points,
452 S* penetration_depth,
453 Vector3<S>* normal)
const 456 *
this, s, tf1, P1, P2, P3, tf2,
457 contact_points, penetration_depth, normal);
467 const Transform3<S>& tf1,
468 const Vector3<S>& P1,
469 const Vector3<S>& P2,
470 const Vector3<S>& P3,
471 const Transform3<S>& tf2,
472 Vector3<S>* contact_points,
473 S* penetration_depth,
476 return detail::sphereTriangleIntersect(
477 s, tf1, tf2 * P1, tf2 * P2, tf2 * P3,
478 contact_points, penetration_depth, normal);
489 const Transform3<S>& tf1,
490 const Vector3<S>& P1,
491 const Vector3<S>& P2,
492 const Vector3<S>& P3,
493 const Transform3<S>& tf2,
494 Vector3<S>* contact_points,
495 S* penetration_depth,
498 return detail::halfspaceTriangleIntersect(
499 s, tf1, P1, P2, P3, tf2,
500 contact_points, penetration_depth, normal);
511 const Transform3<S>& tf1,
512 const Vector3<S>& P1,
513 const Vector3<S>& P2,
514 const Vector3<S>& P3,
515 const Transform3<S>& tf2,
516 Vector3<S>* contact_points,
517 S* penetration_depth,
520 return detail::planeTriangleIntersect(
521 s, tf1, P1, P2, P3, tf2,
522 contact_points, penetration_depth, normal);
527 template<
typename S,
typename Shape1,
typename Shape2>
533 const Transform3<S>& tf1,
535 const Transform3<S>& tf2,
543 bool res = detail::GJKDistance(
555 (*p1).noalias() = tf1.inverse(Eigen::Isometry) * *p1;
558 (*p2).noalias() = tf2.inverse(Eigen::Isometry) * *p2;
568 template<
typename Shape1,
typename Shape2>
571 const Transform3<S>& tf1,
573 const Transform3<S>& tf2,
576 Vector3<S>* p2)
const 579 *
this, s1, tf1, s2, tf2, dist, p1, p2);
613 const Transform3<S>& tf1,
615 const Transform3<S>& tf2,
620 return detail::sphereCapsuleDistance(s1, tf1, s2, tf2, dist, p1, p2);
631 const Transform3<S>& tf1,
633 const Transform3<S>& tf2,
638 return detail::sphereCapsuleDistance(s2, tf2, s1, tf1, dist, p2, p1);
649 const Transform3<S>& tf1,
651 const Transform3<S>& tf2,
656 return detail::sphereSphereDistance(s1, tf1, s2, tf2, dist, p1, p2);
667 const Transform3<S>& tf1,
669 const Transform3<S>& tf2,
674 return detail::capsuleCapsuleDistance(s1, tf1, s2, tf2, dist, p1, p2);
679 template<
typename S,
typename Shape>
685 const Transform3<S>& tf,
686 const Vector3<S>& P1,
687 const Vector3<S>& P2,
688 const Vector3<S>& P3,
694 void* o2 = detail::triCreateGJKObject(P1, P2, P3);
696 bool res = detail::GJKDistance(
700 detail::triGetSupportFunction(),
707 (*p1).noalias() = tf.inverse(Eigen::Isometry) * *p1;
710 detail::triDeleteGJKObject(o2);
718 template<
typename Shape>
721 const Transform3<S>& tf,
722 const Vector3<S>& P1,
723 const Vector3<S>& P2,
724 const Vector3<S>& P3,
727 Vector3<S>* p2)
const 730 *
this, s, tf, P1, P2, P3, dist, p1, p2);
740 const Transform3<S>& tf,
741 const Vector3<S>& P1,
742 const Vector3<S>& P2,
743 const Vector3<S>& P3,
748 return detail::sphereTriangleDistance(s, tf, P1, P2, P3, dist, p1, p2);
753 template<
typename S,
typename Shape>
759 const Transform3<S>& tf1,
760 const Vector3<S>& P1,
761 const Vector3<S>& P2,
762 const Vector3<S>& P3,
763 const Transform3<S>& tf2,
769 void* o2 = detail::triCreateGJKObject(P1, P2, P3, tf2);
771 bool res = detail::GJKDistance(
775 detail::triGetSupportFunction(),
782 (*p1).noalias() = tf1.inverse(Eigen::Isometry) * *p1;
784 (*p2).noalias() = tf2.inverse(Eigen::Isometry) * *p2;
787 detail::triDeleteGJKObject(o2);
795 template<
typename Shape>
798 const Transform3<S>& tf1,
799 const Vector3<S>& P1,
800 const Vector3<S>& P2,
801 const Vector3<S>& P3,
802 const Transform3<S>& tf2,
805 Vector3<S>* p2)
const 808 *
this, s, tf1, P1, P2, P3, tf2, dist, p1, p2);
818 const Transform3<S>& tf1,
819 const Vector3<S>& P1,
820 const Vector3<S>& P2,
821 const Vector3<S>& P3,
822 const Transform3<S>& tf2,
827 return detail::sphereTriangleDistance(
828 s, tf1, P1, P2, P3, tf2, dist, p1, p2);
836 max_collision_iterations = 500;
837 max_distance_iterations = 1000;
838 collision_tolerance = 1e-6;
839 distance_tolerance = 1e-6;
852 const Vector3<S>& guess)
const 861 return Vector3<S>(-1, 0, 0);
Half Space: this is equivalent to the Planed in ODE. The separation plane is defined as n * x = d; Po...
Definition: halfspace.h:55
bool shapeTriangleDistance(const Shape &s, const Transform3< S > &tf, const Vector3< S > &P1, const Vector3< S > &P2, const Vector3< S > &P3, S *dist=nullptr, Vector3< S > *p1=nullptr, Vector3< S > *p2=nullptr) const
distance computation between one shape and a triangle
Definition: gjk_solver_libccd-inl.h:719
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
unsigned int max_collision_iterations
maximum number of iterations used in GJK algorithm for collision
Definition: gjk_solver_libccd.h:150
Definition: gjk_solver_libccd-inl.h:528
FCL_DEPRECATED bool shapeIntersect(const Shape1 &s1, const Transform3< S > &tf1, const Shape2 &s2, const Transform3< S > &tf2, Vector3< S > *contact_points, S *penetration_depth, Vector3< S > *normal) const
intersection checking between two shapes
Center at zero point ellipsoid.
Definition: ellipsoid.h:48
Definition: gjk_solver_libccd-inl.h:107
S collision_tolerance
the threshold used in GJK algorithm to stop collision iteration
Definition: gjk_solver_libccd.h:156
Definition: gjk_solver_libccd-inl.h:331
bool shapeTriangleIntersect(const Shape &s, const Transform3< S > &tf, const Vector3< S > &P1, const Vector3< S > &P2, const Vector3< S > &P3, Vector3< S > *contact_points=nullptr, S *penetration_depth=nullptr, Vector3< S > *normal=nullptr) const
intersection checking between one shape and a triangle
Definition: gjk_solver_libccd-inl.h:369
static void * createGJKObject(const T &, const Transform3< S > &)
Get GJK object from a shape Notice that only local transformation is applied. Gloal transformation ar...
Definition: gjk_libccd.h:82
initialize GJK stuffs
Definition: gjk_libccd.h:70
Definition: gjk_solver_libccd-inl.h:680
static GJKCenterFunction getCenterFunction()
Get GJK center function.
Definition: gjk_libccd.h:77
collision and distance solver based on libccd library.
Definition: gjk_solver_libccd.h:53
S distance_tolerance
the threshold used in GJK algorithm to stop distance iteration
Definition: gjk_solver_libccd.h:159
Center at zero point capsule.
Definition: capsule.h:48
bool shapeDistance(const Shape1 &s1, const Transform3< S > &tf1, const Shape2 &s2, const Transform3< S > &tf2, S *dist=nullptr, Vector3< S > *p1=nullptr, Vector3< S > *p2=nullptr) const
distance computation between two shapes
Definition: gjk_solver_libccd-inl.h:569
Center at zero point, axis aligned box.
Definition: box.h:48
static void deleteGJKObject(void *o)
Delete GJK object.
Definition: gjk_libccd.h:85
Infinite plane.
Definition: plane.h:48
Center at zero cylinder.
Definition: cylinder.h:48
Center at zero cone.
Definition: cone.h:48
Center at zero point sphere.
Definition: sphere.h:48
GJKSolver_libccd()
default setting for GJK algorithm
Definition: gjk_solver_libccd-inl.h:834
unsigned int max_distance_iterations
maximum number of iterations used in GJK algorithm for distance
Definition: gjk_solver_libccd.h:153
static GJKSupportFunction getSupportFunction()
Get GJK support function.
Definition: gjk_libccd.h:74