Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
Plane.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_Plane_CPP_
9#define model_Plane_CPP_
10
11#include <cfloat>
12#include <tuple>
13#include <Eigen/Dense>
14#include <Plane.h>
15
16namespace model
17{
18
19 template <int dim>
21 /* init */ P(p)
22 /* init */,unitNormal(n.normalized())
23 /* init */,L2G(LocalToGlobal<dim>::getL2G(unitNormal))
24 {
25 if(n.norm()<FLT_EPSILON)
26 {
27 std::cout<<"Plane: n="<<n.transpose()<<std::endl;
28 throw std::runtime_error("Plane must have non-zero normal");
29 }
30 }
31
32 template <int dim>
33 bool Plane<dim>::contains(const VectorDim& P0) const
34 {
35 return fabs((P0-P).dot(unitNormal))<FLT_EPSILON;
36 }
37
38 template <int dim>
39 bool Plane<dim>::isAbove(const VectorDim& P0) const
40 {
41 return (P0-P).dot(unitNormal)<0.0;
42 }
43
44 template <int dim>
45 bool Plane<dim>::isBelow(const VectorDim& P0) const
46 {
47 return (P0-P).dot(unitNormal)>0.0;
48 }
49
50 template <int dim>
52 {
53 return P0-(P0-P).dot(unitNormal)*unitNormal;
54 }
55
56 template <int dim>
57 double Plane<dim>::distanceTo(const VectorDim& P0) const
58 {
59 return fabs((P0-P).dot(unitNormal));
60 }
61
62 template <int dim>
64 {
65 return (P0-P).dot(unitNormal);
66 }
68 template <int dim>
70 {
71 const VectorDim pointLocal(L2G.transpose()*(point-P));
72 if(fabs(pointLocal(dim-1))>FLT_EPSILON)
73 {
74 std::cout<<"point="<<point.transpose()<<std::endl;
75 std::cout<<"P="<<P.transpose()<<std::endl;
76 std::cout<<"L2G=\n"<<L2G<<std::endl;
77 std::cout<<"pointLocal="<<pointLocal.transpose()<<std::endl;
78 throw std::runtime_error("Local point has non-zero z-coordinate");
79 }
80 return pointLocal.template segment<dim-1>(0);
81 }
82
83 template <int dim>
85 {// terurns the position on the plane in global goordinates
86 return L2G.template block<dim,dim-1>(0,0)*point+P;
87 }
88
89 template <int dim>
91 {
92 const VectorDim dirLocal(L2G.transpose()*dir);
93 if(fabs(dirLocal(dim-1))>FLT_EPSILON)
94 {
95 std::cout<<"dir="<<dir.transpose()<<std::endl;
96 std::cout<<"L2G=\n"<<L2G<<std::endl;
97 std::cout<<"dirLocal="<<dirLocal.transpose()<<std::endl;
98 throw std::runtime_error("Local point has non-zero z-coordinate");
99 }
100 return dirLocal.template segment<dim-1>(0);
101 }
102
103 template <int dim>
105 {// returns the direction on the plane in global goordinates
106 return L2G.template block<dim,dim-1>(0,0)*dir;
107 }
108
109 template <int dim>
114
116 {
117 return MatrixDim::Identity();
118 }
119
121 {
122 const double yNorm(y.norm());
123 if(yNorm<FLT_EPSILON)
124 {
125 throw std::runtime_error("LocalToGlobal<2>::getL2G input vector has zero norm.");
126 }
127 y/=yNorm;
128
129 const VectorDim x((VectorDim()<<y(1),-y(0)).finished());
130 MatrixDim temp(MatrixDim::Identity());
131 temp.col(1)=y;
132 temp.col(0)=x;
133 return temp;
134 }
135
137 {
138 const double zNorm(z.norm());
139 if(zNorm<FLT_EPSILON)
140 {
141 throw std::runtime_error("LocalToGlobal<3>::getL2G input vector has zero norm.");
142 }
143 assert(zNorm>FLT_EPSILON);
144 z/=zNorm;
145
146 VectorDim x(VectorDim::UnitX().cross(z));
147 double xNorm(x.norm());
148 if(xNorm>FLT_EPSILON)
149 {
150 x=x/xNorm;
151 }
152 else
153 {
154 x=VectorDim::UnitY().cross(z);
155 xNorm=x.norm();
156 if(xNorm>FLT_EPSILON)
157 {
158 x=x/xNorm;
159 }
160 else
161 {
162 x=VectorDim::UnitZ().cross(z);
163 xNorm=x.norm();
164 if(xNorm>FLT_EPSILON)
165 {
166 x=x/xNorm;
167 }
168 else
169 {
170 throw std::runtime_error("CANNOT FIND VECTOR ORTHOGONAL TO z");
171 }
172 }
173 }
174
175 assert(std::fabs(x.norm()-1.0)<FLT_EPSILON);
176 assert(std::fabs(z.norm()-1.0)<FLT_EPSILON);
177 assert(fabs(x.dot(z)<FLT_EPSILON));
178 MatrixDim temp(Eigen::Matrix3d::Identity());
179 temp.col(2)=z;
180 temp.col(0)=x;
181 temp.col(1)=temp.col(2).cross(temp.col(0));
182 return temp;
183 }
184
185 template struct Plane<1>;
186 template struct Plane<2>;
187 template struct Plane<3>;
188
189}
190#endif
id z()
x
Definition int_R.m:12
Eigen::Matrix< double, 3, 1 > VectorDim
Definition pyMoDELib.cxx:66
Eigen::Matrix< double, dim, 1 > VectorDim
Definition Plane.h:30
Eigen::Matrix< double, dim, 1 > VectorDim
Definition Plane.h:39
Eigen::Matrix< double, dim, dim > MatrixDim
Definition Plane.h:40
Eigen::Matrix< double, dim, 1 > VectorDim
Definition Plane.h:48
Eigen::Matrix< double, dim, dim > MatrixDim
Definition Plane.h:49
bool isBelow(const VectorDim &P0) const
Definition Plane.cpp:45
bool contains(const VectorDim &P0) const
Definition Plane.cpp:33
Plane(const VectorDim &p, const VectorDim &n)
Definition Plane.cpp:20
bool isAbove(const VectorDim &P0) const
Definition Plane.cpp:39
VectorDim snapToPlane(const VectorDim &P0) const
Definition Plane.cpp:51
const MatrixDim L2G
Definition Plane.h:62
Eigen::Matrix< double, dim-1, 1 > VectorLowerDim
Definition Plane.h:57
double signedDistanceTo(const VectorDim &P0) const
Definition Plane.cpp:63
Eigen::Matrix< double, dim, 1 > VectorDim
Definition Plane.h:56
Eigen::Matrix< double, dim, dim > MatrixDim
Definition Plane.h:58
double distanceTo(const VectorDim &P0) const
Definition Plane.cpp:57
VectorLowerDim localDirection(const VectorDim &dir) const
Definition Plane.cpp:90
VectorLowerDim localPosition(const VectorDim &point) const
Definition Plane.cpp:69
VectorDim globalPosition(const VectorLowerDim &point) const
Definition Plane.cpp:84
const VectorDim P
Definition Plane.h:60
VectorDim globalDirection(const VectorLowerDim &dir) const
Definition Plane.cpp:104
const VectorDim unitNormal
Definition Plane.h:61
static MatrixDim getL2G(const VectorDim &z)
Definition Plane.cpp:110
vertex p[3]
vertex temp