NetDEM v1.0
Loading...
Searching...
No Matches
solver_gjk_pw.hpp
Go to the documentation of this file.
1#pragma once
2
5#include "gjk_simplex.hpp"
6#include "particle.hpp"
7#include "shape.hpp"
8#include "wall.hpp"
9
10namespace netdem {
11
21public:
24
27
29 bool use_erosion{false};
30
32 bool enable_logging{false};
33
38
44 SolverGJKPW(Particle *const p, Wall *const w);
45
50 CollisionSolverPW *Clone() const override;
51
57 void Init(Particle *const p, Wall *const w) override;
58
63 bool Detect() override;
64
70 void ResolveInit(ContactPW *const cnt, double timestep) override;
71
77 void ResolveUpdate(ContactPW *const cnt, double timestep) override;
78
85 void ResolveInit(CollisionGeometries *const cnt_geoms, double timestep);
86
92 void ResolveUpdate(CollisionGeometries *const cnt_geoms, double timestep);
93
94protected:
96 Shape *shape_1{nullptr}, *shape_2{nullptr};
97
100
103
106
109
115 bool GJK();
116
123 std::tuple<double, Vec3d, Vec3d> GJK_EROSION();
124
131 std::tuple<double, Vec3d, Vec3d> EPA();
132
139 std::tuple<Vec3d, bool> GetContactPoint(Vec3d const &dir);
140
150 std::tuple<Vec3d, bool>
151 GetContactPoint_PlaneCase(Vec3d const &dir, const VecXT<Vec3d> &pos_vec_1,
152 const VecXT<Vec3d> &pos_vec_2);
153
161 inline Vec3d MinkowskiDiff(Vec3d const &dir, double erosion_ratio = 0);
162
171 void UpdateSimplex(Simplex *const s, Vec3d *const dir, double *const min_dist,
172 bool *const cnt_flag);
173
181 void UpdateSimplexLine(Simplex *const s, Vec3d *const dir,
182 double *const min_dist, bool *const cnt_flag);
183
191 void UpdateSimplexTriangle(Simplex *const s, Vec3d *const dir,
192 double *const min_dist, bool *const cnt_flag);
193
201 void UpdateSimplexTetrahedron(Simplex *const s, Vec3d *const dir,
202 double *const min_dist, bool *const cnt_flag);
203
212 inline std::tuple<Vec3d, double>
213 GetFacetNormal(Vec3d const &a, Vec3d const &b, Vec3d const &c);
214
220 void GetLooseEdges(VecXT<Vec2i> *const edges, Vec3i const &facet);
221
231 void GetIntersections(VecXT<Vec3d> *const intersects, Vec3d const &dir_n,
232 Vec3d const &l1_p, Vec3d const &l1_w, Vec3d const &l2_p,
233 Vec3d const &l2_w);
234
245 void GetIntersectionsAggresive(VecXT<Vec3d> *const intersects,
246 Vec3d const &dir_n, Vec3d const &l1_p,
247 Vec3d const &l1_w, Vec3d const &l2_p,
248 Vec3d const &l2_w);
249
256 void SortVertices(VecXT<Vec3d> *const pos_vec, Vec3d const &dir_n);
257
266 bool IsInsidePolygon(VecXT<Vec3d> const &pos_vec, Vec3d const &dir_n,
267 Vec3d const &pos);
268
275 Vec3d GetPolygonCentroid(VecXT<Vec3d> const &pos_vec, Vec3d const &dir_n);
276};
277
278} // namespace netdem
A class representing the geometries associated with a collision.
Definition collision_geometries.hpp:15
An abstract class representing a collision solver for a particle and a wall.
Definition collision_solver_pw.hpp:20
A class representing a contact between a particle and a wall.
Definition contact_pw.hpp:22
Definition particle.hpp:26
This class represents different types of shapes and performs various calculations on them.
Definition shape.hpp:15
A simplex class for representing a convex hull in n-dimensional space.
Definition gjk_simplex.hpp:18
GJK solver for convex geometries.
Definition solver_gjk_pw.hpp:20
std::tuple< Vec3d, bool > GetContactPoint(Vec3d const &dir)
Computes the contact point given the contact normal.
Definition solver_gjk_pw.cpp:369
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.
Definition solver_gjk_pw.cpp:679
void UpdateSimplexLine(Simplex *const s, Vec3d *const dir, double *const min_dist, bool *const cnt_flag)
Updates the simplex for the line case.
Definition solver_gjk_pw.cpp:543
void ResolveUpdate(ContactPW *const cnt, double timestep) override
Updates the contact resolution for a contact point.
Definition solver_gjk_pw.cpp:68
bool Detect() override
Detects collisions between a particle and a wall.
Definition solver_gjk_pw.cpp:36
Shape * shape_1
< The shapes involved in the collision.
Definition solver_gjk_pw.hpp:96
double bound_sphere_radius_2
The position difference between the particles.
Definition solver_gjk_pw.hpp:99
bool enable_logging
Definition solver_gjk_pw.hpp:32
Simplex simplex_after_gjk
Definition solver_gjk_pw.hpp:108
void GetLooseEdges(VecXT< Vec2i > *const edges, Vec3i const &facet)
Computes the edges of a polygon defined by a set of vertices.
Definition solver_gjk_pw.cpp:709
double erosion_ratio_increment
Whether to use erosion during collision detection.
Definition solver_gjk_pw.hpp:26
Vec3d GetPolygonCentroid(VecXT< Vec3d > const &pos_vec, Vec3d const &dir_n)
Computes the centroid of a polygon defined by a set of vertices.
Definition solver_gjk_pw.cpp:893
std::tuple< double, Vec3d, Vec3d > GJK_EROSION()
Implements the Gilbert-Johnson-Keerthi algorithm with erosion for collision detection.
Definition solver_gjk_pw.cpp:165
double erosion_ratio_initial
< The initial erosion ratio used by the solver.
Definition solver_gjk_pw.hpp:23
bool use_erosion
Whether to print debug logs during collision detection.
Definition solver_gjk_pw.hpp:29
void Init(Particle *const p, Wall *const w) override
Initializes the collision solver with a particle and a wall.
Definition solver_gjk_pw.cpp:18
void UpdateSimplexTetrahedron(Simplex *const s, Vec3d *const dir, double *const min_dist, bool *const cnt_flag)
Updates the simplex for the tetrahedron case.
Definition solver_gjk_pw.cpp:617
CollisionSolverPW * Clone() const override
Creates a copy of the current collision solver.
Definition solver_gjk_pw.cpp:16
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.
Definition solver_gjk_pw.cpp:815
Shape * shape_2
The radii of the bounding spheres around the shapes.
Definition solver_gjk_pw.hpp:96
Vec3d dpos_12
Definition solver_gjk_pw.hpp:102
double bound_sphere_radius_1
Definition solver_gjk_pw.hpp:99
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.
Definition solver_gjk_pw.cpp:449
void UpdateSimplexTriangle(Simplex *const s, Vec3d *const dir, double *const min_dist, bool *const cnt_flag)
Updates the simplex for the triangle case.
Definition solver_gjk_pw.cpp:577
Vec4d dquat_12_conj
The simplex computed during GJK collision detection.
Definition solver_gjk_pw.hpp:105
Vec3d MinkowskiDiff(Vec3d const &dir, double erosion_ratio=0)
Computes the Minkowski difference between the two shapes along a given direction.
Definition solver_gjk_pw.cpp:518
void ResolveInit(ContactPW *const cnt, double timestep) override
Initializes the contact resolution for a contact point.
Definition solver_gjk_pw.cpp:60
Vec4d dquat_12
Definition solver_gjk_pw.hpp:105
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.
Definition solver_gjk_pw.cpp:863
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.
Definition solver_gjk_pw.cpp:733
std::tuple< double, Vec3d, Vec3d > EPA()
Implements the Expanding Polytope Algorithm for collision resolution.
Definition solver_gjk_pw.cpp:246
SolverGJKPW()
Default constructor for the SolverGJKPW class.
Definition solver_gjk_pw.cpp:12
Vec3d dpos_12_ref
The orientation difference between the particles.
Definition solver_gjk_pw.hpp:102
bool GJK()
Implements the Gilbert-Johnson-Keerthi algorithm for collision detection.
Definition solver_gjk_pw.cpp:116
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.
Definition solver_gjk_pw.cpp:778
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.
Definition solver_gjk_pw.cpp:526
A class representing a wall object in a physics simulation.
Definition wall.hpp:32
Definition bond_entry.hpp:7
std::vector< T > VecXT
Definition utils_macros.hpp:31
pos
Definition json_serilization.hpp:19
std::array< double, 3 > Vec3d
Definition utils_macros.hpp:18
std::array< int, 3 > Vec3i
Definition utils_macros.hpp:14
std::array< double, 4 > Vec4d
Definition utils_macros.hpp:19
dir_n
Definition json_serilization.hpp:19