cubic_function.h 2.28 KB
 stonneau committed Jun 19, 2013 1 ``````/** `````` stonneau committed Jun 27, 2013 2 ``````* \file cubic_function.h `````` stonneau committed Jun 19, 2013 3 4 5 6 7 ``````* \brief Definition of a cubic spline. * \author Steve T. * \version 0.1 * \date 06/17/2013 * `````` stonneau committed Jun 27, 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 `````` stonneau committed Jun 19, 2013 11 12 13 ``````*/ `````` stonneau committed Jun 27, 2013 14 15 ``````#ifndef _STRUCT_CUBICFUNCTION #define _STRUCT_CUBICFUNCTION `````` stonneau committed Jun 19, 2013 16 17 `````` #include "MathDefs.h" `````` stonneau committed Jun 27, 2013 18 `````` `````` stonneau committed Jun 27, 2013 19 ``````#include "curve_abc.h" `````` stonneau committed Jun 19, 2013 20 `````` `````` stonneau committed Jun 27, 2013 21 22 ``````#include `````` stonneau committed Jun 19, 2013 23 24 ``````namespace spline { `````` stonneau committed Jun 27, 2013 25 26 27 28 29 30 31 32 33 ``````/// \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 /// template > struct cubic_function : public curve_abc { `````` stonneau committed Jun 27, 2013 34 35 36 `````` typedef Point point_t; typedef Time time_t; typedef Numeric num_t; `````` stonneau committed Jun 19, 2013 37 38 ``````/* Constructors - destructors */ public: `````` stonneau committed Jun 27, 2013 39 40 41 42 43 `````` ///\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) { if(t_min_ >= t_max_ & Safe) `````` stonneau committed Jun 27, 2013 44 `````` { `````` stonneau committed Jun 27, 2013 45 `````` std::out_of_range("TODO"); `````` stonneau committed Jun 27, 2013 46 `````` } `````` stonneau committed Jun 27, 2013 47 `````` } `````` stonneau committed Jun 19, 2013 48 `````` `````` stonneau committed Jun 27, 2013 49 50 51 52 53 `````` ///\brief Destructor ~cubic_function() { // NOTHING } `````` stonneau committed Jun 19, 2013 54 55 `````` private: `````` stonneau committed Jun 27, 2013 56 57 `````` cubic_function(const cubic_function&); cubic_function& operator=(const cubic_function&); `````` stonneau committed Jun 19, 2013 58 59 60 61 ``````/* Constructors - destructors */ /*Operations*/ public: `````` stonneau committed Jun 27, 2013 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; } `````` stonneau committed Jun 19, 2013 71 ``````/*Operations*/ `````` stonneau committed Jun 27, 2013 72 `````` `````` stonneau committed Jun 19, 2013 73 74 ``````/*Helpers*/ public: `````` stonneau committed Jun 27, 2013 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_;} `````` stonneau committed Jun 19, 2013 79 80 81 ``````/*Helpers*/ /*Attributes*/ `````` stonneau committed Jun 27, 2013 82 `````` public: `````` stonneau committed Jun 27, 2013 83 84 `````` const point_t a_, b_, c_ ,d_; const time_t t_min_, t_max_; `````` stonneau committed Jun 19, 2013 85 86 87 ``````/*Attributes*/ }; //class CubicFunction } `````` stonneau committed Jun 27, 2013 88 ``````#endif //_STRUCT_CUBICFUNCTION `````` stonneau committed Jun 27, 2013 89