hpp-core  4.12.0
Implement basic classes for canonical path planning for kinematic chains.
math.hh
Go to the documentation of this file.
1 // Copyright (c) 2017, Joseph Mirabel
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4 // This file is part of hpp-core.
5 // hpp-core is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // hpp-core is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // hpp-core. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HPP_CORE_PATH_MATH_HH
18 #define HPP_CORE_PATH_MATH_HH
19 
20 namespace hpp {
21  namespace core {
22  namespace path {
23  template <int N> struct binomials {
24  typedef Eigen::Matrix<size_type, N, 1> Factorials_t;
25 
26  static inline const Factorials_t& factorials ()
27  {
28  static Factorials_t ret (Factorials_t::Zero());
29  if (ret(0)==0) {
30  ret (0) = 1;
31  for (size_type i = 1; i < N; ++i) ret(i) = ret(i-1) * i;
32  }
33  return ret;
34  }
35 
36  static inline size_type binomial (size_type n, size_type k)
37  {
38  const Factorials_t& factors = factorials();
39  assert (n >= k && k >= 0);
40  assert (n < N);
41  size_type denom = factors(k) * factors(n - k);
42  return factors (n) / denom;
43  }
44  };
45  } // namespace path
46  } // namespace core
47 } // namespace hpp
48 
49 #endif // HPP_CORE_PATH_MATH_HH
Eigen::Matrix< size_type, N, 1 > Factorials_t
Definition: math.hh:24
Definition: bi-rrt-planner.hh:24
pinocchio::size_type size_type
Definition: fwd.hh:156
static const Factorials_t & factorials()
Definition: math.hh:26
static size_type binomial(size_type n, size_type k)
Definition: math.hh:36
Definition: math.hh:23