NetDEM v1.0
Loading...
Searching...
No Matches
netdem::SolverGJKPP Class Reference

GJK solver for convex geometries. More...

#include <solver_gjk_pp.hpp>

Inheritance diagram for netdem::SolverGJKPP:
netdem::CollisionSolverPP

Public Member Functions

 SolverGJKPP ()
 Default constructor for SolverGJKPP.
 
 SolverGJKPP (Particle *const p1, Particle *const p2)
 Constructor for SolverGJKPP.
 
CollisionSolverPPClone () const override
 Creates a copy of this collision solver.
 
void Init (Particle *const p1, Particle *const p2) override
 Initializes the collision solver with two particles.
 
bool Detect () override
 Detects collisions between the two particles.
 
void ResolveInit (ContactPP *const cnt, double timestep) override
 Initializes the contact point between two particles at time t = 0.
 
void ResolveUpdate (ContactPP *const cnt, double timestep) override
 Updates the contact point between two particles at time t > 0.
 
void ResolveInit (CollisionGeometries *const cnt_geoms, double timestep)
 Initializes the contact geometries between two particles at time t = 0.
 
void ResolveUpdate (CollisionGeometries *const cnt_geoms, double timestep)
 Updates the contact geometries between two particles at time t > 0.
 
- Public Member Functions inherited from netdem::CollisionSolverPP
 CollisionSolverPP ()
 
 CollisionSolverPP (Particle *const p1, Particle *const p2)
 
virtual bool Detect (ContactPP *const cnt)
 
virtual ~CollisionSolverPP ()
 

Public Attributes

double erosion_ratio_initial {0.01}
 < The initial ratio of erosion for the terrain.
 
double erosion_ratio_increment {0.01}
 Whether to use erosion for the terrain or not.
 
bool use_erosion {false}
 
bool enable_logging {false}
 Flag to determine whether logging is enabled.
 
- Public Attributes inherited from netdem::CollisionSolverPP
Particleparticle_1 {nullptr}
 
Particleparticle_2 {nullptr}
 

Protected Member Functions

bool GJK ()
 Runs the Gilbert-Johnson-Keerthi algorithm.
 
std::tuple< double, Vec3d, Vec3dGJK_EROSION ()
 Runs the Gilbert-Johnson-Keerthi algorithm with erosion applied.
 
std::tuple< double, Vec3d, Vec3dEPA ()
 Runs the Expanding Polytope Algorithm.
 
std::tuple< Vec3d, bool > GetContactPoint (Vec3d const &dir)
 Computes the contact point along a given direction.
 
std::tuple< Vec3d, bool > GetContactPoint_PlaneCase (Vec3d const &dir, const VecXT< Vec3d > &pos_vec_1, const VecXT< Vec3d > &pos_vec_2)
 Computes the contact point in the case where one of the shapes is a plane.
 
Vec3d MinkowskiDiff (Vec3d const &dir, double erosion_ratio=0)
 Computes the Minkowski difference of two shapes along a given direction.
 
void UpdateSimplex (Simplex *const s, Vec3d *const dir, double *const min_dist, bool *const cnt_flag)
 Updates the simplex used in the Gilbert-Johnson-Keerthi algorithm.
 
void UpdateSimplexLine (Simplex *const s, Vec3d *const dir, double *const min_dist, bool *const cnt_flag)
 Updates the simplex when it contains a line segment.
 
void UpdateSimplexTriangle (Simplex *const s, Vec3d *const dir, double *const min_dist, bool *const cnt_flag)
 Updates the simplex when it contains a triangle.
 
void UpdateSimplexTetrahedron (Simplex *const s, Vec3d *const dir, double *const min_dist, bool *const cnt_flag)
 Updates the simplex when it contains a tetrahedron.
 
std::tuple< Vec3d, double > GetFacetNormal (Vec3d const &a, Vec3d const &b, Vec3d const &c)
 Computes the normal and distance from origin of a facet defined by three vertices.
 
void GetLooseEdges (VecXT< Vec2i > *const edges, Vec3i const &facet)
 Computes the edges of a triangle that could potentially be involved in a collision.
 
void GetIntersections (VecXT< Vec3d > *const intersects, Vec3d const &dir_n, Vec3d const &l1_p1, Vec3d const &l1_p2, Vec3d const &l2_p1, Vec3d const &l2_p2)
 Computes the intersection points of two line segments.
 
void GetIntersectionsAggresive (VecXT< Vec3d > *const intersects, Vec3d const &dir_n, Vec3d const &l1_p1, Vec3d const &l1_p2, Vec3d const &l2_p1, Vec3d const &l2_p2)
 Computes the intersection points of two line segments using a more aggressive algorithm.
 
void SortVertices (VecXT< Vec3d > *const pos_vec, Vec3d const &dir_n)
 Sorts the vertices of a polygon based on their distance to a given point.
 
bool IsInsidePolygon (VecXT< Vec3d > const &pos_vec, Vec3d const &dir_n, Vec3d const &pos)
 Determines whether a point is inside a polygon.
 
Vec3d GetPolygonCentroid (VecXT< Vec3d > const &pos_vec, Vec3d const &dir_n)
 Computes the centroid of a polygon.
 
- Protected Member Functions inherited from netdem::CollisionSolverPP
void InitBasicGeoms (CollisionGeometries *const cnt_geoms, double timestep)
 
void UpdateBasicGeoms (CollisionGeometries *const cnt_geoms, double timestep, Vec3d const &dir_n_old)
 Update the basic contact geometries associated with a collision.
 

Protected Attributes

Shapeshape_1 {nullptr}
 
Shapeshape_2 {nullptr}
 
double bound_sphere_radius_1
 
double bound_sphere_radius_2
 
Vec3d dpos_12
 
Vec3d dpos_12_ref
 
Vec4d dquat_12
 
Vec4d dquat_12_conj
 
Simplex simplex_after_gjk
 

Detailed Description

Constructor & Destructor Documentation

◆ SolverGJKPP() [1/2]

netdem::SolverGJKPP::SolverGJKPP ( )

Default constructor for SolverGJKPP.

◆ SolverGJKPP() [2/2]

netdem::SolverGJKPP::SolverGJKPP ( Particle *const p1,
Particle *const p2 )

Constructor for SolverGJKPP.

Parameters
p1The first particle.
p2The second particle.

Member Function Documentation

◆ Clone()

CollisionSolverPP * netdem::SolverGJKPP::Clone ( ) const
overridevirtual

Creates a copy of this collision solver.

Returns
A new instance of the collision solver.

Implements netdem::CollisionSolverPP.

◆ Detect()

bool netdem::SolverGJKPP::Detect ( )
overridevirtual

Detects collisions between the two particles.

Returns
True if a collision occurred, false otherwise.

Implements netdem::CollisionSolverPP.

Examples
2_ev_gjk_performance.cpp, 31_test_dataset_ellipsoid.cpp, 36_test_ann_vs_geom_ellipsoid.cpp, and 37_test_ann_vs_geom_ellipsoid.cpp.

◆ EPA()

tuple< double, Vec3d, Vec3d > netdem::SolverGJKPP::EPA ( )
protected

Runs the Expanding Polytope Algorithm.

Returns
A tuple containing the contact position and a flag indicating whether the algorithm succeeded.

◆ GetContactPoint()

tuple< Vec3d, bool > netdem::SolverGJKPP::GetContactPoint ( Vec3d const & dir)
protected

Computes the contact point along a given direction.

Parameters
dirThe direction to compute the contact point along.
Returns
A tuple containing the contact position and a flag indicating whether the algorithm succeeded.

◆ GetContactPoint_PlaneCase()

tuple< Vec3d, bool > netdem::SolverGJKPP::GetContactPoint_PlaneCase ( Vec3d const & dir,
const VecXT< Vec3d > & pos_vec_1,
const VecXT< Vec3d > & pos_vec_2 )
protected

Computes the contact point in the case where one of the shapes is a plane.

Parameters
dirThe contact normal.
pos_vec_1The positions of the vertices of shape 1.
pos_vec_2The positions of the vertices of shape 2.
Returns
A tuple containing the contact position and a flag indicating whether the algorithm succeeded.

◆ GetFacetNormal()

std::tuple< Vec3d, double > netdem::SolverGJKPP::GetFacetNormal ( Vec3d const & a,
Vec3d const & b,
Vec3d const & c )
inlineprotected

Computes the normal and distance from origin of a facet defined by three vertices.

Parameters
aThe first vertex.
bThe second vertex.
cThe third vertex.
Returns
A tuple containing the facet normal and distance from origin.

◆ GetIntersections()

void netdem::SolverGJKPP::GetIntersections ( VecXT< Vec3d > *const intersects,
Vec3d const & dir_n,
Vec3d const & l1_p1,
Vec3d const & l1_p2,
Vec3d const & l2_p1,
Vec3d const & l2_p2 )
protected

Computes the intersection points of two line segments.

Parameters
intersectsThe output vector of intersection points.
dir_nThe direction of the line segments.
l1_p1The starting point of the first line segment.
l1_p2The ending point of the first line segment.
l2_p1The starting point of the second line segment.
l2_p2The ending point of the second line segment.

◆ GetIntersectionsAggresive()

void netdem::SolverGJKPP::GetIntersectionsAggresive ( VecXT< Vec3d > *const intersects,
Vec3d const & dir_n,
Vec3d const & l1_p1,
Vec3d const & l1_p2,
Vec3d const & l2_p1,
Vec3d const & l2_p2 )
protected

Computes the intersection points of two line segments using a more aggressive algorithm.

Parameters
intersectsThe output vector of intersection points.
dir_nThe direction of the line segments.
l1_p1The starting point of the first line segment.
l1_p2The ending point of the first line segment.
l2_p1The starting point of the second line segment.
l2_p2The ending point of the second line segment.

◆ GetLooseEdges()

void netdem::SolverGJKPP::GetLooseEdges ( VecXT< Vec2i > *const edges,
Vec3i const & facet )
protected

Computes the edges of a triangle that could potentially be involved in a collision.

Parameters
edgesThe output vector of edges.
facetThe indices of the vertices defining the triangle.

◆ GetPolygonCentroid()

Vec3d netdem::SolverGJKPP::GetPolygonCentroid ( VecXT< Vec3d > const & pos_vec,
Vec3d const & dir_n )
protected

Computes the centroid of a polygon.

Parameters
pos_vecThe vector of vertices defining the polygon.
dir_nThe normal of the polygon.
Returns
The centroid of the polygon.

◆ GJK()

bool netdem::SolverGJKPP::GJK ( )
protected

Runs the Gilbert-Johnson-Keerthi algorithm.

Returns
True if a collision occurred, false otherwise.

◆ GJK_EROSION()

tuple< double, Vec3d, Vec3d > netdem::SolverGJKPP::GJK_EROSION ( )
protected

Runs the Gilbert-Johnson-Keerthi algorithm with erosion applied.

Returns
A tuple containing the length of the contact normal, the contact direction, and the contact position.

◆ Init()

void netdem::SolverGJKPP::Init ( Particle *const p1,
Particle *const p2 )
overridevirtual

Initializes the collision solver with two particles.

Parameters
p1The first particle.
p2The second particle.

Reimplemented from netdem::CollisionSolverPP.

Examples
2_ev_gjk_performance.cpp, 31_test_dataset_ellipsoid.cpp, 36_test_ann_vs_geom_ellipsoid.cpp, and 37_test_ann_vs_geom_ellipsoid.cpp.

◆ IsInsidePolygon()

bool netdem::SolverGJKPP::IsInsidePolygon ( VecXT< Vec3d > const & pos_vec,
Vec3d const & dir_n,
Vec3d const & pos )
protected

Determines whether a point is inside a polygon.

Parameters
pos_vecThe vector of vertices defining the polygon.
dir_nThe normal of the polygon.
posThe position of the point to test.
Returns
True if the point is inside the polygon, false otherwise.

◆ MinkowskiDiff()

Vec3d netdem::SolverGJKPP::MinkowskiDiff ( Vec3d const & dir,
double erosion_ratio = 0 )
inlineprotected

Computes the Minkowski difference of two shapes along a given direction.

Parameters
dirThe direction to compute the Minkowski difference along.
erosion_ratioThe erosion ratio to apply.
Returns
The Minkowski difference of the two shapes.

◆ ResolveInit() [1/2]

void netdem::SolverGJKPP::ResolveInit ( CollisionGeometries *const cnt_geoms,
double timestep )

Initializes the contact geometries between two particles at time t = 0.

Parameters
cnt_geomsThe contact geometries.
timestepThe simulation timestep.

◆ ResolveInit() [2/2]

void netdem::SolverGJKPP::ResolveInit ( ContactPP *const cnt,
double timestep )
overridevirtual

Initializes the contact point between two particles at time t = 0.

Parameters
cntThe contact point.
timestepThe simulation timestep.

Implements netdem::CollisionSolverPP.

Examples
2_ev_gjk_performance.cpp, 31_test_dataset_ellipsoid.cpp, 36_test_ann_vs_geom_ellipsoid.cpp, and 37_test_ann_vs_geom_ellipsoid.cpp.

◆ ResolveUpdate() [1/2]

void netdem::SolverGJKPP::ResolveUpdate ( CollisionGeometries *const cnt_geoms,
double timestep )

Updates the contact geometries between two particles at time t > 0.

Parameters
cnt_geomsThe contact geometries.
timestepThe simulation timestep.

◆ ResolveUpdate() [2/2]

void netdem::SolverGJKPP::ResolveUpdate ( ContactPP *const cnt,
double timestep )
overridevirtual

Updates the contact point between two particles at time t > 0.

Parameters
cntThe contact point.
timestepThe simulation timestep.

Implements netdem::CollisionSolverPP.

◆ SortVertices()

void netdem::SolverGJKPP::SortVertices ( VecXT< Vec3d > *const pos_vec,
Vec3d const & dir_n )
protected

Sorts the vertices of a polygon based on their distance to a given point.

Parameters
pos_vecThe vector of vertices to sort.
dir_nThe direction to sort the vertices in.

◆ UpdateSimplex()

void netdem::SolverGJKPP::UpdateSimplex ( Simplex *const s,
Vec3d *const dir,
double *const min_dist,
bool *const cnt_flag )
protected

Updates the simplex used in the Gilbert-Johnson-Keerthi algorithm.

Parameters
sThe simplex to update.
dirThe search direction.
min_distThe minimum distance between the two shapes.
cnt_flagA flag indicating whether a contact has been found.

◆ UpdateSimplexLine()

void netdem::SolverGJKPP::UpdateSimplexLine ( Simplex *const s,
Vec3d *const dir,
double *const min_dist,
bool *const cnt_flag )
protected

Updates the simplex when it contains a line segment.

Parameters
sThe simplex to update.
dirThe search direction.
min_distThe minimum distance between the two shapes.
cnt_flagA flag indicating whether a contact has been found.

◆ UpdateSimplexTetrahedron()

void netdem::SolverGJKPP::UpdateSimplexTetrahedron ( Simplex *const s,
Vec3d *const dir,
double *const min_dist,
bool *const cnt_flag )
protected

Updates the simplex when it contains a tetrahedron.

Parameters
sThe simplex to update.
dirThe search direction.
min_distThe minimum distance between the two shapes.
cnt_flagA flag indicating whether a contact has been found.

◆ UpdateSimplexTriangle()

void netdem::SolverGJKPP::UpdateSimplexTriangle ( Simplex *const s,
Vec3d *const dir,
double *const min_dist,
bool *const cnt_flag )
protected

Updates the simplex when it contains a triangle.

Parameters
sThe simplex to update.
dirThe search direction.
min_distThe minimum distance between the two shapes.
cnt_flagA flag indicating whether a contact has been found.

Member Data Documentation

◆ bound_sphere_radius_1

double netdem::SolverGJKPP::bound_sphere_radius_1
protected

◆ bound_sphere_radius_2

double netdem::SolverGJKPP::bound_sphere_radius_2
protected

◆ dpos_12

Vec3d netdem::SolverGJKPP::dpos_12
protected

◆ dpos_12_ref

Vec3d netdem::SolverGJKPP::dpos_12_ref
protected

◆ dquat_12

Vec4d netdem::SolverGJKPP::dquat_12
protected

◆ dquat_12_conj

Vec4d netdem::SolverGJKPP::dquat_12_conj
protected

◆ enable_logging

bool netdem::SolverGJKPP::enable_logging {false}

Flag to determine whether logging is enabled.

◆ erosion_ratio_increment

double netdem::SolverGJKPP::erosion_ratio_increment {0.01}

Whether to use erosion for the terrain or not.

◆ erosion_ratio_initial

double netdem::SolverGJKPP::erosion_ratio_initial {0.01}

< The initial ratio of erosion for the terrain.

The increment ratio of erosion for the terrain.

Examples
2_ev_gjk_performance.cpp.

◆ shape_1

Shape* netdem::SolverGJKPP::shape_1 {nullptr}
protected

◆ shape_2

Shape * netdem::SolverGJKPP::shape_2 {nullptr}
protected

◆ simplex_after_gjk

Simplex netdem::SolverGJKPP::simplex_after_gjk
protected

◆ use_erosion

bool netdem::SolverGJKPP::use_erosion {false}

The documentation for this class was generated from the following files: