Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
FiniteLineSegment.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_FiniteLineSegment_CPP_
9#define model_FiniteLineSegment_CPP_
10
11#include <cfloat>
12#include <tuple>
13#include <map>
14#include <Eigen/Dense>
15
17#include <FiniteLineSegment.h>
18
19namespace model
20{
21
22 /**********************************************************************/
23 template <int dim>
25 const VectorDim& p1) :
26 /* init */ P0(p0),
27 /* init */ P1(p1)
28 {
29
30 }
31
32 /**********************************************************************/
33 template <int dim>
35 {
43
44 const VectorDim chord(P1-P0);
45 const double chordNorm2(chord.squaredNorm());
46 if(chordNorm2>FLT_EPSILON)
47 {
48 const double u=(x-P0).dot(chord)/chordNorm2;
49 if(u<0.0)
50 {
51 return P0;
52 }
53 else if(u>1.0)
54 {
55 return P1;
56 }
57 else
58 {
59 return P0+u*chord;
60 }
61 }
62 else
63 {
64 return 0.5*(P0+P1);
65 }
66
67 }
68
69 /**********************************************************************/
70 template <int dim>
72 {
80
81 const VectorDim chord(P1-P0);
82 const double chordNorm2(chord.squaredNorm());
83 if(chordNorm2>FLT_EPSILON)
84 {
85 const double u=(x-P0).dot(chord)/chordNorm2;
86 return P0 + u * chord;
87 }
88 else
89 {
90 return 0.5*(P0+P1);
91 }
92
93 }
94
95 /**********************************************************************/
96 template <int dim>
98 const double& degeneracyValue) const
99 {
100 return SegmentSegmentDistance<dim>(P0,P1,other.P0,other.P1,degeneracyValue);
101 }
102
103
104 /**********************************************************************/
105 template <int dim>
107 {
108 return (x-snap(x)).norm();
109 }
110
111 /**********************************************************************/
112 template <int dim>
114 {
115 return distanceTo(x)<FLT_EPSILON;
116 }
117
118 /**********************************************************************/
119 template <int dim>
121 {
122 return (P1-P0).norm();
123 }
124
125 /**********************************************************************/
126 template <int dim>
128 {
129 return length()<FLT_EPSILON;
130 }
131
132 /**********************************************************************/
133 template <int dim>
135 {
136 return 0.5*(P0+P1);
137 }
138
139 template struct FiniteLineSegment<1>;
140 template struct FiniteLineSegment<2>;
141 template struct FiniteLineSegment<3>;
142}
143#endif
x
Definition int_R.m:12
VectorDim snap(const VectorDim &x) const
SegmentSegmentDistance< dim > distanceTo(const FiniteLineSegment< dim > &other, const double &degeneracyValue=0.0) const
bool contains(const VectorDim &x) const
Eigen::Matrix< double, dim, 1 > VectorDim
VectorDim snapToInfiniteLine(const VectorDim &x) const
FiniteLineSegment(const VectorDim &p0, const VectorDim &p1)
REAL u[4]
vertex p1