@@ -76,7 +76,8 @@ struct HPP_FCL_DLLAPI GJKSolver {
76
76
Vec3f p1 (Vec3f::Zero ()), p2 (Vec3f::Zero ());
77
77
Vec3f n (Vec3f::Zero ());
78
78
FCL_REAL distance ((std::numeric_limits<FCL_REAL>::max)());
79
- bool gjk_and_epa_ran_successfully = runGJKAndEPA (tf1, distance, p1, p2, n);
79
+ bool gjk_and_epa_ran_successfully =
80
+ runGJKAndEPA (s1, tf1, s2, tf2, distance, p1, p2, n);
80
81
HPP_FCL_UNUSED_VARIABLE (gjk_and_epa_ran_successfully);
81
82
if (normal != NULL ) *normal = n;
82
83
if (contact_points != NULL ) *contact_points = 0.5 * (p1 + p2);
@@ -100,9 +101,10 @@ struct HPP_FCL_DLLAPI GJKSolver {
100
101
TriangleP tri (tf_1M2.transform (P1), tf_1M2.transform (P2),
101
102
tf_1M2.transform (P3));
102
103
103
- minkowski_difference. set (&s, &tri) ;
104
+ bool relative_transformation_already_computed = true ;
104
105
bool gjk_and_epa_ran_successfully =
105
- runGJKAndEPA (tf1, distance, p1, p2, normal );
106
+ runGJKAndEPA (s, tf1, tri, tf_1M2, distance, p1, p2, normal ,
107
+ relative_transformation_already_computed);
106
108
HPP_FCL_UNUSED_VARIABLE (gjk_and_epa_ran_successfully);
107
109
return (gjk.status == details::GJK::Inside);
108
110
}
@@ -115,9 +117,8 @@ struct HPP_FCL_DLLAPI GJKSolver {
115
117
bool shapeDistance (const S1& s1, const Transform3f& tf1, const S2& s2,
116
118
const Transform3f& tf2, FCL_REAL& distance, Vec3f& p1,
117
119
Vec3f& p2, Vec3f& normal ) const {
118
- minkowski_difference.set (&s1, &s2, tf1, tf2);
119
120
bool gjk_and_epa_ran_successfully =
120
- runGJKAndEPA (tf1, distance, p1, p2, normal );
121
+ runGJKAndEPA (s1, tf1, s2, tf2 , distance, p1, p2, normal );
121
122
return gjk_and_epa_ran_successfully;
122
123
}
123
124
@@ -165,11 +166,19 @@ struct HPP_FCL_DLLAPI GJKSolver {
165
166
// / This function assumes the minkowski difference has been already been set,
166
167
// / i.e. `minkowski_difference.set(&s1, &s2, tf1, tf2);` has been called.
167
168
// / @return true if no error occured, false otherwise.
168
- bool runGJKAndEPA (const Transform3f& tf1, FCL_REAL& distance, Vec3f& p1,
169
- Vec3f& p2, Vec3f& normal ) const {
169
+ template <typename S1, typename S2>
170
+ bool runGJKAndEPA (
171
+ const S1& s1, const Transform3f& tf1, const S2& s2,
172
+ const Transform3f& tf2, FCL_REAL& distance, Vec3f& p1, Vec3f& p2,
173
+ Vec3f& normal ,
174
+ bool relative_transformation_already_computed = false ) const {
170
175
bool gjk_and_epa_ran_successfully = true ;
171
176
172
177
// Reset internal state of GJK algorithm
178
+ if (relative_transformation_already_computed)
179
+ minkowski_difference.set (&s1, &s2);
180
+ else
181
+ minkowski_difference.set (&s1, &s2, tf1, tf2);
173
182
gjk.reset ();
174
183
175
184
// Get initial guess for GJK: default, cached or bounding volume guess
0 commit comments