23#include "absl/strings/str_cat.h"
24#include "absl/strings/str_join.h"
32 const std::array<double, 3>& start,
const std::array<double, 2>& end,
38 const double x0,
const double dx0,
const double ddx0,
const double dx1,
39 const double ddx1,
const double param) {
41 start_condition_[0] = x0;
42 start_condition_[1] = dx0;
43 start_condition_[2] = ddx0;
44 end_condition_[0] = dx1;
45 end_condition_[1] = ddx1;
46 ComputeCoefficients(x0, dx0, ddx0, dx1, ddx1, param);
56 const double p)
const {
59 return (((coef_[4] * p + coef_[3]) * p + coef_[2]) * p + coef_[1]) * p +
63 return ((4.0 * coef_[4] * p + 3.0 * coef_[3]) * p + 2.0 * coef_[2]) * p +
67 return (12.0 * coef_[4] * p + 6.0 * coef_[3]) * p + 2.0 * coef_[2];
70 return 24.0 * coef_[4] * p + 6.0 * coef_[3];
73 return 24.0 * coef_[4];
81 const double x0,
const double dx0,
const double ddx0,
const double x1,
82 const double dx1,
const double p) {
91 coef_[2] = 0.5 * ddx0;
97 double b0 = x1 - coef_[0] - coef_[1] * p - coef_[2] * p2;
98 double b1 = dx1 - dx0 - ddx0 * p;
100 coef_[4] = (b1 * p - 3 * b0) / p4;
101 coef_[3] = (4 * b0 - b1 * p) / p3;
106 const double x0,
const double dx0,
const double x1,
const double dx1,
107 const double ddx1,
const double p) {
120 double b0 = x1 - coef_[0] - coef_[1] * p;
121 double b1 = dx1 - coef_[1];
123 double c2 = ddx1 * p2;
125 coef_[2] = (0.5 * c2 - 3 * c1 + 6 * b0) / p2;
126 coef_[3] = (-c2 + 5 * c1 - 8 * b0) / p3;
127 coef_[4] = (0.5 * c2 - 2 * c1 + 3 * b0) / p4;
134 CHECK_EQ(other.
Order(), 3U);
136 coef_[0] = init_value;
137 for (
size_t i = 0; i < 4; ++i) {
138 coef_[i + 1] = other.
Coef(i) / (
static_cast<double>(i) + 1);
145 CHECK_EQ(other.
Order(), 5U);
147 for (
size_t i = 1; i < 6; ++i) {
148 coef_[i - 1] = other.
Coef(i) *
static_cast<double>(i);
153void QuarticPolynomialCurve1d::ComputeCoefficients(
154 const double x0,
const double dx0,
const double ddx0,
const double dx1,
155 const double ddx1,
const double p) {
160 coef_[2] = 0.5 * ddx0;
162 double b0 = dx1 - ddx0 * p - dx0;
163 double b1 = ddx1 - ddx0;
168 coef_[3] = (3 * b0 - b1 * p) / (3 * p2);
169 coef_[4] = (-2 * b0 + b1 * p) / (4 * p3);
173 return absl::StrCat(absl::StrJoin(coef_,
"\t"),
param_,
"\n");
virtual double ParamLength() const =0
virtual size_t Order() const =0
virtual double Coef(const size_t order) const =0
QuarticPolynomialCurve1d()=default
QuarticPolynomialCurve1d & IntegratedFromCubicCurve(const PolynomialCurve1d &other, const double init_value)
double Coef(const size_t order) const override
QuarticPolynomialCurve1d & FitWithEndPointSecondOrder(const double x0, const double dx0, const double x1, const double dx1, const double ddx1, const double param)
Interface with refine quartic polynomial by meets end point second order and start point first order ...
double Evaluate(const std::uint32_t order, const double p) const override
QuarticPolynomialCurve1d & DerivedFromQuinticCurve(const PolynomialCurve1d &other)
std::string ToString() const override
QuarticPolynomialCurve1d & FitWithEndPointFirstOrder(const double x0, const double dx0, const double ddx0, const double x1, const double dx1, const double param)
Interface with refine quartic polynomial by meets end first order and start second order boundary con...
Planning module main class.