39 #ifndef HPP_FCL_SRC_NARROWPHASE_DETAILS_H
40 #define HPP_FCL_SRC_NARROWPHASE_DETAILS_H
52 static inline void lineSegmentPointClosestToPoint(
const Vec3f& p,
63 }
else if (c2 <= c1) {
67 Vec3f Pb = s1 + v * b;
85 lineSegmentPointClosestToPoint(s_c, pos1, pos2, segment_point);
86 normal = segment_point - s_c;
92 static const FCL_REAL eps(std::numeric_limits<FCL_REAL>::epsilon());
98 p1 = s_c + normal * r1;
99 p2 = segment_point - normal * r2;
111 static const FCL_REAL eps(sqrt(std::numeric_limits<FCL_REAL>::epsilon()));
124 assert((B - A - (s2.
halfLength * 2) * u).norm() < eps);
152 normal = (1 / dSp2) * Sp2;
153 p1 = S + r1 * normal;
155 assert(fabs(dist) - (p1 - p2).norm() < eps);
158 normal = p2 - .5 * (A + B);
159 assert(u.dot(normal) >= 0);
162 p1 = S + r1 * normal;
168 dist = dPS - r1 - r2;
185 normal = (1 / dSp2) * Sp2;
186 p1 = S + r1 * normal;
188 assert(fabs(dist) - (p1 - p2).norm() < eps);
191 normal = p2 - .5 * (A + B);
193 p1 = S + r1 * normal;
202 if (ssr1 > 0 || ssr2 > 0) {
205 dist -= (ssr1 + ssr2);
223 Vec3f c1c2 = center2 - center1;
226 if (cdist > Eigen::NumTraits<FCL_REAL>::epsilon()) unit = c1c2 / cdist;
229 p1.noalias() = center1 + r1 * unit;
230 p2.noalias() = center2 - r2 * unit;
237 Vec3f diff = p - from;
253 nearest.noalias() = from + v * t;
254 return diff.squaredNorm();
260 Vec3f edge1(p2 - p1);
261 Vec3f edge2(p3 - p2);
262 Vec3f edge3(p1 - p3);
264 Vec3f p1_to_p(p - p1);
265 Vec3f p2_to_p(p - p2);
266 Vec3f p3_to_p(p - p3);
268 Vec3f edge1_normal(edge1.cross(normal));
269 Vec3f edge2_normal(edge2.cross(normal));
270 Vec3f edge3_normal(edge3.cross(normal));
273 r1 = edge1_normal.dot(p1_to_p);
274 r2 = edge2_normal.dot(p2_to_p);
275 r3 = edge3_normal.dot(p3_to_p);
276 if ((r1 > 0 && r2 > 0 && r3 > 0) || (r1 <= 0 && r2 <= 0 && r3 <= 0)) {
294 Vec3f tri_normal = (P2 - P1).cross(P3 - P1);
295 tri_normal.normalize();
305 Vec3f p1_to_center = center - P1;
306 FCL_REAL distance_from_plane = p1_to_center.dot(tri_normal);
308 Vec3f::Constant(std::numeric_limits<FCL_REAL>::quiet_NaN()));
309 FCL_REAL min_distance_sqr, distance_sqr;
311 if (distance_from_plane < 0) {
312 distance_from_plane *= -1;
317 closest_point = center - tri_normal * distance_from_plane;
318 min_distance_sqr = distance_from_plane * distance_from_plane;
321 Vec3f nearest_on_edge;
325 if (distance_sqr < min_distance_sqr) {
326 min_distance_sqr = distance_sqr;
327 closest_point = nearest_on_edge;
330 if (distance_sqr < min_distance_sqr) {
331 min_distance_sqr = distance_sqr;
332 closest_point = nearest_on_edge;
336 normal = (closest_point - center).normalized();
363 getSupport<details::SupportOptions::WithSweptSphere>(&s, -n_2, hint);
367 p1.noalias() = p2 - dist * new_h.
n;
368 normal.noalias() = new_h.
n;
371 std::sqrt(Eigen::NumTraits<FCL_REAL>::dummy_precision());
373 assert(new_h.
distance(p1) <= dummy_precision);
398 getSupport<details::SupportOptions::WithSweptSphere>(&s, -n_h1, hint);
403 getSupport<details::SupportOptions::WithSweptSphere>(&s, -n_h2, hint);
406 FCL_REAL dist1 = new_h[0].signedDistance(p2h1);
407 FCL_REAL dist2 = new_h[1].signedDistance(p2h2);
410 std::sqrt(Eigen::NumTraits<FCL_REAL>::dummy_precision());
414 if (dist1 >= dist2) {
417 p1.noalias() = p2 - dist * new_h[0].n;
418 normal.noalias() = new_h[0].n;
419 assert(new_h[0].
distance(p1) <= dummy_precision);
423 p1.noalias() = p2 - dist * new_h[1].n;
424 normal.noalias() = new_h[1].n;
425 assert(new_h[1].
distance(p1) <= dummy_precision);
444 bool outside =
false;
445 const Vec3f os_in_b_frame(Rb.transpose() * (os - ob));
447 FCL_REAL min_d = (std::numeric_limits<FCL_REAL>::max)();
448 for (
int i = 0; i < 3; ++i) {
450 if (os_in_b_frame(i) < -b.
halfSide(i)) {
451 pb.noalias() -= b.
halfSide(i) * Rb.col(i);
453 }
else if (os_in_b_frame(i) > b.
halfSide(i)) {
454 pb.noalias() += b.
halfSide(i) * Rb.col(i);
457 pb.noalias() += os_in_b_frame(i) * Rb.col(i);
459 (facedist = b.
halfSide(i) - std::fabs(os_in_b_frame(i))) < min_d) {
472 if (os_in_b_frame(axis) >= 0) {
473 normal = Rb.col(axis);
475 normal = -Rb.col(axis);
479 ps = os - s.
radius * normal;
480 if (!outside || dist <= 0) {
482 pb = ps - dist * normal;
488 if (ssrb > 0 || ssrs > 0) {
491 dist -= (ssrb + ssrs);
518 Vec3f dir = (new_s1.
n).cross(new_s2.
n);
519 FCL_REAL dir_sq_norm = dir.squaredNorm();
521 if (dir_sq_norm < std::numeric_limits<FCL_REAL>::epsilon())
523 if (new_s1.
n.dot(new_s2.
n) > 0) {
526 distance = -(std::numeric_limits<FCL_REAL>::max)();
527 if (new_s1.
d <= new_s2.
d) {
530 p2 = new_s2.
n * new_s2.
d;
532 Eigen::NumTraits<FCL_REAL>::dummy_precision());
535 p1 << new_s1.
n * new_s1.
d;
538 Eigen::NumTraits<FCL_REAL>::dummy_precision());
543 p1 = new_s1.
n * new_s1.
d;
544 p2 = new_s2.
n * new_s2.
d;
550 distance = -(std::numeric_limits<FCL_REAL>::max)();
556 ((new_s2.
n * new_s1.
d - new_s1.
n * new_s2.
d).cross(dir)) / dir_sq_norm;
564 if (ssr1 > 0 || ssr2 > 0) {
593 Vec3f dir = (new_s1.
n).cross(new_s2.
n);
594 FCL_REAL dir_sq_norm = dir.squaredNorm();
596 if (dir_sq_norm < std::numeric_limits<FCL_REAL>::epsilon())
599 distance = new_s1.
n.dot(new_s2.
n) > 0 ? (new_s2.
d - new_s1.
d)
600 : -(new_s1.
d + new_s2.
d);
601 p1 = new_s1.
n * new_s1.
d;
602 p2 = new_s2.
n * new_s2.
d;
604 Eigen::NumTraits<FCL_REAL>::dummy_precision());
606 Eigen::NumTraits<FCL_REAL>::dummy_precision());
611 distance = -(std::numeric_limits<FCL_REAL>::max)();
617 ((new_s2.
n * new_s1.
d - new_s1.
n * new_s2.
d).cross(dir)) / dir_sq_norm;
625 if (ssr1 > 0 || ssr2 > 0) {
653 Vec3f dir = (new_s1.
n).cross(new_s2.
n);
654 FCL_REAL dir_sq_norm = dir.squaredNorm();
656 if (dir_sq_norm < std::numeric_limits<FCL_REAL>::epsilon())
658 p1 = new_s1.
n * new_s1.
d;
659 p2 = new_s2.
n * new_s2.
d;
661 Eigen::NumTraits<FCL_REAL>::dummy_precision());
663 Eigen::NumTraits<FCL_REAL>::dummy_precision());
666 if (
distance > Eigen::NumTraits<FCL_REAL>::dummy_precision()) {
667 normal = (p2 - p1).normalized();
675 distance = -(std::numeric_limits<FCL_REAL>::max)();
681 ((new_s2.
n * new_s1.
d - new_s1.
n * new_s2.
d).cross(dir)) / dir_sq_norm;
689 if (ssr1 > 0 || ssr2 > 0) {
703 Vec3f u((P2 - P1).cross(P3 - P1));
704 normal = u.normalized();
705 FCL_REAL depth1((P1 - Q1).dot(normal));
706 FCL_REAL depth2((P1 - Q2).dot(normal));
707 FCL_REAL depth3((P1 - Q3).dot(normal));
708 return std::max(depth1, std::max(depth2, depth3));
Center at zero point, axis aligned box.
Definition: geometric_shapes.h:164
Capsule It is where is the distance between the point x and the capsule segment AB,...
Definition: geometric_shapes.h:381
Cylinder along Z axis. The cylinder is defined at its centroid.
Definition: geometric_shapes.h:555
Half Space: this is equivalent to the Plane in ODE. A Half space has a priviledged direction: the dir...
Definition: geometric_shapes.h:885
Infinite plane. A plane can be viewed as two half spaces; it has no priviledged direction....
Definition: geometric_shapes.h:976
Base class for all basic geometric shapes.
Definition: geometric_shapes.h:59
Center at zero point sphere.
Definition: geometric_shapes.h:238
Triangle stores the points instead of only indices of points.
Definition: geometric_shapes.h:109
#define HPP_FCL_UNUSED_VARIABLE(var)
Definition: fwd.hh:56
FCL_REAL distance(const Matrix3f &R0, const Vec3f &T0, const kIOS &b1, const kIOS &b2, Vec3f *P=NULL, Vec3f *Q=NULL)
Approximate distance between two kIOS bounding volumes.
Vec3f c
Definition: geometric_shapes.h:147
FCL_REAL halfLength
Half Length along z axis.
Definition: geometric_shapes.h:400
FCL_REAL getSweptSphereRadius() const
Get radius of sphere swept around the shape. This radius is always >= 0.
Definition: geometric_shapes.h:87
FCL_REAL distance(const Vec3f &p) const
Definition: geometric_shapes.h:917
Vec3f a
Definition: geometric_shapes.h:147
FCL_REAL halfLength
Half Length along z axis.
Definition: geometric_shapes.h:582
Vec3f n
Plane normal.
Definition: geometric_shapes.h:1027
FCL_REAL radius
Radius of capsule.
Definition: geometric_shapes.h:394
Vec3f n
Plane normal.
Definition: geometric_shapes.h:949
FCL_REAL signedDistance(const Vec3f &p) const
Definition: geometric_shapes.h:913
FCL_REAL distance(const Vec3f &p) const
Definition: geometric_shapes.h:1016
FCL_REAL d
Plane offset.
Definition: geometric_shapes.h:1030
FCL_REAL radius
Radius of the sphere.
Definition: geometric_shapes.h:248
Vec3f halfSide
box side half-length
Definition: geometric_shapes.h:187
FCL_REAL radius
Radius of the cylinder.
Definition: geometric_shapes.h:576
Vec3f b
Definition: geometric_shapes.h:147
FCL_REAL d
Plane offset.
Definition: geometric_shapes.h:952
FCL_REAL halfspaceHalfspaceDistance(const Halfspace &s1, const Transform3f &tf1, const Halfspace &s2, const Transform3f &tf2, Vec3f &p1, Vec3f &p2, Vec3f &normal)
return distance between two halfspaces
Definition: details.h:509
FCL_REAL sphereCapsuleDistance(const Sphere &s1, const Transform3f &tf1, const Capsule &s2, const Transform3f &tf2, Vec3f &p1, Vec3f &p2, Vec3f &normal)
Definition: details.h:76
FCL_REAL sphereCylinderDistance(const Sphere &s1, const Transform3f &tf1, const Cylinder &s2, const Transform3f &tf2, Vec3f &p1, Vec3f &p2, Vec3f &normal)
Definition: details.h:107
FCL_REAL sphereSphereDistance(const Sphere &s1, const Transform3f &tf1, const Sphere &s2, const Transform3f &tf2, Vec3f &p1, Vec3f &p2, Vec3f &normal)
Definition: details.h:215
FCL_REAL boxSphereDistance(const Box &b, const Transform3f &tfb, const Sphere &s, const Transform3f &tfs, Vec3f &pb, Vec3f &ps, Vec3f &normal)
Definition: details.h:435
FCL_REAL computePenetration(const Vec3f &P1, const Vec3f &P2, const Vec3f &P3, const Vec3f &Q1, const Vec3f &Q2, const Vec3f &Q3, Vec3f &normal)
See the prototype below.
Definition: details.h:699
FCL_REAL halfspaceDistance(const Halfspace &h, const Transform3f &tf1, const ShapeBase &s, const Transform3f &tf2, Vec3f &p1, Vec3f &p2, Vec3f &normal)
Definition: details.h:347
FCL_REAL planeDistance(const Plane &plane, const Transform3f &tf1, const ShapeBase &s, const Transform3f &tf2, Vec3f &p1, Vec3f &p2, Vec3f &normal)
Definition: details.h:381
FCL_REAL planePlaneDistance(const Plane &s1, const Transform3f &tf1, const Plane &s2, const Transform3f &tf2, Vec3f &p1, Vec3f &p2, Vec3f &normal)
return distance between two planes
Definition: details.h:646
FCL_REAL halfspacePlaneDistance(const Halfspace &s1, const Transform3f &tf1, const Plane &s2, const Transform3f &tf2, Vec3f &p1, Vec3f &p2, Vec3f &normal)
return distance between plane and halfspace.
Definition: details.h:585
bool projectInTriangle(const Vec3f &p1, const Vec3f &p2, const Vec3f &p3, const Vec3f &normal, const Vec3f &p)
Whether a point's projection is in a triangle.
Definition: details.h:258
FCL_REAL sphereTriangleDistance(const Sphere &s, const Transform3f &tf1, const TriangleP &tri, const Transform3f &tf2, Vec3f &p1, Vec3f &p2, Vec3f &normal)
Definition: details.h:286
FCL_REAL segmentSqrDistance(const Vec3f &from, const Vec3f &to, const Vec3f &p, Vec3f &nearest)
the minimum distance from a point to a line
Definition: details.h:235
Eigen::Matrix< FCL_REAL, 3, 3 > Matrix3f
Definition: data_types.h:71
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
Definition: data_types.h:67
std::array< Halfspace, 2 > transformToHalfspaces(const Plane &a, const Transform3f &tf)
Halfspace transform(const Halfspace &a, const Transform3f &tf)
double FCL_REAL
Definition: data_types.h:66
Main namespace.
Definition: broadphase_bruteforce.h:44