9 #ifndef _CLASS_BERNSTEIN 10 #define _CLASS_BERNSTEIN 26 inline unsigned int bin(
const unsigned int n,
const unsigned int k) {
27 if (k > n)
throw std::runtime_error(
"binomial coefficient higher than degree");
29 if (k > n / 2)
return bin(n, n - k);
30 return n * bin(n - 1, k - 1) / k;
36 template <
typename Numeric =
double>
39 Bern(
const unsigned int m,
const unsigned int i) : m_minus_i(m - i), i_(i), bin_m_i_(bin(m, i)) {}
47 if (!(u >= 0. && u <= 1.)) {
48 throw std::invalid_argument(
"u needs to be betwen 0 and 1.");
50 return bin_m_i_ * (pow(u, i_)) * pow((1 - u), m_minus_i);
56 virtual bool operator==(
const Bern& other)
const {
57 return ndcurves::isApprox<Numeric>(m_minus_i, other.m_minus_i) && ndcurves::isApprox<Numeric>(i_, other.i_) &&
58 ndcurves::isApprox<Numeric>(bin_m_i_, other.bin_m_i_);
64 virtual bool operator!=(
const Bern& other)
const {
return !(*
this == other); }
73 friend class boost::serialization::access;
74 template <
class Archive>
75 void serialize(Archive& ar,
const unsigned int version) {
79 ar& boost::serialization::make_nvp(
"m_minus_i", m_minus_i);
80 ar& boost::serialization::make_nvp(
"i", i_);
81 ar& boost::serialization::make_nvp(
"bin_m_i", bin_m_i_);
87 template <
typename Numeric>
89 std::vector<Bern<Numeric> > res;
90 for (
unsigned int i = 0; i <= n; ++i) {
91 res.push_back(Bern<Numeric>(n, i));
99 #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:88
double Numeric
Definition: effector_spline.h:26