Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
PlanesIntersection.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_PlanesIntersection_cpp_
9#define model_PlanesIntersection_cpp_
10
11#include <iostream>
12#include <PlanesIntersection.h>
13
14//#include <Plane.h>
15
16namespace model
17{
18
19
20
21 template<int dim>
23 /* init */ NP(std::make_pair(N,P))
24 /* init */,svd(SVDsolverType().setThreshold(tol).compute(NP.first,Eigen::ComputeThinU | Eigen::ComputeThinV))
25 {// Ax=b
26 }
27
28 template<int dim>
29 std::pair<bool,typename PlanesIntersection<dim>::VectorDim> PlanesIntersection<dim>::snap(const VectorDim& x) const
30 {
39
40 Eigen::Matrix<double,Eigen::Dynamic,1> b(Eigen::Matrix<double,Eigen::Dynamic,1>::Zero(NP.first.cols(),1));
41 Eigen::Matrix<double,Eigen::Dynamic,1> b1(Eigen::Matrix<double,Eigen::Dynamic,1>::Zero(NP.first.cols(),1));
42 for(int k=0;k<NP.first.cols();++k)
43 {
44 b(k)=NP.first.col(k).dot(x-NP.second.col(k));
45 b1(k)=NP.first.col(k).dot(NP.second.col(k));
46 }
47
48 const int r(svd.rank());
49 const Eigen::MatrixXd Vr(svd.matrixV().block(0,0,NP.first.cols(),r));
50 const Eigen::VectorXd Sinv2(svd.singularValues().segment(0,r).array().pow(-2).matrix());
51 const Eigen::VectorXd lam(Vr*Sinv2.asDiagonal()*Vr.transpose()*b);
52 const VectorDim y(x-NP.first*lam);
53
54 const double b1norm2(b1.squaredNorm());
55 if(b1norm2>svd.threshold())
56 {
57 if((NP.first.transpose()*y-b1).squaredNorm()/b1norm2<svd.threshold())
58 {// y belongs to planes
59 return std::make_pair(true,y);
60 }
61 else
62 {
63 return std::make_pair(false,y);
64 }
65 }
66 else
67 {
68 if((NP.first.transpose()*y-b1).squaredNorm()<svd.threshold())
69 {// y belongs to planes
70 return std::make_pair(true,y);
71 }
72 else
73 {
74 return std::make_pair(false,y);
75 }
76 }
77 }
78
79template struct PlanesIntersection<1>;
80template struct PlanesIntersection<2>;
81template struct PlanesIntersection<3>;
82
83}
84#endif
b
Definition int_R.m:16
x
Definition int_R.m:12
Eigen::Matrix< double, dim, 1 > VectorDim
const std::pair< MatrixDimDynamic, MatrixDimDynamic > NP
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixDimDynamic
PlanesIntersection(const MatrixDimDynamic &N, const MatrixDimDynamic &P, const double &tol=FLT_EPSILON)
Eigen::JacobiSVD< MatrixDimDynamic > SVDsolverType
std::pair< bool, VectorDim > snap(const VectorDim &x) const
int k
vertex first