Struct ContactPatchSolver
Defined in File contact_patch_solver.h
Struct Documentation
-
struct ContactPatchSolver
Solver to compute contact patches, i.e. the intersection between two contact surfaces projected onto the shapes’ separating plane. Otherwise said, a contact patch is simply the intersection between two support sets: the support set of shape S1 in direction
n
and the support set of shape S2 in direction-n
, wheren
is the contact normal (satisfying the optimality conditions of GJK/EPA).TODO(louis): algo improvement:
The clipping algo is currently n1 * n2; it can be done in n1 + n2.
Note
A contact patch is not the support set of the Minkowski Difference in the direction of the normal. A contact patch is actually the support set of the Minkowski difference in the direction of the normal, i.e. the instersection of the shapes support sets as mentioned above.
Public Types
-
using ShapeSupportData = details::ShapeSupportData
-
using SupportSetDirection = SupportSet::PatchDirection
-
typedef void (*SupportSetFunction)(const ShapeBase *shape, SupportSet &support_set, int &hint, ShapeSupportData &support_data, size_t num_sampled_supports, CoalScalar tol)
Support set function for shape si.
- Param shape:
[in] the shape.
- Param [in/out]:
support_set a support set of the shape. A support set is attached to a frame. All the points of the set computed by this function will be expressed in the local frame of the support set. The support set is computed in the direction of the positive z-axis if its direction is DEFAULT, negative z-axis if its direction is INVERTED.
- Param [in/out]:
hint for the support computation of ConvexBase shapes. Gets updated after calling the function onto ConvexBase shapes.
- Param [in/out]:
support_data for the support computation of ConvexBase shapes. Gets updated with visited vertices after calling the function onto ConvexBase shapes.
- Param num_sampled_supports:
[in] for shapes like cone or cylinders which have smooth non-strictly convex sides (their bases are circles), we need to know how many supports we sample from these sides. For any other shape, this parameter is not used.
- Param tol:
[in] the “thickness” of the support plane. Any point v which satisfies
max_{x in shape}(x.dot(dir)) - v.dot(dir) <= tol
is tol distant from the support plane and is added to the support set.
Public Functions
-
inline explicit ContactPatchSolver()
Default constructor.
-
inline explicit ContactPatchSolver(const ContactPatchRequest &request)
Construct the solver with a
ContactPatchRequest
.
-
inline void set(const ContactPatchRequest &request)
Set up the solver using a
ContactPatchRequest
.
-
inline void setSupportGuess(const support_func_guess_t guess) const
Sets the support guess used during support set computation of shapes s1 and s2.
-
template<typename ShapeType1, typename ShapeType2>
void computePatch(const ShapeType1 &s1, const Transform3s &tf1, const ShapeType2 &s2, const Transform3s &tf2, const Contact &contact, ContactPatch &contact_patch) const Main API of the solver: compute a contact patch from a contact between shapes s1 and s2. The contact patch is the (triple) intersection between the separating plane passing (by
contact.pos
and supported bycontact.normal
) and the shapes s1 and s2.
-
template<typename ShapeType1, typename ShapeType2>
inline void reset(const ShapeType1 &shape1, const Transform3s &tf1, const ShapeType2 &shape2, const Transform3s &tf2, const ContactPatch &contact_patch) const Reset the internal quantities of the solver.
-
inline void getResult(const Contact &contact, const ContactPatch::Polygon *result, ContactPatch &contact_patch) const
Retrieve result, adds a post-processing step if result has bigger size than
this->max_patch_size
.
-
inline bool operator==(const ContactPatchSolver &other) const
Public Members
-
size_t num_samples_curved_shapes
Number of points sampled for Cone and Cylinder when the normal is orthogonal to the shapes’ basis. See ContactPatchRequest::m_num_samples_curved_shapes for more details.
-
CoalScalar patch_tolerance
Tolerance below which points are added to the shapes support sets. See ContactPatchRequest::m_patch_tolerance for more details.
-
mutable SupportSetFunction supportFuncShape1
Support set function for shape s1.
-
mutable SupportSetFunction supportFuncShape2
Support set function for shape s2.
-
mutable std::array<ShapeSupportData, 2> supports_data
Temporary data to compute the support sets on each shape.
-
mutable support_func_guess_t support_guess
Guess for the support sets computation.
-
mutable SupportSet support_set_shape1
Holder for support set of shape 1, used for internal computation. After
computePatch
has been called, this support set is no longer valid.
-
mutable SupportSet support_set_shape2
Holder for support set of shape 2, used for internal computation. After
computePatch
has been called, this support set is no longer valid.
-
mutable SupportSet support_set_buffer
Temporary support set used for the Sutherland-Hodgman algorithm.
-
mutable std::vector<bool> added_to_patch
Tracks which point of the Sutherland-Hodgman result have been added to the contact patch. Only used if the post-processing step occurs, i.e. if the result of Sutherland-Hodgman has a size bigger than
max_patch_size
.
Public Static Functions
-
static inline Vec2s computeLineSegmentIntersection(const Vec2s &a, const Vec2s &b, const Vec2s &c, const Vec2s &d)
Note
we make the following hypothesis: 1) c != d (should be when creating initial polytopes) 2) (c, d) is not parallel to ray -> if so, we return d.
- Returns:
the intersecting point between line defined by ray (a, b) and the segment [c, d].
-
static SupportSetFunction makeSupportSetFunction(const ShapeBase *shape, ShapeSupportData &support_data)
Construct support set function for shape.
Public Static Attributes
-
static constexpr size_t default_num_preallocated_supports = 16
Number of vectors to pre-allocate in the
m_clipping_sets
vectors.