CubicFunction.h 2.28 KB
Newer Older
1
2
3
4
5
6
7
/**
* \file ExactCubic.h
* \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
18

#include "Exports.h"
#include "MathDefs.h"
19

20
#include "Curve_ABC.h"
21

22
23
#include <stdexcept>

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

		///\brief Destructor
51
52
53
54
		SPLINE_API ~cubic_function()
		{
			// NOTHING
		}
55
56

	private:
57
58
		//cubic_function(const cubic_function&);
		//cubic_function& operator=(const cubic_function&);
59
60
61
62
63
64
/* Constructors - destructors */

/*Operations*/
	public:
		///  \brief Evaluation of the cubic spline at time t.
		///  \param t : the time when to evaluate the spine
65
66
67
68
69
70
71
		///  \param return : the value x(t)
		SPLINE_API 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;
		}
72
/*Operations*/
73
		
74
75
/*Helpers*/
	public:
76
77
		SPLINE_API num_t virtual MinBound() const {return t_min_;}
		SPLINE_API num_t virtual MaxBound() const {return t_max_;}
78
79
80
/*Helpers*/

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