Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
LineSimplexIntersection.cpp
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MoDELib is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_LineSimplexIntersection_CPP_
9#define model_LineSimplexIntersection_CPP_
10
11#include <cfloat>
12#include <tuple>
13#include <map>
14#include <Eigen/Dense>
15
18
19namespace model
20{
21
22 /**********************************************************************/
23 template <int dim>
24 std::map<float,typename LineSimplexIntersection<dim>::VectorDim> LineSimplexIntersection<dim>::lineTriangleIntersection(const VectorDim& X,const VectorDim& s,
25 const VectorDim& P1,const VectorDim& P2,const VectorDim& P3)
26 {
27
28 std::map<float,VectorDim> temp;
29
30 LineSegmentIntersection<dim> lineP1P2(X,s,P1,P2);
32 {
33 temp.emplace(lineP1P2.u1,lineP1P2.x1);
34 }
35
36 LineSegmentIntersection<dim> lineP2P3(X,s,P2,P3);
38 {
39 temp.emplace(lineP2P3.u1,lineP2P3.x1);
40 }
41
42 LineSegmentIntersection<dim> lineP3P1(X,s,P3,P1);
44 {
45 temp.emplace(lineP3P1.u1,lineP3P1.x1);
46 }
47 return temp;
48
49// int temp=0;
50//
51// const VectorDim v12(P2-P1);
52// const VectorDim v13(P3-P1);
53//
54// VectorDim n(v12.cross(v13)); // right-handed norm to triangle P1->P2->P3
55// const double nNorm(n.norm());
56// assert(nNorm>FLT_EPSILON && "n has zero norm");
57// n/=nNorm; // normalize
58// const double nDots(n.dot(s));
59//
60// if(std::fabs(nDots)>FLT_EPSILON) // s in not parallel to triangle
61// {
62// MatrixDim M(MatrixDim::Zero());
63// M.col(0)=v12;
64// M.col(1)=v13;
65// M.col(2)=-s;
66// const VectorDim a=M.inverse()*(X-P1);
67//
68// if( a(0)>=0.0 && a(0)<=1.0 // intersection with trignale exists
69// && a(1)>=0.0 && a(0)+a(1)<=1.0 // intersection with trignale exists
70// && a(2)>=0.0) // intersection along positive S-vector
71// {
72// if(nDots>=0.0)
73// {
74// temp=-1;
75// }
76// else
77// {
78// temp=+1;
79// }
80// }
81// }
82// // else // s is parallel to triangle
83// // {
84// // assert(0 && "IMPLEMENT INTERSECTION AT INFINITY");
85// //// if((P1-X).dot(n)>=0.0) // X is below the trianlge. Positive intersection at infinity
86// //// {
87// //// temp=-1;
88// //// }
89// //// else // X is above the trianlge. Negative intersection at infinity
90// //// {
91// //// temp=+1;
92// //// }
93// // }
94//
95// return temp;
96 }
97
98 template class LineSimplexIntersection<3>;
99
100}
101#endif
static std::map< float, VectorDim > lineTriangleIntersection(const VectorDim &X, const VectorDim &s, const VectorDim &P1, const VectorDim &P2, const VectorDim &P3)
vertex temp