Skip to content
Snippets Groups Projects
Commit a0527d5d authored by Steve Tonneau's avatar Steve Tonneau Committed by Steve Tonneau
Browse files

cubic_spline inherits spline_curve

parent d1757d2a
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "MathDefs.h" #include "MathDefs.h"
#include "curve_abc.h" #include "spline_curve.h"
#include <stdexcept> #include <stdexcept>
...@@ -28,23 +28,30 @@ namespace spline ...@@ -28,23 +28,30 @@ namespace spline
/// x(t) = a + b(t - t_min_) + c(t - t_min_)^2 + d(t - t_min_)^3 /// x(t) = a + b(t - t_min_) + c(t - t_min_)^2 + d(t - t_min_)^3
/// ///
template<typename Time= double, typename Numeric=Time, std::size_t Dim=3, bool Safe=false template<typename Time= double, typename Numeric=Time, std::size_t Dim=3, bool Safe=false
, typename Point= Eigen::Matrix<Numeric, Dim, 1> > , typename Point= Eigen::Matrix<Numeric, Dim, 1>, typename T_Point =std::vector<Point,Eigen::aligned_allocator<Point> > >
struct cubic_function : public curve_abc<Time, Numeric, Dim, Safe, Point> struct cubic_function : public spline_curve<Time, Numeric, Dim,3, Safe, Point, T_Point>
{ {
typedef Point point_t; typedef Point point_t;
typedef T_Point t_point_t;
typedef Time time_t; typedef Time time_t;
typedef Numeric num_t; typedef Numeric num_t;
typedef spline_curve<Time, Numeric, Dim,3, Safe, Point, T_Point> spline_curve_t;
/* Constructors - destructors */ /* Constructors - destructors */
public: public:
///\brief Constructor ///\brief Constructor
cubic_function(point_t const& a, point_t const& b, point_t const& c, point_t const &d, time_t min, time_t max) cubic_function(point_t const& a, point_t const& b, point_t const& c, point_t const &d, time_t min, time_t max)
:a_(a), b_(b), c_(c), d_(d), t_min_(min), t_max_(max) :spline_curve_t(makeVector(a,b,c,d), min, max) {}
{
if(t_min_ > t_max_ && Safe)
{ ///\brief Constructor
std::out_of_range("TODO"); cubic_function(const T_Point& coefficients, time_t min, time_t max)
} :spline_curve_t(coefficients, min, max) {}
}
///\brief Constructor
template<typename In>
cubic_function(In zeroOrderCoefficient, In out, time_t min, time_t max)
:spline_curve_t(zeroOrderCoefficient, out, min, max) {}
///\brief Destructor ///\brief Destructor
~cubic_function() ~cubic_function()
...@@ -57,32 +64,15 @@ struct cubic_function : public curve_abc<Time, Numeric, Dim, Safe, Point> ...@@ -57,32 +64,15 @@ struct cubic_function : public curve_abc<Time, Numeric, Dim, Safe, Point>
cubic_function& operator=(const cubic_function&); cubic_function& operator=(const cubic_function&);
/* Constructors - destructors */ /* Constructors - destructors */
/*Operations*/ /*Operations*/
public: T_Point makeVector(point_t const& a, point_t const& b, point_t const& c, point_t const &d)
/// \brief Evaluation of the cubic spline at time t.
/// \param t : the time when to evaluate the spine
/// \param return : the value x(t)
virtual point_t operator()(time_t t) const
{ {
if((t < t_min_ || t > t_max_) && Safe){ throw std::out_of_range("TODO");} T_Point res;
time_t const dt (t-t_min_); res.push_back(a);res.push_back(b);res.push_back(c);res.push_back(d);
return a_+ b_ * dt + c_ * dt*dt + d_ * dt*dt*dt; return res;
} }
/*Operations*/
/*Helpers*/
public:
/// \brief Returns the minimum time for wich curve is defined
num_t virtual min() const {return t_min_;}
/// \brief Returns the maximum time for wich curve is defined
num_t virtual max() const {return t_max_;}
/*Helpers*/
/*Attributes*/ /*Operations*/
public:
const point_t a_, b_, c_ ,d_;
const time_t t_min_, t_max_;
/*Attributes*/
}; //class CubicFunction }; //class CubicFunction
} }
#endif //_STRUCT_CUBICFUNCTION #endif //_STRUCT_CUBICFUNCTION
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment