53struct COAL_DLLAPI
GJK {
81 for (
size_t i = 0; i < 4; ++i)
vertex[i] =
nullptr;
124 size_t max_iterations;
133 size_t iterations_momentum_stop;
144 : max_iterations(max_iterations_), tolerance(tolerance_) {
145 COAL_ASSERT(tolerance_ > 0,
"Tolerance must be positive.",
146 std::invalid_argument);
165 sv.
w = sv.
w0 - sv.
w1;
215 return iterations_momentum_stop;
225 inline void removeVertex(Simplex& simplex);
228 inline void appendVertex(Simplex& simplex,
const Vec3s& v,
246 bool projectLineOrigin(
const Simplex& current, Simplex& next);
250 bool projectTriangleOrigin(
const Simplex& current, Simplex& next);
254 bool projectTetrahedraOrigin(
const Simplex& current, Simplex& next);
294 if (
root !=
nullptr)
root->prev_face = face;
313 assert(ea == 0 || ea == 1 || ea == 2);
314 assert(eb == 0 || eb == 1 || eb == 2);
353 size_t max_iterations;
356 std::vector<SimplexVertex> sv_store;
357 std::vector<SimplexFace> fc_store;
364 : max_iterations(max_iterations_), tolerance(tolerance_) {
371 : max_iterations(other.max_iterations),
372 tolerance(other.tolerance),
373 sv_store(other.sv_store),
374 fc_store(other.fc_store) {
436 SimplexFace* newFace(
size_t id_a,
size_t id_b,
size_t id_vertex,
#define COAL_ASSERT(check, message, exception)
Definition fwd.hh:82
Main namespace.
Definition broadphase_bruteforce.h:44
GJKConvergenceCriterionType
Wether the convergence criterion is scaled on the norm of the solution or not.
Definition data_types.h:108
Eigen::Vector2i support_func_guess_t
Definition data_types.h:87
GJKConvergenceCriterion
Which convergence criterion is used to stop the algorithm (when the shapes are not in collision)....
Definition data_types.h:104
Eigen::Matrix< CoalScalar, 3, 1 > Vec3s
Definition data_types.h:77
double CoalScalar
Definition data_types.h:76
GJKVariant
Variant to use for the GJK algorithm.
Definition data_types.h:98
The simplex list of EPA is a linked list of faces. Note: EPA's linked list does not own any memory....
Definition gjk.h:281
SimplexFace * root
Definition gjk.h:282
void reset()
Definition gjk.h:286
size_t count
Definition gjk.h:283
void append(SimplexFace *face)
Definition gjk.h:291
SimplexFaceList()
Definition gjk.h:284
void remove(SimplexFace *face)
Definition gjk.h:299
size_t adjacent_edge[3]
Definition gjk.h:269
Vec3s n
Definition gjk.h:261
CoalScalar d
Definition gjk.h:262
SimplexFace * adjacent_faces[3]
Definition gjk.h:266
size_t vertex_id[3]
Definition gjk.h:265
bool ignore
Definition gjk.h:263
SimplexFace * next_face
Definition gjk.h:268
size_t pass
Definition gjk.h:273
SimplexFace()
Definition gjk.h:275
SimplexFace * prev_face
Definition gjk.h:267
SimplexHorizon()
Definition gjk.h:325
SimplexFace * first_face
Definition gjk.h:323
size_t num_faces
Definition gjk.h:324
SimplexFace * current_face
Definition gjk.h:322
size_t getNumMaxIterations() const
Get the max number of iterations of EPA.
Definition gjk.h:379
void reset(size_t max_iterations, CoalScalar tolerance)
resets the EPA algorithm, preparing it for a new run. It potentially reallocates memory for the verti...
support_func_guess_t support_hint
Definition gjk.h:346
Vec3s normal
Definition gjk.h:345
GJK::SimplexV SimplexVertex
Definition gjk.h:259
Status status
Definition gjk.h:343
Status
Definition gjk.h:329
@ AccuracyReached
Definition gjk.h:333
@ DidNotRun
Definition gjk.h:330
@ InvalidHull
Definition gjk.h:336
@ OutOfFaces
Definition gjk.h:337
@ Failed
Definition gjk.h:331
@ Valid
Definition gjk.h:332
@ Degenerated
Definition gjk.h:334
@ OutOfVertices
Definition gjk.h:338
@ NonConvex
Definition gjk.h:335
@ FallBack
Definition gjk.h:339
CoalScalar depth
Definition gjk.h:347
EPA(const EPA &other)
Copy constructor of EPA. Mostly needed for the copy constructor of GJKSolver.
Definition gjk.h:370
size_t getNumVertices() const
Get the number of vertices in the polytope of the last run of EPA.
Definition gjk.h:394
static void bind(SimplexFace *fa, size_t ea, SimplexFace *fb, size_t eb)
We bind the face fa along its edge ea to the face fb along its edge fb.
Definition gjk.h:311
CoalScalar getTolerance() const
Get the tolerance of EPA.
Definition gjk.h:388
size_t getNumMaxFaces() const
Get the max number of faces of EPA.
Definition gjk.h:385
size_t getNumIterations() const
Get the number of iterations of the last run of EPA.
Definition gjk.h:391
GJK::Simplex result
Definition gjk.h:344
Status evaluate(GJK &gjk, const Vec3s &guess)
size_t getNumFaces() const
Get the number of faces in the polytope of the last run of EPA.
Definition gjk.h:397
size_t getNumMaxVertices() const
Get the max number of vertices of EPA.
Definition gjk.h:382
EPA(size_t max_iterations_, CoalScalar tolerance_)
Definition gjk.h:363
void getWitnessPointsAndNormal(const MinkowskiDiff &shape, Vec3s &w0, Vec3s &w1, Vec3s &normal) const
SimplexFace * closest_face
Definition gjk.h:348
Vec3s w0
support vector for shape 0 and 1.
Definition gjk.h:56
Vec3s w
support vector (i.e., the furthest point on the shape along the support direction)
Definition gjk.h:59
Vec3s w1
Definition gjk.h:56
A simplex is a set of up to 4 vertices. Its rank is the number of vertices it contains.
Definition gjk.h:71
vertex_id_t rank
size of simplex (number of vertices)
Definition gjk.h:75
SimplexV * vertex[4]
simplex vertex
Definition gjk.h:73
void reset()
Definition gjk.h:79
Simplex()
Definition gjk.h:77
class for GJK algorithm
Definition gjk.h:53
void reset(size_t max_iterations_, CoalScalar tolerance_)
resets the GJK algorithm, preparing it for a new run. Other than the maximum number of iterations and...
void getWitnessPointsAndNormal(const MinkowskiDiff &shape, Vec3s &w0, Vec3s &w1, Vec3s &normal) const
Vec3s getGuessFromSimplex() const
get the guess from current simplex
void getSupport(const Vec3s &d, SimplexV &sv, support_func_guess_t &hint) const
apply the support function along a direction, the result is return in sv
Definition gjk.h:162
GJKConvergenceCriterionType convergence_criterion_type
Definition gjk.h:108
void setDistanceEarlyBreak(const CoalScalar &dup)
Distance threshold for early break. GJK stops when it proved the distance is more than this threshold...
Definition gjk.h:194
support_func_guess_t support_hint
Definition gjk.h:112
Status evaluate(const MinkowskiDiff &shape, const Vec3s &guess, const support_func_guess_t &supportHint=support_func_guess_t::Zero())
GJK algorithm, given the initial value guess.
GJKVariant gjk_variant
Definition gjk.h:106
MinkowskiDiff const * shape
Definition gjk.h:110
CoalScalar distance
The distance between the two shapes, computed by GJK. If the distance is below GJK's threshold,...
Definition gjk.h:118
GJK(size_t max_iterations_, CoalScalar tolerance_)
Definition gjk.h:143
size_t getNumIterationsMomentumStopped() const
Get GJK number of iterations before momentum stops. Only usefull if the Nesterov or Polyak accelerati...
Definition gjk.h:214
CoalScalar distance_upper_bound
Definition gjk.h:104
Simplex * simplex
Definition gjk.h:119
size_t getNumIterations() const
Get the number of iterations of the last run of GJK.
Definition gjk.h:210
Vec3s ray
Definition gjk.h:111
unsigned char vertex_id_t
Definition gjk.h:62
size_t getNumMaxIterations() const
Get the max number of iterations of GJK.
Definition gjk.h:204
GJKConvergenceCriterion convergence_criterion
Definition gjk.h:107
Status
Status of the GJK algorithm: DidNotRun: GJK has not been run. Failed: GJK did not converge (it exceed...
Definition gjk.h:94
@ Collision
Definition gjk.h:100
@ DidNotRun
Definition gjk.h:95
@ Failed
Definition gjk.h:96
@ NoCollisionEarlyStopped
Definition gjk.h:97
@ CollisionWithPenetrationInformation
Definition gjk.h:99
@ NoCollision
Definition gjk.h:98
CoalScalar getTolerance() const
Get the tolerance of GJK.
Definition gjk.h:207
bool hasClosestPoints() const
Tells whether the closest points are available.
Definition gjk.h:176
Status status
Definition gjk.h:105
bool checkConvergence(const Vec3s &w, const CoalScalar &rl, CoalScalar &alpha, const CoalScalar &omega) const
Convergence check used to stop GJK when shapes are not in collision.
bool encloseOrigin()
whether the simplex enclose the origin
Simplex * getSimplex() const
get the underlying simplex using in GJK, can be used for cache in next iteration
Definition gjk.h:173
Minkowski difference class of two shapes.
Definition minkowski_difference.h:53