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 
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,
91  ydot_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 
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 
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 }
229 
230 
231 } // namespace ecl
Blueprint for interpolating a cubic polynomial between end point conditions.
Definition: polynomial.hpp:620
Embedded control libraries.
Blueprint for interpolating a cubic polynomial between end point conditions.
Definition: polynomial.hpp:690
Blueprint for interpolating a linear function connecting end point conditions.
Definition: polynomial.hpp:491
void apply(ecl::CubicPolynomial &polynomial) const
Apply the blueprint to configure an existing object.
ecl::QuinticPolynomial instantiate()
Instantiate a copy of the object that is blueprinted.
Blueprint for generating a linear function from slope and point pair.
Definition: polynomial.hpp:554
ecl::CubicPolynomial instantiate()
Instantiate a copy of the object that is blueprinted.
LinearInterpolation(const double x_i, const double y_i, const double x_f, const double y_f)
Constructor that properly configures/initialises the blueprint.
Definition: polynomial.hpp:507
Polynomial< 1 > LinearFunction
Mathematical term for 1st order polynomials.
Definition: polynomial.hpp:387
void apply(ecl::QuinticPolynomial &polynomial) const
Apply the blueprint to configure an existing object.
void apply(base_type &polynomial) const
Apply the blueprint to configure an existing object.
Coefficients & coefficients()
Handle to the coefficient array, use to initialise the polynomial.
Definition: polynomial.hpp:233
ecl::LinearFunction instantiate()
Instantiate a copy of the object that is blueprinted.
void shift_horizontal(const double &shift)
Horizontal shift transform.
Definition: polynomial.hpp:396
base_type instantiate()
Instantiate a copy of the object that is blueprinted.
Blueprint for interpolating a quintic polynomial between end point conditions.
Definition: polynomial.hpp:764
void apply(ecl::LinearFunction &function) const
Apply the blueprint to configure an existing object.
void apply(ecl::LinearFunction &function) const
Apply the blueprint to configure an existing object.
Polynomial< 3 > CubicPolynomial
Mathematical term for 3rd order polynomials.
Definition: polynomial.hpp:389
Representation of a polynomial function of n-th degree.
Definition: polynomial.hpp:44
Polynomial< 5 > QuinticPolynomial
Mathematical term for 5th order polynomials.
Definition: polynomial.hpp:390
ecl::LinearFunction instantiate()
Instantiate a copy of the object that is blueprinted.


ecl_geometry
Author(s): Daniel Stonier
autogenerated on Mon Feb 28 2022 22:18:49