9 #ifndef _CLASS_BERNSTEIN 10 #define _CLASS_BERNSTEIN 26 inline unsigned int bin(
const unsigned int n,
const unsigned int k) {
28 throw std::runtime_error(
"binomial coefficient higher than degree");
30 if (k > n / 2)
return bin(n, n - k);
31 return n * bin(n - 1, k - 1) / k;
37 template <
typename Numeric =
double>
40 Bern(
const unsigned int m,
const unsigned int i)
41 : m_minus_i(m - i), i_(i), bin_m_i_(bin(m, i)) {}
49 if (!(u >= 0. && u <= 1.)) {
50 throw std::invalid_argument(
"u needs to be betwen 0 and 1.");
52 return bin_m_i_ * (pow(u, i_)) * pow((1 - u), m_minus_i);
58 virtual bool operator==(
const Bern& other)
const {
59 return ndcurves::isApprox<Numeric>(m_minus_i, other.m_minus_i) &&
60 ndcurves::isApprox<Numeric>(i_, other.i_) &&
61 ndcurves::isApprox<Numeric>(bin_m_i_, other.bin_m_i_);
67 virtual bool operator!=(
const Bern& other)
const {
return !(*
this == other); }
76 friend class boost::serialization::access;
77 template <
class Archive>
78 void serialize(Archive& ar,
const unsigned int version) {
82 ar& boost::serialization::make_nvp(
"m_minus_i", m_minus_i);
83 ar& boost::serialization::make_nvp(
"i", i_);
84 ar& boost::serialization::make_nvp(
"bin_m_i", bin_m_i_);
90 template <
typename Numeric>
92 std::vector<Bern<Numeric> > res;
93 for (
unsigned int i = 0; i <= n; ++i) {
94 res.push_back(Bern<Numeric>(n, i));
102 #endif //_CLASS_BERNSTEIN Definition: bernstein.h:20
interface for a Curve of arbitrary dimension.
brief Computes all Bernstein polynomes for a certain degree std::vector< Bern< Numeric > > makeBernstein(const unsigned int n)
Definition: bernstein.h:91
#define DEFINE_CLASS_TEMPLATE_VERSION(Template, Type)
Definition: archive.hpp:27
double Numeric
Definition: effector_spline.h:26
void serialize(Archive &ar, Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &m, const unsigned int version)
Definition: eigen-matrix.hpp:77