PolyFEM
Loading...
Searching...
No Matches
QuadraticBSpline.cpp
Go to the documentation of this file.
2
3#include <cmath>
4
5namespace polyfem
6{
7 namespace basis
8 {
9 void QuadraticBSpline::init(const std::array<double, 4> &knots)
10 {
11 knots_ = knots;
12 }
13
14 void QuadraticBSpline::interpolate(const Eigen::MatrixXd &ts, Eigen::MatrixXd &result) const
15 {
16 result.resize(ts.size(), 1);
17
18 for (long i = 0; i < ts.size(); ++i)
19 result(i) = interpolate(ts(i));
20 }
21
22 double QuadraticBSpline::interpolate(const double t) const
23 {
24 if (t >= knots_[0] && t < knots_[1])
25 return (t - knots_[0]) * (t - knots_[0]) / (knots_[2] - knots_[0]) / (knots_[1] - knots_[0]);
26
27 if (t >= knots_[1] && t < knots_[2])
28 return (t - knots_[0]) / (knots_[2] - knots_[0]) * (knots_[2] - t) / (knots_[2] - knots_[1]) + (knots_[3] - t) / (knots_[3] - knots_[1]) * (t - knots_[1]) / (knots_[2] - knots_[1]);
29
30 if (t >= knots_[2] && t <= knots_[3])
31 {
32 if (fabs(knots_[3] - knots_[2]) < 1e-12 && fabs(knots_[3] - knots_[1]) < 1e-12)
33 return knots_[3];
34 if (fabs(knots_[3] - knots_[2]) < 1e-12)
35 return 0;
36
37 return (knots_[3] - t) * (knots_[3] - t) / (knots_[3] - knots_[1]) / (knots_[3] - knots_[2]);
38 }
39
40 return 0;
41 }
42
43 void QuadraticBSpline::derivative(const Eigen::MatrixXd &ts, Eigen::MatrixXd &result) const
44 {
45 result.resize(ts.size(), 1);
46
47 for (long i = 0; i < ts.size(); ++i)
48 result(i) = derivative(ts(i));
49 }
50
51 double QuadraticBSpline::derivative(const double t) const
52 {
53 if (t >= knots_[0] && t < knots_[1])
54 return 2 / (knots_[2] - knots_[0]) * (t - knots_[0]) / (knots_[1] - knots_[0]);
55
56 if (t >= knots_[1] && t < knots_[2])
57 return ((-2 * t + 2 * knots_[0]) * knots_[1] + (2 * t - 2 * knots_[3]) * knots_[2] - 2 * t * (knots_[0] - knots_[3])) / (-knots_[2] + knots_[0]) / (-knots_[2] + knots_[1]) / (-knots_[3] + knots_[1]);
58
59 if (t >= knots_[2] && t <= knots_[3])
60 {
61 if (fabs(knots_[3] - knots_[2]) < 1e-12 && fabs(knots_[3] - knots_[1]) < 1e-12)
62 return 2 * knots_[3];
63 if (fabs(knots_[3] - knots_[2]) < 1e-12)
64 return -2 * knots_[3];
65
66 return (2 * t - 2 * knots_[3]) / (-knots_[3] + knots_[1]) / (-knots_[3] + knots_[2]);
67 }
68
69 return 0;
70 }
71 } // namespace basis
72} // namespace polyfem
void init(const std::array< double, 4 > &knots)
void interpolate(const Eigen::MatrixXd &ts, Eigen::MatrixXd &result) const
void derivative(const Eigen::MatrixXd &ts, Eigen::MatrixXd &result) const