|
@@ -0,0 +1,95 @@
|
|
|
|
+/****************************************
|
|
|
|
+ * Class: Quartic Polynomial class
|
|
|
|
+ * Purpose: Fitting a quartic polynomial on interval [0, t] by given
|
|
|
|
+ * boundary conditions.
|
|
|
|
+ * Author: Zhao Liang
|
|
|
|
+ * Last Updated: 2021/02/23
|
|
|
|
+*****************************************
|
|
|
|
+*
|
|
|
|
+* Note: The polynomial is defined on interval [0, t] and has form
|
|
|
|
+*
|
|
|
|
+* f(t) = a0 + a1*t + a2*t^2 + a3*t^3 + a4*t^4
|
|
|
|
+*
|
|
|
|
+* Boundary conditions are given by:
|
|
|
|
+* 1. x0=f(0), dx0=f'(0), ddx0=f''(0)
|
|
|
|
+* 2. dx1=f'(t), ddx1=f''(t)
|
|
|
|
+*/
|
|
|
|
+
|
|
|
|
+#ifndef QUARTIC_POLYNOMIAL_H
|
|
|
|
+#define QUARTIC_POLYNOMIAL_H
|
|
|
|
+
|
|
|
|
+#pragma once
|
|
|
|
+
|
|
|
|
+#include <array>
|
|
|
|
+
|
|
|
|
+namespace iv {
|
|
|
|
+namespace math {
|
|
|
|
+
|
|
|
|
+class QuarticPolynomial
|
|
|
|
+{
|
|
|
|
+public:
|
|
|
|
+ QuarticPolynomial() = default;
|
|
|
|
+ ~QuarticPolynomial() = default;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @brief Initialize a quartic polynomial by given boundary conditions.
|
|
|
|
+ * @param x0: start point at x=0
|
|
|
|
+ * @param dx0: first order derivative at the start point
|
|
|
|
+ * @param ddx0: second order derivative at the start point
|
|
|
|
+ * @param dx1: first order derivative at the end point x=t.
|
|
|
|
+ * @param ddx1: second order derivative at the end point x=t.
|
|
|
|
+ * @param t: parameter length.
|
|
|
|
+ */
|
|
|
|
+ QuarticPolynomial(const double x0, const double dx0, const double ddx0,
|
|
|
|
+ const double dx1, const double ddx1,
|
|
|
|
+ const double t
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @brief You can also pack the boundary conditions into two arrays.
|
|
|
|
+ */
|
|
|
|
+ QuarticPolynomial(const std::array<double, 3> &start,
|
|
|
|
+ const std::array<double, 2> &end,
|
|
|
|
+ const double t);
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @brief Evaluate the n-th derivative of this polynomial at a given point p.
|
|
|
|
+ * @param order: the order of the derivative to be evaluated.
|
|
|
|
+ * @param p: the point to be evaluated.
|
|
|
|
+ */
|
|
|
|
+ double evaluate(const std::uint32_t order, const double p) const;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @brief Return the coefficient of the k-th term.
|
|
|
|
+ */
|
|
|
|
+ double coef(const std::int32_t order) const;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @brief Return all coefficients as a std::array.
|
|
|
|
+ */
|
|
|
|
+ const std::array<double, 5> &coef() const;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @brief Return a pretty string representation of this polynomial
|
|
|
|
+ */
|
|
|
|
+ std::string toString() const;
|
|
|
|
+
|
|
|
|
+private:
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @brief Compute the coefficients array.
|
|
|
|
+ */
|
|
|
|
+ void computeCoefficients(const double x0, const double dx0, const double ddx0,
|
|
|
|
+ const double dx1, const double ddx1,
|
|
|
|
+ const double t
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ double t_;
|
|
|
|
+ std::array<double, 3> start_condition_;
|
|
|
|
+ std::array<double, 2> end_condition_;
|
|
|
|
+ std::array<double, 5> coef_;
|
|
|
|
+};
|
|
|
|
+}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#endif // QUARTIC_POLYNOMIAL_H
|