39
39
#define HPP_FCL_COLLISION_DATA_H
40
40
41
41
#include < vector>
42
+ #include < array>
42
43
#include < set>
43
44
#include < limits>
44
45
@@ -70,9 +71,14 @@ struct HPP_FCL_DLLAPI Contact {
70
71
// / if object 2 is octree, it is the id of the cell
71
72
int b2;
72
73
73
- // / @brief contact normal, pointing from o1 to o2
74
+ // / @brief contact normal, pointing from o1 to o2.
75
+ // / See DistanceResult::normal for a complete definition of the normal.
74
76
Vec3f normal ;
75
77
78
+ // / @brief nearest points associated to this contact.
79
+ // / See \ref CollisionResult::nearest_points.
80
+ std::array<Vec3f, 2 > nearest_points;
81
+
76
82
// / @brief contact position, in world space
77
83
Vec3f pos;
78
84
@@ -97,7 +103,24 @@ struct HPP_FCL_DLLAPI Contact {
97
103
b2(b2_),
98
104
normal(normal_),
99
105
pos(pos_),
100
- penetration_depth(depth_) {}
106
+ penetration_depth(depth_) {
107
+ nearest_points[0 ] = pos - 0.5 * depth_ * normal_;
108
+ nearest_points[1 ] = pos + 0.5 * depth_ * normal_;
109
+ }
110
+
111
+ Contact (const CollisionGeometry* o1_, const CollisionGeometry* o2_, int b1_,
112
+ int b2_, const Vec3f& p1, const Vec3f& p2, const Vec3f& normal_,
113
+ FCL_REAL depth_)
114
+ : o1(o1_),
115
+ o2(o2_),
116
+ b1(b1_),
117
+ b2(b2_),
118
+ normal(normal_),
119
+ penetration_depth(depth_) {
120
+ nearest_points[0 ] = p1;
121
+ nearest_points[1 ] = p2;
122
+ pos = (p1 + p2) / 2 ;
123
+ }
101
124
102
125
bool operator <(const Contact& other) const {
103
126
if (b1 == other.b1 ) return b2 < other.b2 ;
@@ -117,7 +140,7 @@ struct QueryResult;
117
140
118
141
// / @brief base class for all query requests
119
142
struct HPP_FCL_DLLAPI QueryRequest {
120
- // @briefInitial guess to use for the GJK algorithm
143
+ // @brief Initial guess to use for the GJK algorithm
121
144
GJKInitialGuess gjk_initial_guess;
122
145
123
146
// / @brief whether enable gjk initial guess
@@ -233,11 +256,13 @@ enum CollisionRequestFlag {
233
256
234
257
// / @brief request to the collision algorithm
235
258
struct HPP_FCL_DLLAPI CollisionRequest : QueryRequest {
236
- // / @brief The maximum number of contacts will return
259
+ // / @brief The maximum number of contacts that can be returned
237
260
size_t num_max_contacts;
238
261
239
262
// / @brief whether the contact information (normal, penetration depth and
240
263
// / contact position) will return
264
+ // / @note Only effective if the collision pair involves an Octree.
265
+ // / Otherwise, it is always true.
241
266
bool enable_contact;
242
267
243
268
// / Whether a lower bound on distance is returned when objects are disjoint
@@ -307,13 +332,21 @@ struct HPP_FCL_DLLAPI CollisionResult : QueryResult {
307
332
public:
308
333
// / Lower bound on distance between objects if they are disjoint.
309
334
// / See \ref hpp_fcl_collision_and_distance_lower_bound_computation
310
- // / @note computed only on request (or if it does not add any computational
311
- // / overhead).
335
+ // / @note Always computed. If \ref CollisionRequest::distance_upper_bound is
336
+ // / set to infinity, distance_lower_bound is the actual distance between the
337
+ // / shapes.
312
338
FCL_REAL distance_lower_bound;
313
339
314
340
// / @brief nearest points
315
341
// / available only when distance_lower_bound is inferior to
316
342
// / CollisionRequest::break_distance.
343
+ // / @note Also referred as "witness points" in other collision libraries.
344
+ // / The points p1 = nearest_points[0] and p2 = nearest_points[1] verify the
345
+ // / property that dist(o1, o2) * (p1 - p2) is the separation vector between o1
346
+ // / and o2, with dist(o1, o2) being the **signed** distance separating o1 from
347
+ // / o2. See \ref DistanceResult::normal for the definition of the separation
348
+ // / vector. If o1 and o2 have multiple contacts, the nearest_points are
349
+ // / associated with the contact which has the greatest penetration depth.
317
350
Vec3f nearest_points[2 ];
318
351
319
352
public:
@@ -419,14 +452,24 @@ struct HPP_FCL_DLLAPI DistanceRequest : QueryRequest {
419
452
// / @brief distance result
420
453
struct HPP_FCL_DLLAPI DistanceResult : QueryResult {
421
454
public:
422
- // / @brief minimum distance between two objects. if two objects are in
455
+ // / @brief minimum distance between two objects. If two objects are in
423
456
// / collision, min_distance <= 0.
424
457
FCL_REAL min_distance;
425
458
426
- // / @brief nearest points
427
- Vec3f nearest_points[2 ];
428
-
429
- // / In case both objects are in collision, store the normal
459
+ // / @brief nearest points.
460
+ // / See CollisionResult::nearest_points.
461
+ std::array<Vec3f, 2 > nearest_points;
462
+
463
+ // / Stores the normal, defined as the normalized separation vector:
464
+ // / normal = (p2 - p1) / dist(o1, o2), where p1 = nearest_points[0]
465
+ // / belongs to o1 and p2 = nearest_points[1] belongs to o2 and dist(o1, o2) is
466
+ // / the **signed** distance between o1 and o2. The normal always points from
467
+ // / o1 to o2.
468
+ // / @note The separation vector is the smallest vector such that if o1 is
469
+ // / translated by it, o1 and o2 are in touching contact (they share at least
470
+ // / one contact point but have a zero intersection volume). If the shapes
471
+ // / overlap, dist(o1, o2) = -((p2-p1).norm()). Otherwise, dist(o1, o2) =
472
+ // / (p2-p1).norm().
430
473
Vec3f normal ;
431
474
432
475
// / @brief collision object 1
0 commit comments