Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
CatmullRomSplineSegment.cpp
Go to the documentation of this file.
1/* This file is part of MoDELib, distributed under GNU GPL v2. */
3#include <math.h>
4
5namespace model
6{
7
8 template <int dim>
9 auto CatmullRomSplineSegment<dim>::get_M(const VectorDim &P0, const VectorDim &P1, const VectorDim &P2,
10 const VectorDim &P3) -> Eigen::Matrix<double, 4, 4>
11 {
12 Eigen::Matrix<double, 4, 4> temp;
13 const double g0(std::pow((P1 - P0).norm(), 0.5));
14 const double g1(std::pow((P2 - P1).norm(), 0.5));
15 const double g2(std::pow((P3 - P2).norm(), 0.5));
16
17 temp << 0, 1.0, 0, 0, -std::pow(g1, 2) / g0 / (g0 + g1), g1 / g0 - 1.0, g0 / (g1 + g0), 0,
18 2.0 * std::pow(g1, 2) / g0 / (g0 + g1), -2.0 * g1 / g0 - g1 / (g1 + g2), 2.0 * g1 / (g1 + g0) + g1 / g2,
19 -std::pow(g1, 2) / g2 / (g1 + g2), -std::pow(g1, 2) / g0 / (g0 + g1), g1 / g0 + g1 / (g1 + g2),
20 -g1 / (g0 + g1) - g1 / g2, std::pow(g1, 2) / g2 / (g1 + g2);
21
22 return temp.transpose();
23 }
24
25 template <int dim>
26 CatmullRomSplineSegment<dim>::CatmullRomSplineSegment(const VectorDim &P0, const VectorDim &P1, const VectorDim &P2,
27 const VectorDim &P3)
28 : P((PointMatrixType() << P0, P1, P2, P3).finished()), M(get_M(P0, P1, P2, P3)), PM(P * M)
29 {
30 // std::cout<<P<<std::endl;
31 }
32
33 template <int dim> auto CatmullRomSplineSegment<dim>::get_r(const double &u) const -> VectorDim
34 {
35 return PM * (Eigen::Matrix<double, 4, 1>() << 1.0, u, std::pow(u, 2), std::pow(u, 3)).finished();
36 }
37
38 template <int dim> auto CatmullRomSplineSegment<dim>::get_ru(const double &u) const -> VectorDim
39 {
40 return PM * (Eigen::Matrix<double, 4, 1>() << 0.0, 1.0, 2.0 * u, 3.0 * std::pow(u, 2)).finished();
41 }
42
43 template <int dim> auto CatmullRomSplineSegment<dim>::get_ruu(const double &u) const -> VectorDim
44 {
45 return PM * (Eigen::Matrix<double, 4, 1>() << 0.0, 0.0, 2.0, 6.0 * u).finished();
46 }
47 template class CatmullRomSplineSegment<3>;
48
49} // namespace model
VectorDim get_ru(const double &u) const
CatmullRomSplineSegment(const VectorDim &P0, const VectorDim &P1, const VectorDim &P2, const VectorDim &P3)
VectorDim get_r(const double &u) const
VectorDim get_ruu(const double &u) const
REAL u[4]
vertex temp