Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
PlaneLineIntersection.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_PlaneLineIntersection_CPP_
9#define model_PlaneLineIntersection_CPP_
10
11#include <cfloat>
12#include <tuple>
13#include <map>
14#include <Eigen/Dense>
15#include <Eigen/Cholesky>
16
18
19namespace model
20{
21 /**********************************************************************/
22 template <int dim>
24 const VectorDimD& N,
25 const VectorDimD& pL,
26 const VectorDimD& D)
27 {
28
29 const double normN(N.norm());
30 assert(normN>FLT_EPSILON && "PLANE MUST HAVE NON-ZERO NORMAL");
31 const VectorDimD n(N/normN); // unit plane normal
32
33 const double normD(D.norm());
34 if(normD<FLT_EPSILON)
35 {// line is degenerate (a point)
36 if(fabs((pL-pP).dot(n))<FLT_EPSILON)
37 {// degenerate incident
38 return std::make_tuple(INCIDENT,pL,VectorDimD::Zero());
39 }
40 else
41 {// degenerate parallel (non-intersection)
42 return std::make_tuple(PARALLEL,pL-(pL-pP).dot(n)*n,VectorDimD::Zero());
43 }
44 }
45 else
46 {
47 const VectorDimD d(D/normD); // unit line direction
48 const double den(d.dot(n));
49 const double num((pP-pL).dot(n));
50
51 if(fabs(den)>FLT_EPSILON)
52 {// incident
53 const double u=num/den;
54 return std::make_tuple(INCIDENT,pL+u*d,VectorDimD::Zero());
55
56 }
57 else
58 {// parallel or conincident
59 if(fabs(num)<FLT_EPSILON)
60 {// coincident
61 return std::make_tuple(COINCIDENT,pL,d);
62
63 }
64 else
65 {// parallel
66 return std::make_tuple(PARALLEL,pL,d);
67 }
68 }
69
70 }
71
72 }
73
74
75 /**********************************************************************/
76 template <int dim>
77 PlaneLineIntersection<dim>::PlaneLineIntersection(const Eigen::Matrix<double,dim,1>& pP,
78 const Eigen::Matrix<double,dim,1>& N,
79 const Eigen::Matrix<double,dim,1>& pL,
80 const Eigen::Matrix<double,dim,1>& D) :
81 /* init */ sol(findIntersection(pP,N,pL,D)),
82 /* init */ type(std::get<0>(sol)),
83 /* init */ P(std::get<1>(sol)),
84 /* init */ d(std::get<2>(sol))
85 {
86
87 }
88
89template struct PlaneLineIntersection<1>;
90template struct PlaneLineIntersection<2>;
91 template struct PlaneLineIntersection<3>;
92
93} /* namespace model */
94#endif
PlaneLineIntersection(const VectorDimD &pP, const VectorDimD &N, const VectorDimD &pL, const VectorDimD &D)
const IntersectionType & type
std::tuple< IntersectionType, VectorDimD, VectorDimD > SolutionType
Eigen::Matrix< double, dim, 1 > VectorDimD
static SolutionType findIntersection(const VectorDimD &pP, const VectorDimD &N, const VectorDimD &pL, const VectorDimD &D)
REAL D[16]
REAL u[4]