214 std::set<std::pair<double,double> >
intersectWith(
const Eigen::Matrix<double,2,otherPolyDegree+1>& otherCoeffs)
const
321 enum {eigenSize=polyDegree*otherPolyDegree};
322 typedef Eigen::Matrix< double, eigenSize,eigenSize> EigenSizeMatrixType;
325 std::set<std::pair<double,double> > intersectionParameters;
328 const MatrixPolyDeg Mn(otherCoeffs(0,otherPolyDegree)*
Mx+otherCoeffs(1,otherPolyDegree)*
My);
329 const Eigen::JacobiSVD<MatrixPolyDeg> jsvd(Mn, Eigen::ComputeFullU | Eigen::ComputeFullV);
330 const double condNumber(jsvd.singularValues().maxCoeff()/jsvd.singularValues().minCoeff());
335 if (condNumber<1.0/FLT_EPSILON)
338 EigenSizeMatrixType C(Eigen::Matrix<double, eigenSize,eigenSize>::Zero());
339 if (otherPolyDegree>1)
341 C.template block<polyDegree*(otherPolyDegree-1),polyDegree*(otherPolyDegree-1)>(0,polyDegree).setIdentity();
343 C.template block<polyDegree,polyDegree>(polyDegree*(otherPolyDegree-1),0*polyDegree)= -jsvd.solve(otherCoeffs(0,0)*
Mx+otherCoeffs(1,0)*
My+
Mc);
344 for (
int p=1;
p<otherPolyDegree;++
p)
346 C.template block<polyDegree,polyDegree>(polyDegree*(otherPolyDegree-1),
p*polyDegree)= -jsvd.solve(otherCoeffs(0,
p)*
Mx+otherCoeffs(1,
p)*
My);
352 const Eigen::EigenSolver<EigenSizeMatrixType> es(C);
358#ifdef _MODEL_BENCH_SPLINEINTERSECTION_
360 EigenSizeMatrixType
A(EigenSizeMatrixType::Identity());
361 A.template block<polyDegree,polyDegree>(0,0)=-(otherCoeffs(0,0)*
Mx+otherCoeffs(1,0)*
My+
Mc);
363 EigenSizeMatrixType
B(EigenSizeMatrixType::Zero());
364 if (otherPolyDegree>1)
366 B.template block<polyDegree*(otherPolyDegree-1),polyDegree*(otherPolyDegree-1)>(polyDegree,0).setIdentity();
368 for (
int p=0;
p<otherPolyDegree;++
p)
370 B.template block<polyDegree,polyDegree>(0,
p*polyDegree)=otherCoeffs(0,
p+1)*
Mx+otherCoeffs(1,
p+1)*
My;
373 Eigen::GeneralizedEigenSolver<EigenSizeMatrixType> ges(
A,
B);
376 std::cout<<
"geav"<<ges.eigenvalues()<<std::endl<<std::endl;
378 std::ofstream ABfile;
379 ABfile.open (
"AB.txt");
381 ABfile<< std::scientific<<std::setprecision(15)<<
A<<std::endl<<
B<<std::endl;
384 std::ofstream coeffFile;
385 coeffFile.open (
"coeffFile.txt");
387 coeffFile<< std::scientific<<std::setprecision(15)<<
coeffs<<std::endl<<otherCoeffs<<std::endl;
415 for(
int i=0;
i<eigenSize;++
i)
417 const std::complex<double> s(es.eigenvalues()(
i));
418 const std::complex<double>
t( es.eigenvectors().col(
i)(1)/es.eigenvectors().col(
i)(0) );
419 std::cout<<
t<<
", "<<s<<std::endl;
423 if (es.info() == Eigen::Success)
429 std::map<double,const int> sMap;
430 for (
int i=0;
i<eigenSize; ++
i)
432 if (std::fabs(es.eigenvalues()(
i).imag())<
compTol)
439 sMap.emplace(es.eigenvalues()(
i).real(),
i);
462 for(std::map<double,const int>::const_iterator last=sMap.begin();last!=sMap.end();)
464 std::map<double,const int>::const_iterator
first = last;
465 std::map<double,const int>::const_iterator next = last;
467 last = sMap.upper_bound(
first->first+FLT_EPSILON);
474 sMap.erase(
first,last);
479 for (
auto pair : sMap)
481 const double& s=pair.first;
482 const int&
i=pair.second;
483 const double t( (es.eigenvectors().col(
i)(1)/es.eigenvectors().col(
i)(0)).real() );
487 Eigen::Matrix<double,2,1> Pt(
coeffs.col(0));
488 for(
int k=1;
k<polyDegree+1;++
k)
492 Eigen::Matrix<double,2,1> Ps(otherCoeffs.col(0));
493 for(
int k=1;
k<otherPolyDegree+1;++
k)
495 Ps+=otherCoeffs.col(
k)*std::pow(s,
k);
499 intersectionParameters.insert(std::make_pair(
t,s));
510 return intersectionParameters;