GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
EPA.hpp
Go to the documentation of this file.
1 // This file is part of GranOO, a workbench for DEM simulation.
2 //
3 // Author(s) : - Damien Andre IRCER/UNILIM, Limoges France
4 // <damien.andre@unilim.fr>
5 // - Jean-luc Charles Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
6 // <jean-luc.charles@ensam.eu>
7 // - Jeremie Girardot Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
8 // <jeremie.girardot@ensam.eu>
9 // - Cedric Hubert LAMIH/UPHF, Valenciennes France
10 // <cedric.hubert@uphf.fr>
11 // - Ivan Iordanoff Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
12 // <ivan.iordanoff@ensam.eu>
13 //
14 // Copyright (C) 2008-2019 D. Andre, JL. Charles, J. Girardot, C. Hubert, I. Iordanoff
15 //
16 // This program is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 // This program is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License
27 // along with this program. If not, see <http://www.gnu.org/licenses/>.
28 
29 
30 
31 #ifndef _LibCollision_EPA_H
32 #define _LibCollision_EPA_H
33 
34 #include <array>
35 #include <list>
36 
37 #include "GranOO3/Geom/Vector.hpp"
40 
41 namespace GranOO3
42 {
43  namespace Collision
44  {
45  namespace EPA
46  {
47 
48 
49  // Triangle struct that compose the polyhedron
50  struct Triangle
51  {
52 
54  // public data
55  std::array<GJK::SupportPoint, 3> point;
57  };
58 
59 
60 
61 
62  // Edge struct that compose the polyhedron
63  struct Edge
64  {
65  Edge(const GJK::SupportPoint &a,const GJK::SupportPoint &b);
66  // public data
67  std::array<GJK::SupportPoint, 2> point;
68 
69  };
70 
71 
72 
73 
74  // Polyhedron struct needed for the EPA algorithm
75  struct Polyhedron
76  {
77  void AddEdge(const GJK::SupportPoint& a, const GJK::SupportPoint& b);
78  // public data
79 
80  std::list<Triangle> triangle;
81  std::list<Edge> edge;
82  };
83 
84 
85  // Some inlined definitions
86  inline
88  : point({{a,b,c}}), normal(((b.v-a.v)^(c.v-a.v)).unit()) {
89  }
90 
91  inline
93  : point({{a,b}}) {
94  }
95 
96  }// End of EPA namespace
97 
98 
99 
100  // The EPA algorithm : it allows to compute the contact information (depth, normal and point),
101  // this algo work together with the GJK
103  {
104  public:
105  static unsigned int max_iter;
106  static double exit_treshold;
107 
108  public:
110  ~EPA_Algorithm();
111 
112  bool compute_data(Data&);
113  bool compute_data(const EPA::Triangle& triangle, double penetration, Data&);
114  void barycentric(const EPA::Triangle& triangle, const Geom::Vector &p,
115  double& u, double& v, double& w);
116 
117  public:
120  };
121 
122 
123 
124  }
125 }
126 
127 
128 #endif
Definition: EPA.hpp:103
GJK_Algorithm & gjk
Definition: EPA.hpp:118
static double exit_treshold
Definition: EPA.hpp:106
static unsigned int max_iter
Definition: EPA.hpp:105
~EPA_Algorithm()
Definition: EPA.cpp:76
void barycentric(const EPA::Triangle &triangle, const Geom::Vector &p, double &u, double &v, double &w)
Definition: EPA.cpp:187
bool compute_data(Data &)
Definition: EPA.cpp:81
EPA_Algorithm(GJK_Algorithm &)
Definition: EPA.cpp:67
EPA::Polyhedron polyhedron
Definition: EPA.hpp:119
Definition: GJK.hpp:162
Definition: Vector.hpp:75
Definition: Common.hpp:198
Definition: Data.hpp:43
Definition: EPA.hpp:64
std::array< GJK::SupportPoint, 2 > point
Definition: EPA.hpp:67
Edge(const GJK::SupportPoint &a, const GJK::SupportPoint &b)
Definition: EPA.hpp:92
std::list< Triangle > triangle
Definition: EPA.hpp:80
std::list< Edge > edge
Definition: EPA.hpp:81
void AddEdge(const GJK::SupportPoint &a, const GJK::SupportPoint &b)
Definition: EPA.cpp:49
Definition: EPA.hpp:51
Geom::Vector normal
Definition: EPA.hpp:56
Triangle(const GJK::SupportPoint &a, const GJK::SupportPoint &b, const GJK::SupportPoint &c)
Definition: EPA.hpp:87
std::array< GJK::SupportPoint, 3 > point
Definition: EPA.hpp:55