cubic_function.h 2.29 KB
Newer Older
1
/**
stonneau's avatar
stonneau committed
2
* \file cubic_function.h
3
4
5
6
7
* \brief Definition of a cubic spline.
* \author Steve T.
* \version 0.1
* \date 06/17/2013
*
8
9
10
* This file contains definitions for the CubicFunction struct.
* It allows the creation and evaluation of natural
* smooth cubic splines of arbitrary dimension
11
12
13
*/


14
15
#ifndef _STRUCT_CUBICFUNCTION
#define _STRUCT_CUBICFUNCTION
16
17

#include "MathDefs.h"
18

stonneau's avatar
stonneau committed
19
#include "curve_abc.h"
20

21
22
#include <stdexcept>

23
24
namespace spline
{
stonneau's avatar
stonneau committed
25
26
27
28
29
/// \class CubicFunction
/// \brief Represents a cubic spline defined on the interval 
/// [tBegin, tEnd]. It follows the equation
/// x(t) = a + b(t - t_min_) + c(t - t_min_)^2 + d(t - t_min_)^3 
///
30
template<typename Time= double, typename Numeric=Time, std::size_t Dim=3, bool Safe=false
stonneau's avatar
stonneau committed
31
32
33
, typename Point= Eigen::Matrix<Numeric, Dim, 1> >
struct cubic_function : public curve_abc<Time, Numeric, Dim, Safe, Point>
{
34
35
36
	typedef Point 	point_t;
  	typedef Time 	time_t;
  	typedef Numeric	num_t;
37
38
/* Constructors - destructors */
	public:
stonneau's avatar
stonneau committed
39
40
41
42
	///\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)
		:a_(a), b_(b), c_(c), d_(d), t_min_(min), t_max_(max)
	{
43
		if(t_min_ > t_max_ && Safe)
44
		{
stonneau's avatar
stonneau committed
45
			std::out_of_range("TODO");
46
		}
stonneau's avatar
stonneau committed
47
	}
48

stonneau's avatar
stonneau committed
49
50
51
52
53
	///\brief Destructor
	~cubic_function()
	{
		// NOTHING
	}
54
55

	private:
stonneau's avatar
stonneau committed
56
57
	cubic_function(const cubic_function&);
	cubic_function& operator=(const cubic_function&);
58
59
60
61
/* Constructors - destructors */

/*Operations*/
	public:
stonneau's avatar
stonneau committed
62
63
64
65
66
67
68
69
70
	///  \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");}
	    	time_t const dt (t-t_min_);
	    	return a_+ b_ * dt + c_ * dt*dt  + d_ * dt*dt*dt;
	}
71
/*Operations*/
72
		
73
74
/*Helpers*/
	public:
stonneau's avatar
stonneau committed
75
76
77
78
	///  \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_;}
79
80
81
/*Helpers*/

/*Attributes*/
82
	public:
stonneau's avatar
stonneau committed
83
84
	const point_t a_, b_, c_ ,d_;
	const time_t t_min_, t_max_;
85
86
87
/*Attributes*/
	}; //class CubicFunction
}
88
#endif //_STRUCT_CUBICFUNCTION
89