Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
src
Geometry
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
17
#include <
PlaneLineIntersection.h
>
18
19
namespace
model
20
{
21
/**********************************************************************/
22
template
<
int
dim>
23
typename
PlaneLineIntersection<dim>::SolutionType
PlaneLineIntersection<dim>::findIntersection
(
const
VectorDimD
& pP,
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
89
template
struct
PlaneLineIntersection<1>
;
90
template
struct
PlaneLineIntersection<2>
;
91
template
struct
PlaneLineIntersection<3>
;
92
93
}
/* namespace model */
94
#endif
PlaneLineIntersection.h
model
Definition
DD_converter.dox:2
model::PlaneLineIntersection
Definition
PlaneLineIntersection.h:21
model::PlaneLineIntersection::PlaneLineIntersection
PlaneLineIntersection(const VectorDimD &pP, const VectorDimD &N, const VectorDimD &pL, const VectorDimD &D)
Definition
PlaneLineIntersection.cpp:77
model::PlaneLineIntersection::P
const VectorDimD & P
Definition
PlaneLineIntersection.h:40
model::PlaneLineIntersection::type
const IntersectionType & type
Definition
PlaneLineIntersection.h:39
model::PlaneLineIntersection::SolutionType
std::tuple< IntersectionType, VectorDimD, VectorDimD > SolutionType
Definition
PlaneLineIntersection.h:27
model::PlaneLineIntersection::VectorDimD
Eigen::Matrix< double, dim, 1 > VectorDimD
Definition
PlaneLineIntersection.h:25
model::PlaneLineIntersection::findIntersection
static SolutionType findIntersection(const VectorDimD &pP, const VectorDimD &N, const VectorDimD &pL, const VectorDimD &D)
Definition
PlaneLineIntersection.cpp:23
model::PlaneLineIntersection::COINCIDENT
@ COINCIDENT
Definition
PlaneLineIntersection.h:23
model::PlaneLineIntersection::PARALLEL
@ PARALLEL
Definition
PlaneLineIntersection.h:23
model::PlaneLineIntersection::INCIDENT
@ INCIDENT
Definition
PlaneLineIntersection.h:23
model::PlaneLineIntersection::sol
const SolutionType sol
Definition
PlaneLineIntersection.h:28
model::PlaneLineIntersection::d
const VectorDimD & d
Definition
PlaneLineIntersection.h:41
den
den
Definition
testStraightExp.m:22
N
N
Definition
testStraightExp.m:9
num
num
Definition
testStraightExp.m:21
D
REAL D[16]
Definition
triangle.cpp:5165
u
REAL u[4]
Definition
triangle.cpp:5168
Generated by
1.15.0