Go to the documentation of this file.
32 virtual T
derivative(
double t,
int order = 1)
const = 0;
37 return std::numeric_limits<double>::lowest();
43 return std::numeric_limits<double>::max();
63 auto funcIt =
funcs_.lower_bound(t);
64 return (*(funcIt->second))(t);
71 virtual T
derivative(
double t,
int order = 1)
const override
74 auto funcIt =
funcs_.lower_bound(t);
75 return (funcIt->second)->derivative(t, order);
81 virtual size_t index(
double t)
const
84 return std::distance(
funcs_.begin(),
funcs_.lower_bound(t));
98 return std::numeric_limits<double>::max();
100 return funcs_.rbegin()->first;
116 funcs_.insert(std::pair<
double, std::shared_ptr<
Func<T>>>(t, func));
135 throw std::runtime_error(
"[PiecewiseFunc] Argument is out of function range. it should be "
136 + std::to_string(
tLowerLimit_) +
" <= " + std::to_string(t)
137 +
" <= " + std::to_string(
funcs_.rbegin()->first));
143 std::map<double, std::shared_ptr<Func<T>>>
funcs_;
153 template<
class T,
int Order>
175 for(
int i = 0; i < Order; i++)
177 ret +=
coeff_[i + 1] * std::pow(t -
t0_, i + 1);
186 virtual T
derivative(
double t,
int derivativeOrder = 1)
const override
188 if(derivativeOrder > Order)
190 if constexpr(std::is_scalar_v<T>)
202 T ret =
coeff_[derivativeOrder];
203 for(
int j = 0; j < derivativeOrder - 1; j++)
205 ret *= (derivativeOrder - j);
208 for(
int i = 0; i < Order - derivativeOrder; i++)
210 T term =
coeff_[i + 1 + derivativeOrder] * std::pow(t -
t0_, i + 1);
211 for(
int j = 0; j < derivativeOrder; j++)
213 term *= (i + 1 + derivativeOrder - j);
virtual T operator()(double t=0.0) const override
Evaluate function value.
virtual T derivative(double t, int derivativeOrder=1) const override
Evaluate function derivative value.
void appendFunc(double t, std::shared_ptr< Func< T >> func)
Add function.
virtual double domainUpperLimit() const
Get upper limit of domain.
virtual double domainUpperLimit() const override
Get upper limit of domain.
virtual T derivative(double t, int order=1) const override
Evaluate function derivative value.
int order() const
Get polynomial order.
virtual T operator()(double t) const =0
Evaluate function value.
PiecewiseFunc()
Constructor.
std::array< T, Order+1 > coeff_
Coefficients from low order (i.e., constant term) to high order.
virtual T operator()(double t) const override
Evaluate function value.
virtual T operator()(double t) const override
Evaluate function value.
double tLowerLimit_
Lower limit of domain of this function.
virtual double domainLowerLimit() const
Get lower limit of domain.
virtual double domainLowerLimit() const override
Get lower limit of domain.
Polynomial(const std::array< T, Order+1 > &coeff, double t0=0.0)
Constructor.
void checkArg(double t) const
Check argument of function.
void clearFuncs()
Clear function.
Constant(const T &value)
Constructor.
virtual T derivative(double t, int order=1) const =0
Evaluate function derivative value.
double t0_
Offset of function arugment.
void setDomainLowerLimit(double t)
Set lower limit of domain.
std::map< double, std::shared_ptr< Func< T > > > funcs_
Map of upper bound of domain and function.
virtual size_t index(double t) const
Get the index of piecewise functions.