24template<
typename Scalar>
30 template<
typename Derived>
31 Polynomial(
const Eigen::DenseBase<Derived>& coefficients)
37 [[nodiscard]] Scalar
f(Scalar x)
const
40 auto xpow =
static_cast<Scalar
>(1.0);
43 value += coeff * xpow;
53 Eigen::VectorX<Scalar> derivative = Eigen::VectorX<Scalar>::Zero(degree);
54 for (
int i = 0; i < degree; i++)
62 [[nodiscard]]
const Eigen::VectorX<Scalar>&
coeffs()
const
70 [[nodiscard]] std::string
toString(fmt::format_string<double> fmt =
"{:.1e}",
const char* var =
"x")
const
79 out += fmt::format(
"{}{}", positive ?
"" :
"-", a);
83 out += fmt::format(
" {} {}{}{}",
87 i > 1 ? fmt::format(
"^{}", i) :
"");
100#ifndef DOXYGEN_IGNORE
103template<
typename Scalar>
104struct fmt::formatter<NAV::Polynomial<Scalar>> : fmt::formatter<std::string>
110 template<
typename FormatContext>
113 return fmt::formatter<std::string>::format(poly.
toString(), ctx);
123template<
typename Scalar>
126 return os << fmt::format(
"{}", obj);
std::ostream & operator<<(std::ostream &os, const NAV::Polynomial< Scalar > &obj)
Stream insertion operator overload.
Definition Polynomial.hpp:124
Polynomial.
Definition Polynomial.hpp:26
Eigen::VectorX< Scalar > _coefficients
Polynomial coefficients in order a0 + a1 * x + a2 * x^2 + ...
Definition Polynomial.hpp:95
const Eigen::VectorX< Scalar > & coeffs() const
Returns the coefficients.
Definition Polynomial.hpp:62
Polynomial< Scalar > getDerivative() const
Calculates the derivative of the polynomial.
Definition Polynomial.hpp:50
std::string toString(fmt::format_string< double > fmt="{:.1e}", const char *var="x") const
Format the polynomial as a string.
Definition Polynomial.hpp:70
Scalar f(Scalar x) const
Calculates the polynomial value at given x.
Definition Polynomial.hpp:37
Polynomial(const Eigen::DenseBase< Derived > &coefficients)
Constructor.
Definition Polynomial.hpp:31