polynomial_blueprints.cpp
Go to the documentation of this file.
1
14 /*****************************************************************************
15 ** Includes
16 *****************************************************************************/
17
18 #include "../../include/ecl/geometry/polynomial.hpp"
19
20 /*****************************************************************************
21 ** Namespaces
22 *****************************************************************************/
23
24 namespace ecl {
25 namespace blueprints {
26
27 /*****************************************************************************
28 ** Using
29 *****************************************************************************/
30
34
35 /*****************************************************************************
36 ** Implementation [LinearInterpolation][LinearPointSlopeForm]
37 *****************************************************************************/
38
40  LinearFunction function;
41  apply(function);
42  return function;
43 }
44
45 void LinearInterpolation::apply(ecl::LinearFunction& function) const {
46  LinearFunction::Coefficients &coefficients = function.coefficients();
47  // First compute the polynomial on [0,xf-xi] (this is easier), then shift it.
48
49  // y = a_1 x + a_0
50  double a_1 = (y_final-y_initial)/(x_final-x_initial);
51  double a_0 = y_initial - a_1*x_initial;
52
53  coefficients << a_0, a_1;
54 }
55
57  LinearFunction function;
58  apply(function);
59  return function;
60 }
61
63  LinearFunction::Coefficients &coefficients = function.coefficients();
64  // First compute the polynomial on [0,xf-xi] (this is easier), then shift it.
65
66  // y = a_1 x + a_0
67  double a_1 = slope;
68  double a_0 = y_final - a_1*x_final;
69
70  coefficients << a_0, a_1;
71 }
72
73
74 /*****************************************************************************
75 ** Implementation [CubicDerivativeInterpolation]
76 *****************************************************************************/
77
78
80  CubicPolynomial cubic;
81  apply(cubic);
82  return cubic;
83 }
84
86  Polynomial<3>::Coefficients &coefficients = polynomial.coefficients();
87  // First compute the polynomial on [0,xf-xi] (this is easier), then shift it.
88  double dx = x_final - x_initial;
89  double dy = y_final - y_initial;
90  coefficients << y_initial,
92  (3/(dx*dx))*(dy) - (2/dx)*ydot_initial - (1/dx)*ydot_final,
93  (-2/(dx*dx*dx))*(dy) + (ydot_final + ydot_initial)/(dx*dx);
94
95 // Matrix<double,4,4> A;
96 // Matrix<double,4,1> a,b;
97 // b << y_initial, ydot_initial, y_final, ydot_final;
98 //
99 // A << 1, 0, 0, 0,
100 // 0, 1, 0, 0,
101 // 1, dx, dx*dx, dx*dx*dx,
102 // 0, 1, 2*dx, 3*dx*dx;
103 //
104 // a = A.inverse()*b;
105 // std::cout << coefficients << std::endl;
106 // std::cout << a << std::endl;
107
108  if ( x_initial != 0.0 ) {
109  polynomial.shift_horizontal(x_initial);
110  }
111 }
112
113 /*****************************************************************************
114 ** Implementation [CubicDerivativeInterpolation]
115 *****************************************************************************/
116
118  CubicPolynomial cubic;
119  apply(cubic);
120  return cubic;
121 }
122
124  Polynomial<3>::Coefficients &coefficients = polynomial.coefficients();
125  // First compute the polynomial on [0,xf-xi] (this is easier), then shift it.
126  double dx = x_final - x_initial;
127  double a_0 = y_initial;
128  double a_2 = yddot_initial/2;
129  double a_3 = (yddot_final - yddot_initial)/(6*dx);
130  double a_1 = (y_final-a_0-a_2*dx*dx - a_3*dx*dx*dx)/dx;
131  coefficients << a_0, a_1, a_2, a_3;
132  if ( x_initial != 0.0 ) {
133  polynomial.shift_horizontal(x_initial);
134  }
135 }
136
137 /*****************************************************************************
138 ** Implementation [QuinticInterpolation]
139 *****************************************************************************/
140
142  QuinticPolynomial quintic;
143  apply(quintic);
144  return quintic;
145 }
146
147 void QuinticInterpolation::apply(ecl::QuinticPolynomial& polynomial) const {
148  QuinticPolynomial::Coefficients &coefficients = polynomial.coefficients();
149  // First compute the polynomial on [0,xf-xi] (this is easier), then shift it.
150
151  double dx = x_final - x_initial;
152  double d2x = dx*dx;
153  double d3x = d2x*dx;
154  double d4x = d3x*dx;
155  double d5x = d4x*dx;
156  double a_0 = y_initial;
157  double a_1 = ydot_initial;
158  double a_2 = yddot_initial/2;
159  double a_3 = ( 20*(y_final - y_initial) - (8*ydot_final + 12*ydot_initial)*dx - (3*yddot_initial - yddot_final)*dx*dx )
160  / (2*d3x);
161  double a_4 = ( 30*(y_initial - y_final) + (14*ydot_final + 16*ydot_initial)*dx + (- 2*yddot_final + 3*yddot_initial)*dx*dx )
162  / (2*d4x);
163  double a_5 = ( 12*(y_final - y_initial) - (6*ydot_final + 6*ydot_initial)*dx - (yddot_initial - yddot_final)*dx*dx )
164  / (2*d5x);
165
166  coefficients << a_0, a_1, a_2, a_3, a_4, a_5;
167
168 // Matrix<double,6,6> A;
169 // Matrix<double,6,1> a,b;
170 // b << y_initial, ydot_initial, yddot_initial, y_final, ydot_final, yddot_final;
171 //
172 // A << 1, 0, 0, 0, 0, 0,
173 // 0, 1, 0, 0, 0, 0,
174 // 0, 0, 2, 0, 0, 0,
175 // 1, dx, d2x, d3x, d4x, d5x,
176 // 0, 1, 2*dx, 3*d2x, 4*d3x, 5*d4x,
177 // 0, 0, 2, 6*dx, 12*d2x, 20*d3x;
178 //
179 // a = A.inverse()*b;
180 // std::cout << coefficients << std::endl;
181 // std::cout << a << std::endl;
182
183  if ( x_initial != 0.0 ) {
184  polynomial.shift_horizontal(x_initial);
185  }
186 }
187
188
189 }; // namespace blueprints
190
191 using blueprints::LinearInterpolation;
192 using blueprints::LinearPointSlopeForm;
193 using blueprints::CubicDerivativeInterpolation;
194 using blueprints::CubicSecondDerivativeInterpolation;
195 using blueprints::QuinticInterpolation;
196
197 /*****************************************************************************
198 ** BluePrintFactory[LinearFunction]
199 *****************************************************************************/
200
201 LinearInterpolation BluePrintFactory< LinearFunction >::Interpolation(const double x_i, const double y_i, const double x_f, const double y_f) {
202  return LinearInterpolation(x_i, y_i, x_f, y_f);
203 }
204
205 LinearPointSlopeForm BluePrintFactory< LinearFunction >::PointSlopeForm(const double x_f, const double y_f, const double slope) {
206  return LinearPointSlopeForm(x_f, y_f, slope);
207 }
208
209 /*****************************************************************************
210 ** BluePrintFactory[CubicPolynomial]
211 *****************************************************************************/
212
213 CubicDerivativeInterpolation BluePrintFactory< CubicPolynomial >::DerivativeInterpolation(const double x_i, const double y_i, const double ydot_i, const double x_f, const double y_f, const double ydot_f) {
214  return CubicDerivativeInterpolation(x_i, y_i, ydot_i, x_f, y_f, ydot_f);
215 }
216
217 CubicSecondDerivativeInterpolation BluePrintFactory< CubicPolynomial >::SecondDerivativeInterpolation(const double x_i, const double y_i, const double yddot_i, const double x_f, const double y_f, const double yddot_f) {
218  return CubicSecondDerivativeInterpolation(x_i, y_i, yddot_i, x_f, y_f, yddot_f);
219 }
220
221 /*****************************************************************************
222 ** BluePrintFactory[QuinticPolynomial]
223 *****************************************************************************/
224
225 QuinticInterpolation BluePrintFactory< QuinticPolynomial >::Interpolation(const double x_i, const double y_i, const double ydot_i, const double yddot_i,
226  const double x_f, const double y_f, const double ydot_f, const double yddot_f) {
227  return QuinticInterpolation(x_i, y_i, ydot_i, yddot_i, x_f, y_f, ydot_f, yddot_f);
228 }
230
231 } // namespace ecl
ecl::blueprints::CubicDerivativeInterpolation::x_initial
double x_initial
Definition: polynomial.hpp:677
ecl::blueprints::CubicSecondDerivativeInterpolation::yddot_initial
double yddot_initial
Definition: polynomial.hpp:748
ecl::blueprints::LinearPointSlopeForm::instantiate
ecl::LinearFunction instantiate()
Instantiate a copy of the object that is blueprinted.
Definition: polynomial_blueprints.cpp:64
ecl::BluePrintFactory< LinearFunction >::Interpolation
static LinearInterpolation Interpolation(const double x_i, const double y_i, const double x_f, const double y_f)
Blueprint for an interpolating a linear function connecting two points.
Definition: polynomial_blueprints.cpp:205
ecl::blueprints::LinearInterpolation::y_final
double y_final
Definition: polynomial.hpp:547
ecl::blueprints::LinearInterpolation::apply
void apply(ecl::LinearFunction &function) const
Apply the blueprint to configure an existing object.
Definition: polynomial_blueprints.cpp:53
ecl::blueprints::LinearInterpolation::y_initial
double y_initial
Definition: polynomial.hpp:546
ecl::blueprints::LinearInterpolation::instantiate
ecl::LinearFunction instantiate()
Instantiate a copy of the object that is blueprinted.
Definition: polynomial_blueprints.cpp:47
ecl::blueprints::QuinticInterpolation::yddot_initial
double yddot_initial
Definition: polynomial.hpp:826
ecl::blueprints::CubicDerivativeInterpolation::x_final
double x_final
Definition: polynomial.hpp:678
ecl::Polynomial::shift_horizontal
void shift_horizontal(const double &shift)
Horizontal shift transform.
Definition: polynomial.hpp:402
ecl::blueprints::LinearPointSlopeForm::slope
double slope
Definition: polynomial.hpp:605
ecl::blueprints::CubicDerivativeInterpolation::instantiate
ecl::CubicPolynomial instantiate()
Instantiate a copy of the object that is blueprinted.
Definition: polynomial_blueprints.cpp:87
ecl::blueprints::CubicSecondDerivativeInterpolation
Blueprint for interpolating a cubic polynomial between end point conditions.
Definition: polynomial.hpp:698
ecl::blueprints::CubicSecondDerivativeInterpolation::x_initial
double x_initial
Definition: polynomial.hpp:748
ecl::blueprints::CubicDerivativeInterpolation::y_initial
double y_initial
Definition: polynomial.hpp:677
ecl::blueprints::LinearInterpolation::x_initial
double x_initial
Definition: polynomial.hpp:546
ecl::blueprints::CubicDerivativeInterpolation
Blueprint for interpolating a cubic polynomial between end point conditions.
Definition: polynomial.hpp:628
ecl::LinearFunction
Polynomial< 1 > LinearFunction
Mathematical term for 1st order polynomials.
Definition: polynomial.hpp:393
ecl::blueprints::QuinticInterpolation::yddot_final
double yddot_final
Definition: polynomial.hpp:827
ecl::blueprints::CubicSecondDerivativeInterpolation::x_final
double x_final
Definition: polynomial.hpp:749
ecl::blueprints::QuinticInterpolation::x_final
double x_final
Definition: polynomial.hpp:827
ecl::blueprints::QuinticInterpolation::x_initial
double x_initial
Definition: polynomial.hpp:826
ecl::blueprints::CubicSecondDerivativeInterpolation::apply
void apply(base_type &polynomial) const
Apply the blueprint to configure an existing object.
Definition: polynomial_blueprints.cpp:131
ecl::blueprints::CubicSecondDerivativeInterpolation::instantiate
base_type instantiate()
Instantiate a copy of the object that is blueprinted.
Definition: polynomial_blueprints.cpp:125
ecl::blueprints::CubicDerivativeInterpolation::ydot_initial
double ydot_initial
Definition: polynomial.hpp:677
ecl::blueprints::CubicSecondDerivativeInterpolation::y_initial
double y_initial
Definition: polynomial.hpp:748
ecl::blueprints::QuinticInterpolation
Blueprint for interpolating a quintic polynomial between end point conditions.
Definition: polynomial.hpp:772
ecl::blueprints::CubicDerivativeInterpolation::ydot_final
double ydot_final
Definition: polynomial.hpp:678
ecl::blueprints::QuinticInterpolation::instantiate
ecl::QuinticPolynomial instantiate()
Instantiate a copy of the object that is blueprinted.
Definition: polynomial_blueprints.cpp:149
ecl::Polynomial
Representation of a polynomial function of n-th degree.
Definition: polynomial.hpp:50
ecl::blueprints::CubicSecondDerivativeInterpolation::yddot_final
double yddot_final
Definition: polynomial.hpp:749
ecl::BluePrintFactory
ecl::blueprints::CubicSecondDerivativeInterpolation::y_final
double y_final
Definition: polynomial.hpp:749
ecl::blueprints::CubicDerivativeInterpolation::apply
void apply(ecl::CubicPolynomial &polynomial) const
Apply the blueprint to configure an existing object.
Definition: polynomial_blueprints.cpp:93
ecl::blueprints::QuinticInterpolation::apply
void apply(ecl::QuinticPolynomial &polynomial) const
Apply the blueprint to configure an existing object.
Definition: polynomial_blueprints.cpp:155
ecl::blueprints::QuinticInterpolation::y_final
double y_final
Definition: polynomial.hpp:827
ecl::QuinticPolynomial
Polynomial< 5 > QuinticPolynomial
Mathematical term for 5th order polynomials.
Definition: polynomial.hpp:396
ecl::blueprints::QuinticInterpolation::ydot_final
double ydot_final
Definition: polynomial.hpp:827
ecl::blueprints::QuinticInterpolation::ydot_initial
double ydot_initial
Definition: polynomial.hpp:826
ecl::blueprints::LinearPointSlopeForm
Blueprint for generating a linear function from slope and point pair.
Definition: polynomial.hpp:562
ecl::Array< double, N+1 >
ecl::blueprints::LinearInterpolation::x_final
double x_final
Definition: polynomial.hpp:547
ecl::CubicPolynomial
Polynomial< 3 > CubicPolynomial
Mathematical term for 3rd order polynomials.
Definition: polynomial.hpp:395
ecl::blueprints::LinearPointSlopeForm::y_final
double y_final
Definition: polynomial.hpp:606
ecl::blueprints::CubicDerivativeInterpolation::y_final
double y_final
Definition: polynomial.hpp:678
ecl::blueprints::LinearPointSlopeForm::x_final
double x_final
Definition: polynomial.hpp:606
ecl::Polynomial::coefficients
Coefficients & coefficients()
Handle to the coefficient array, use to initialise the polynomial.
Definition: polynomial.hpp:241
ecl::blueprints::LinearPointSlopeForm::apply
void apply(ecl::LinearFunction &function) const
Apply the blueprint to configure an existing object.
Definition: polynomial_blueprints.cpp:70
ecl
Embedded control libraries.
ecl::blueprints::QuinticInterpolation::y_initial
double y_initial
Definition: polynomial.hpp:826
ecl::Polynomial::Coefficients
Array< double, N+1 > Coefficients
The coefficient container storage type.
Definition: polynomial.hpp:123

ecl_geometry
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:39