Commit be1a091c authored by JasonChmn's avatar JasonChmn
Browse files

Remove include bernstein in cubic hermite / rename setTimeSplines and...

Remove include bernstein in cubic hermite / rename setTimeSplines and getTimeSplines to setTime and getTime
parent 48e5946d
/**
* \file bezier_curve.h
* \brief class allowing to create a Bezier curve of dimension 1 <= n <= 3.
* \author Steve T.
* \version 0.1
* \date 06/17/2013
*/
#ifndef _CLASS_BERNSTEIN
#define _CLASS_BERNSTEIN
#include "curve_abc.h"
#include "MathDefs.h"
#include <math.h>
#include <vector>
#include <stdexcept>
namespace curves
{
/// \brief Computes factorial of a number.
/// \param n : an unsigned integer.
/// \return \f$n!\f$
///
inline unsigned int fact(const unsigned int n)
{
unsigned int res = 1;
for (unsigned int i=2 ; i <= n ; ++i)
res *= i;
return res;
}
/// \brief Computes a binomial coefficient.
/// \param n : an unsigned integer.
/// \param k : an unsigned integer.
/// \return \f$\binom{n}{k}f$
///
inline unsigned int bin(const unsigned int n, const unsigned int k)
{
return fact(n) / (fact(k) * fact(n - k));
}
/// \class Bernstein.
/// \brief Computes a Bernstein polynome.
///
template <typename Numeric = double>
struct Bern{
Bern(const unsigned int m, const unsigned int i)
:m_minus_i(m - i)
,i_(i)
,bin_m_i_(bin(m,i)) {}
~Bern(){}
Numeric operator()(const Numeric u) const
{
assert(u >= 0. && u <= 1.);
return bin_m_i_*(pow(u, i_)) *pow((1-u),m_minus_i);
}
Numeric m_minus_i;
Numeric i_;
Numeric bin_m_i_;
};
/// \brief Computes all Bernstein polynomes for a certain degree.
///
template <typename Numeric>
std::vector<Bern<Numeric> > makeBernstein(const unsigned int n)
{
std::vector<Bern<Numeric> > res;
for(unsigned int i = 0; i<= n; ++i)
res.push_back(Bern<Numeric>(n, i));
return res;
}
} // namespace curves
#endif //_CLASS_BERNSTEIN
......@@ -9,7 +9,6 @@
#define _CLASS_CUBICHERMITESPLINE
#include "curve_abc.h"
#include "bernstein.h"
#include "curve_constraint.h"
#include "MathDefs.h"
......@@ -85,7 +84,7 @@ struct cubic_hermite_spline : public curve_abc<Time, Numeric, Dim, Safe, Point>
{
control_points_.push_back(*it);
}
setTimeSplines(time_control_points);
setTime(time_control_points);
}
/// \brief Destructor.
......@@ -128,7 +127,7 @@ struct cubic_hermite_spline : public curve_abc<Time, Numeric, Dim, Safe, Point>
/// values corresponding to times for \f$P_0, P_1, P_2, ..., P_N\f$ respectively.<br>
/// \param time_control_points : Vector containing time for each control point.
///
void setTimeSplines(const vector_time_t & time_control_points)
void setTime(const vector_time_t & time_control_points)
{
time_control_points_ = time_control_points;
T_min_ = time_control_points_.front();
......@@ -155,7 +154,7 @@ struct cubic_hermite_spline : public curve_abc<Time, Numeric, Dim, Safe, Point>
/// \brief Get vector of Time corresponding to Time for each control point.
/// \return vector containing time of each control point.
///
vector_time_t getTimeSplines()
vector_time_t getTime()
{
return time_control_points_;
}
......
......@@ -1105,7 +1105,7 @@ void CubicHermitePairsPositionDerivativeTest(bool& error)
time_control_points_test.push_back(0.); // Time at P0
time_control_points_test.push_back(0.5); // Time at P1
time_control_points_test.push_back(1.0); // Time at P2
cubic_hermite_spline_2Pairs.setTimeSplines(time_control_points_test);
cubic_hermite_spline_2Pairs.setTime(time_control_points_test);
res1 = cubic_hermite_spline_2Pairs(0.); // t=0
ComparePoints(p0, res1, errmsg1, error);
res1 = cubic_hermite_spline_2Pairs(0.5); // t=0.5
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment