|
@@ -1,162 +0,0 @@
|
|
-#ifndef QUINTICPOLYNOMIAL_H
|
|
|
|
-#define QUINTICPOLYNOMIAL_H
|
|
|
|
-
|
|
|
|
-#pragma once
|
|
|
|
-
|
|
|
|
-#include <array>
|
|
|
|
-#include "absl/strings/str_cat.h"
|
|
|
|
-#include "absl/strings/str_join.h"
|
|
|
|
-
|
|
|
|
-namespace adtoolbox {
|
|
|
|
-namespace core {
|
|
|
|
-
|
|
|
|
-class QuinticPolynomial
|
|
|
|
-{
|
|
|
|
-public:
|
|
|
|
- QuinticPolynomial() = default;
|
|
|
|
- virtual ~QuinticPolynomial() = default;
|
|
|
|
-
|
|
|
|
- QuinticPolynomial(const double x0, const double dx0, const double ddx0,
|
|
|
|
- const double x1, const double dx1, const double ddx1,
|
|
|
|
- const double t);
|
|
|
|
-
|
|
|
|
- QuinticPolynomial(const std::array<double, 3> &start,
|
|
|
|
- const std::array<double, 3> &end,
|
|
|
|
- const double t);
|
|
|
|
-
|
|
|
|
- void fitBoundaryConditions(const double x0, const double dx0, const double ddx0,
|
|
|
|
- const double x1, const double dx1, const double ddx1,
|
|
|
|
- const double t);
|
|
|
|
-
|
|
|
|
- double evaluate(const size_t order, const double t) const;
|
|
|
|
- size_t order() const;
|
|
|
|
- double paramLength() const;
|
|
|
|
- double coef(const size_t order) const;
|
|
|
|
- std::string toString() const;
|
|
|
|
-
|
|
|
|
-private:
|
|
|
|
- void computeCoefficients(const double x0, const double dx0, const double ddx0,
|
|
|
|
- const double x1, const double dx1, const double ddx1,
|
|
|
|
- const double t);
|
|
|
|
-
|
|
|
|
- double t_;
|
|
|
|
- std::array<double, 3> start_condition_;
|
|
|
|
- std::array<double, 3> end_condition_;
|
|
|
|
- std::array<double, 6> coef_;
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-// ----------------------------------------
|
|
|
|
-
|
|
|
|
-QuinticPolynomial::QuinticPolynomial(const double x0, const double dx0, const double ddx0,
|
|
|
|
- const double x1, const double dx1, const double ddx1,
|
|
|
|
- const double t)
|
|
|
|
-{
|
|
|
|
- t_ = t;
|
|
|
|
- start_condition_[0] = x0;
|
|
|
|
- start_condition_[1] = dx0;
|
|
|
|
- start_condition_[2] = ddx0;
|
|
|
|
- end_condition_[0] = x1;
|
|
|
|
- end_condition_[1] = dx1;
|
|
|
|
- end_condition_[2] = ddx1;
|
|
|
|
- computeCoefficients(x0, dx0, ddx0, x1, dx1, ddx1, t);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// ----------------------------------------
|
|
|
|
-
|
|
|
|
-QuinticPolynomial::QuinticPolynomial(const std::array<double, 3> &start,
|
|
|
|
- const std::array<double, 3> &end,
|
|
|
|
- const double t)
|
|
|
|
- : QuinticPolynomial::QuinticPolynomial(start[0], start[1], start[2],
|
|
|
|
- end[0], end[1], end[2], t) {}
|
|
|
|
-
|
|
|
|
-void QuinticPolynomial::fitBoundaryConditions(const double x0, const double dx0, const double ddx0,
|
|
|
|
- const double x1, const double dx1, const double ddx1,
|
|
|
|
- const double t)
|
|
|
|
-{
|
|
|
|
- t_ = t;
|
|
|
|
- start_condition_[0] = x0;
|
|
|
|
- start_condition_[1] = dx0;
|
|
|
|
- start_condition_[2] = ddx0;
|
|
|
|
- end_condition_[0] = x1;
|
|
|
|
- end_condition_[1] = dx1;
|
|
|
|
- end_condition_[2] = ddx1;
|
|
|
|
- computeCoefficients(x0, dx0, ddx0, x1, dx1, ddx1, t);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// ----------------------------------------
|
|
|
|
-
|
|
|
|
-double QuinticPolynomial::evaluate(const size_t order, const double p) const
|
|
|
|
-{
|
|
|
|
- switch (order)
|
|
|
|
- {
|
|
|
|
- case 0:
|
|
|
|
- return ((((coef_[5] * p + coef_[4]) * p + coef_[3]) * p + coef_[2]) * p + coef_[1]) * p + coef_[0];
|
|
|
|
- case 1:
|
|
|
|
- return (((5.0 * coef_[5] * p + 4.0 * coef_[4]) * p + 3.0 * coef_[3]) * p + 2.0 * coef_[2]) * p + coef_[1];
|
|
|
|
- case 2:
|
|
|
|
- return (((20.0 * coef_[5] * p + 12.0 * coef_[4]) * p) + 6.0 * coef_[3]) * p + 2.0 * coef_[2];
|
|
|
|
- case 3:
|
|
|
|
- return (60.0 * coef_[5] * p + 24.0 * coef_[4]) * p + 6.0 * coef_[3];
|
|
|
|
- case 4:
|
|
|
|
- return 120.0 * coef_[5] * p + 24.0 * coef_[4];
|
|
|
|
- case 5:
|
|
|
|
- return 120.0 * coef_[5];
|
|
|
|
- default:
|
|
|
|
- return 0.0;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// ----------------------------------------
|
|
|
|
-
|
|
|
|
-size_t QuinticPolynomial::order() const
|
|
|
|
-{
|
|
|
|
- return 5;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// ----------------------------------------
|
|
|
|
-
|
|
|
|
-double QuinticPolynomial::coef(const size_t order) const
|
|
|
|
-{
|
|
|
|
- return coef_[order];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// ----------------------------------------
|
|
|
|
-
|
|
|
|
-double QuinticPolynomial::paramLength() const
|
|
|
|
-{
|
|
|
|
- return t_;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// ----------------------------------------
|
|
|
|
-
|
|
|
|
-std::string QuinticPolynomial::toString() const
|
|
|
|
-{
|
|
|
|
- return absl::StrCat("QuinticPoly(", absl::StrJoin(coef_, ", "), ")");
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// ----------------------------------------
|
|
|
|
-
|
|
|
|
-void QuinticPolynomial::computeCoefficients(const double x0, const double dx0, const double ddx0,
|
|
|
|
- const double x1, const double dx1, const double ddx1,
|
|
|
|
- const double t)
|
|
|
|
-{
|
|
|
|
- coef_[0] = x0;
|
|
|
|
- coef_[1] = dx0;
|
|
|
|
- coef_[2] = 0.5 * ddx0;
|
|
|
|
-
|
|
|
|
- double t2 = t * t;
|
|
|
|
- double t3 = t * t2;
|
|
|
|
-
|
|
|
|
- double c0 = (x1 - 0.5 * t2 * ddx0 - dx0 * t - x0) / t3;
|
|
|
|
- double c1 = (dx1 - ddx0 * t - dx0) / t2;
|
|
|
|
- double c2 = (ddx1 - ddx0) / t;
|
|
|
|
-
|
|
|
|
- coef_[3] = 0.5 * (20.0 * c0 - 8.0 * c1 + c2);
|
|
|
|
- coef_[4] = (-15.0 * c0 + 7.0 * c1 - c2) / t;
|
|
|
|
- coef_[5] = (6.0 * c0 - 3.0 * c1 + 0.5 * c2) / t2;
|
|
|
|
-}
|
|
|
|
-// ----------------------------------------
|
|
|
|
-// Ends class QuinticPolynomial
|
|
|
|
-}
|
|
|
|
-}
|
|
|
|
-#endif // QUINTICPOLYNOMIAL_H
|
|
|