Skip to content

Commit 901b4fa

Browse files
committed
GJKSolver: small optimization to avoid computing two transformations
1 parent 2d6e2fc commit 901b4fa

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

include/hpp/fcl/narrowphase/narrowphase.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -634,9 +634,10 @@ struct HPP_FCL_DLLAPI GJKSolver {
634634
// TODO: On degenerated case, the closest points may be non-unique.
635635
// (i.e. an object face normal is colinear to `gjk.ray`)
636636
gjk.getWitnessPointsAndNormal(this->minkowski_difference, p1, p2, normal);
637-
p1 = tf1.transform(p1);
638-
p2 = tf1.transform(p2);
637+
Vec3f p = tf1.transform(0.5 * (p1 + p2));
639638
normal = tf1.getRotation() * normal;
639+
p1.noalias() = p - 0.5 * distance * normal;
640+
p2.noalias() = p + 0.5 * distance * normal;
640641
}
641642

642643
void GJKCollisionExtractWitnessPointsAndNormal(const Transform3f& tf1,
@@ -702,9 +703,10 @@ struct HPP_FCL_DLLAPI GJKSolver {
702703
// We compute the middle points of the current $p_1$ and $p_2$ and we use
703704
// the normal and the distance given by EPA to compute the new $p_1$ and
704705
// $p_2$.
705-
p1 = tf1.transform(p1);
706-
p2 = tf1.transform(p2);
706+
Vec3f p = tf1.transform(0.5 * (p1 + p2));
707707
normal = tf1.getRotation() * normal;
708+
p1.noalias() = p - 0.5 * distance * normal;
709+
p2.noalias() = p + 0.5 * distance * normal;
708710
}
709711

710712
void EPAFailedExtractWitnessPointsAndNormal(const Transform3f& tf1,

0 commit comments

Comments
 (0)