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

GJK solver for convex geometries. More...

#include <solver_gjk_pw.hpp>

Inheritance diagram for netdem::SolverGJKPW:
netdem::CollisionSolverPW

Public Member Functions

 SolverGJKPW ()
 Default constructor for the SolverGJKPW class.
 
 SolverGJKPW (Particle *const p, Wall *const w)
 Constructor for the SolverGJKPW class.
 
CollisionSolverPWClone () const override
 Creates a copy of the current collision solver.
 
void Init (Particle *const p, Wall *const w) override
 Initializes the collision solver with a particle and a wall.
 
bool Detect () override
 Detects collisions between a particle and a wall.
 
void ResolveInit (ContactPW *const cnt, double timestep) override
 Initializes the contact resolution for a contact point.
 
void ResolveUpdate (ContactPW *const cnt, double timestep) override
 Updates the contact resolution for a contact point.
 
void ResolveInit (CollisionGeometries *const cnt_geoms, double timestep)
 Initializes the contact resolution for a set of collision geometries.
 
void ResolveUpdate (CollisionGeometries *const cnt_geoms, double timestep)
 Updates the contact resolution for a set of collision geometries.
 
- Public Member Functions inherited from netdem::CollisionSolverPW
 CollisionSolverPW ()
 
 CollisionSolverPW (Particle *const p, Wall *const w)
 
virtual bool Detect (ContactPW *const cnt)
 
virtual ~CollisionSolverPW ()
 

Public Attributes

double erosion_ratio_initial {0.01}
 < The initial erosion ratio used by the solver.
 
double erosion_ratio_increment {0.01}
 Whether to use erosion during collision detection.
 
bool use_erosion {false}
 Whether to print debug logs during collision detection.
 
bool enable_logging {false}
 
- Public Attributes inherited from netdem::CollisionSolverPW
Particleparticle {nullptr}
 
Wallwall {nullptr}
 

Protected Member Functions

bool GJK ()
 Implements the Gilbert-Johnson-Keerthi algorithm for collision detection.
 
std::tuple< double, Vec3d, Vec3dGJK_EROSION ()
 Implements the Gilbert-Johnson-Keerthi algorithm with erosion for collision detection.
 
std::tuple< double, Vec3d, Vec3dEPA ()
 Implements the Expanding Polytope Algorithm for collision resolution.
 
std::tuple< Vec3d, bool > GetContactPoint (Vec3d const &dir)
 Computes the contact point given the contact normal.
 
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 between the 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 after each GJK iteration based on the distance computed.
 
void UpdateSimplexLine (Simplex *const s, Vec3d *const dir, double *const min_dist, bool *const cnt_flag)
 Updates the simplex for the line case.
 
void UpdateSimplexTriangle (Simplex *const s, Vec3d *const dir, double *const min_dist, bool *const cnt_flag)
 Updates the simplex for the triangle case.
 
void UpdateSimplexTetrahedron (Simplex *const s, Vec3d *const dir, double *const min_dist, bool *const cnt_flag)
 Updates the simplex for the tetrahedron case.
 
std::tuple< Vec3d, double > GetFacetNormal (Vec3d const &a, Vec3d const &b, Vec3d const &c)
 Computes the normal and distance of a facet defined by three points.
 
void GetLooseEdges (VecXT< Vec2i > *const edges, Vec3i const &facet)
 Computes the edges of a polygon defined by a set of vertices.
 
void GetIntersections (VecXT< Vec3d > *const intersects, Vec3d const &dir_n, Vec3d const &l1_p, Vec3d const &l1_w, Vec3d const &l2_p, Vec3d const &l2_w)
 Computes the intersection points between two 3D line segments.
 
void GetIntersectionsAggresive (VecXT< Vec3d > *const intersects, Vec3d const &dir_n, Vec3d const &l1_p, Vec3d const &l1_w, Vec3d const &l2_p, Vec3d const &l2_w)
 Same as GetInter sections, but uses a more aggressive intersection algorithm.
 
void SortVertices (VecXT< Vec3d > *const pos_vec, Vec3d const &dir_n)
 Sorts the vertices of a polygon in counter-clockwise order relative to a given direction.
 
bool IsInsidePolygon (VecXT< Vec3d > const &pos_vec, Vec3d const &dir_n, Vec3d const &pos)
 Determines whether a point is inside a polygon defined by a set of vertices.
 
Vec3d GetPolygonCentroid (VecXT< Vec3d > const &pos_vec, Vec3d const &dir_n)
 Computes the centroid of a polygon defined by a set of vertices.
 
- Protected Member Functions inherited from netdem::CollisionSolverPW
void InitBasicGeoms (CollisionGeometries *const cnt_geoms, double timestep)
 
void UpdateBasicGeoms (CollisionGeometries *const cnt_geoms, double timestep, Vec3d const &dir_n_old)
 

Protected Attributes

Shapeshape_1 {nullptr}
 < The shapes involved in the collision.
 
Shapeshape_2 {nullptr}
 The radii of the bounding spheres around the shapes.
 
double bound_sphere_radius_1
 
double bound_sphere_radius_2
 The position difference between the particles.
 
Vec3d dpos_12
 
Vec3d dpos_12_ref
 The orientation difference between the particles.
 
Vec4d dquat_12
 
Vec4d dquat_12_conj
 The simplex computed during GJK collision detection.
 
Simplex simplex_after_gjk
 

Detailed Description

GJK solver for convex geometries.

This class is a collision solver that uses the Gilbert-Johnson-Keerthi (GJK) algorithm to detect collisions between particles and walls with convex geometries. It extends the CollisionSolverPW class.

Examples
1_test_triaxial_comp.cpp, 21_test_dataset_ellipsoid_plane.cpp, and 26_test_ann_vs_geom_ellipsoid_plane.cpp.

Constructor & Destructor Documentation

◆ SolverGJKPW() [1/2]

netdem::SolverGJKPW::SolverGJKPW ( )

Default constructor for the SolverGJKPW class.

◆ SolverGJKPW() [2/2]

netdem::SolverGJKPW::SolverGJKPW ( Particle *const p,
Wall *const w )

Constructor for the SolverGJKPW class.

Parameters
pThe particle involved in the collision.
wThe wall involved in the collision.

Member Function Documentation

◆ Clone()

CollisionSolverPW * netdem::SolverGJKPW::Clone ( ) const
overridevirtual

Creates a copy of the current collision solver.

Returns
A pointer to the cloned CollisionSolverPW object.

Implements netdem::CollisionSolverPW.

◆ Detect()

bool netdem::SolverGJKPW::Detect ( )
overridevirtual

Detects collisions between a particle and a wall.

Returns
True if a collision is detected, false otherwise.

Implements netdem::CollisionSolverPW.

Examples
21_test_dataset_ellipsoid_plane.cpp, and 26_test_ann_vs_geom_ellipsoid_plane.cpp.

◆ EPA()

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

Implements the Expanding Polytope Algorithm for collision resolution.

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

◆ GetContactPoint()

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

Computes the contact point given the contact normal.

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

◆ GetContactPoint_PlaneCase()

tuple< Vec3d, bool > netdem::SolverGJKPW::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()

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

Computes the normal and distance of a facet defined by three points.

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

◆ GetIntersections()

void netdem::SolverGJKPW::GetIntersections ( VecXT< Vec3d > *const intersects,
Vec3d const & dir_n,
Vec3d const & l1_p,
Vec3d const & l1_w,
Vec3d const & l2_p,
Vec3d const & l2_w )
protected

Computes the intersection points between two 3D line segments.

Parameters
intersectsThe output vector of intersection points.
dir_nThe direction of the line segments.
l1_pThe starting point of the first line segment.
l1_wThe ending point of the first line segment.
l2_pThe starting point of the second line segment.
l2_wThe ending point of the second line segment.

◆ GetIntersectionsAggresive()

void netdem::SolverGJKPW::GetIntersectionsAggresive ( VecXT< Vec3d > *const intersects,
Vec3d const & dir_n,
Vec3d const & l1_p,
Vec3d const & l1_w,
Vec3d const & l2_p,
Vec3d const & l2_w )
protected

Same as GetInter sections, but uses a more aggressive intersection algorithm.

Parameters
intersectsThe output vector of intersection points.
dir_nThe direction of the line segments.
l1_pThe starting point of the first line segment.
l1_wThe ending point of the first line segment.
l2_pThe starting point of the second line segment.
l2_wThe ending point of the second line segment.

◆ GetLooseEdges()

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

Computes the edges of a polygon defined by a set of vertices.

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

◆ GetPolygonCentroid()

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

Computes the centroid of a polygon defined by a set of vertices.

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

◆ GJK()

bool netdem::SolverGJKPW::GJK ( )
protected

Implements the Gilbert-Johnson-Keerthi algorithm for collision detection.

Returns
True if a collision is detected, false otherwise.

◆ GJK_EROSION()

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

Implements the Gilbert-Johnson-Keerthi algorithm with erosion for collision detection.

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

◆ Init()

void netdem::SolverGJKPW::Init ( Particle *const p,
Wall *const w )
overridevirtual

Initializes the collision solver with a particle and a wall.

Parameters
pThe particle involved in the collision.
wThe wall involved in the collision.

Reimplemented from netdem::CollisionSolverPW.

Examples
21_test_dataset_ellipsoid_plane.cpp, and 26_test_ann_vs_geom_ellipsoid_plane.cpp.

◆ IsInsidePolygon()

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

Determines whether a point is inside a polygon defined by a set of vertices.

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

◆ MinkowskiDiff()

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

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

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

◆ ResolveInit() [1/2]

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

Initializes the contact resolution for a set of collision geometries.

Parameters
cnt_geomsThe collision geometries to resolve.
timestepThe simulation time step size.

◆ ResolveInit() [2/2]

void netdem::SolverGJKPW::ResolveInit ( ContactPW *const cnt,
double timestep )
overridevirtual

Initializes the contact resolution for a contact point.

Parameters
cntThe contact point to resolve.
timestepThe simulation time step size.

Implements netdem::CollisionSolverPW.

Examples
21_test_dataset_ellipsoid_plane.cpp, and 26_test_ann_vs_geom_ellipsoid_plane.cpp.

◆ ResolveUpdate() [1/2]

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

Updates the contact resolution for a set of collision geometries.

Parameters
cnt_geomsThe collision geometries to resolve.
timestepThe simulation time step size.

◆ ResolveUpdate() [2/2]

void netdem::SolverGJKPW::ResolveUpdate ( ContactPW *const cnt,
double timestep )
overridevirtual

Updates the contact resolution for a contact point.

Parameters
cntThe contact point to resolve.
timestepThe simulation time step size.

Implements netdem::CollisionSolverPW.

◆ SortVertices()

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

Sorts the vertices of a polygon in counter-clockwise order relative to a given direction.

Parameters
pos_vecThe input and output vector of vertices.
dir_nThe direction to sort the vertices relative to.

◆ UpdateSimplex()

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

Updates the simplex after each GJK iteration based on the distance computed.

Parameters
sThe current simplex.
dirThe search direction for the next iteration.
min_distThe minimum distance between the shapes.
cnt_flagA flag indicating whether a contact has been detected.

◆ UpdateSimplexLine()

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

Updates the simplex for the line case.

Parameters
sThe current simplex.
dirThe search direction for the next iteration.
min_distThe minimum distance between the shapes.
cnt_flagA flag indicating whether a contact has been detected.

◆ UpdateSimplexTetrahedron()

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

Updates the simplex for the tetrahedron case.

Parameters
sThe current simplex.
dirThe search direction for the next iteration.
min_distThe minimum distance between the shapes.
cnt_flagA flag indicating whether a contact has been detected.

◆ UpdateSimplexTriangle()

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

Updates the simplex for the triangle case.

Parameters
sThe current simplex.
dirThe search direction for the next iteration.
min_distThe minimum distance between the shapes.
cnt_flagA flag indicating whether a contact has been detected.

Member Data Documentation

◆ bound_sphere_radius_1

double netdem::SolverGJKPW::bound_sphere_radius_1
protected

◆ bound_sphere_radius_2

double netdem::SolverGJKPW::bound_sphere_radius_2
protected

The position difference between the particles.

◆ dpos_12

Vec3d netdem::SolverGJKPW::dpos_12
protected

◆ dpos_12_ref

Vec3d netdem::SolverGJKPW::dpos_12_ref
protected

The orientation difference between the particles.

◆ dquat_12

Vec4d netdem::SolverGJKPW::dquat_12
protected

◆ dquat_12_conj

Vec4d netdem::SolverGJKPW::dquat_12_conj
protected

The simplex computed during GJK collision detection.

◆ enable_logging

bool netdem::SolverGJKPW::enable_logging {false}

◆ erosion_ratio_increment

double netdem::SolverGJKPW::erosion_ratio_increment {0.01}

Whether to use erosion during collision detection.

◆ erosion_ratio_initial

double netdem::SolverGJKPW::erosion_ratio_initial {0.01}

< The initial erosion ratio used by the solver.

The incremental change in erosion ratio.

◆ shape_1

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

< The shapes involved in the collision.

◆ shape_2

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

The radii of the bounding spheres around the shapes.

◆ simplex_after_gjk

Simplex netdem::SolverGJKPW::simplex_after_gjk
protected

◆ use_erosion

bool netdem::SolverGJKPW::use_erosion {false}

Whether to print debug logs during collision detection.

Examples
1_test_triaxial_comp.cpp.

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