Robotics Library  0.6.2
Cubic.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009, Markus Rickert
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 // POSSIBILITY OF SUCH DAMAGE.
25 //
26 
27 #ifndef _RL_MATH_CUBIC_H_
28 #define _RL_MATH_CUBIC_H_
29 
30 #include <cmath>
31 #include <limits>
32 
33 #include "Real.h"
34 
35 namespace rl
36 {
37  namespace math
38  {
39  template< typename T >
40  class Cubic
41  {
42  public:
43  Cubic() :
44  te(::std::numeric_limits<Real>::max()),
45  x0(),
46  xe(),
47  v0(),
48  ve(),
49  c0(),
50  c1(),
51  c2(),
52  c3()
53  {
54  }
55 
56  virtual ~Cubic()
57  {
58  }
59 
60  T a(const Real& t) const
61  {
62  return 2 * c2 + 6 * c3 * t;
63  }
64 
65  void interpolate()
66  {
67  c0 = x0;
68  c1 = v0;
69  c2 = -(2 * te * v0 + 3 * x0 - 3 * xe + te * ve) / ::std::pow(te, 2);
70  c3 = (2 * x0 + te * v0 - 2 * xe + te * ve) / ::std::pow(te, 3);
71  }
72 
73  T v(const Real& t) const
74  {
75  return c1 + 2 * c2 * t + 3 * c3 * ::std::pow(t, 2);
76  }
77 
78  T x(const Real& t) const
79  {
80  return c0 + c1 * t + c2 * ::std::pow(t, 2) + c3 * ::std::pow(t, 3);
81  }
82 
84 
85  T x0;
86 
87  T xe;
88 
89  T v0;
90 
91  T ve;
92 
93  protected:
94 
95  private:
96  T c0;
97 
98  T c1;
99 
100  T c2;
101 
102  T c3;
103  };
104  }
105 }
106 
107 #endif // _RL_MATH_CUBIC_H_
rl::math::Cubic::c0
T c0
Definition: Cubic.h:96
rl::math::Cubic::c2
T c2
Definition: Cubic.h:100
rl::math::Cubic::~Cubic
virtual ~Cubic()
Definition: Cubic.h:56
rl::math::Cubic::x
T x(const Real &t) const
Definition: Cubic.h:78
rl::math::Cubic
Definition: Cubic.h:41
rl::math::Cubic::x0
T x0
Definition: Cubic.h:85
rl::math::Cubic::c1
T c1
Definition: Cubic.h:98
rl::math::Cubic::ve
T ve
Definition: Cubic.h:91
rl::math::Cubic::v0
T v0
Definition: Cubic.h:89
rl::math::Cubic::v
T v(const Real &t) const
Definition: Cubic.h:73
rl::math::Cubic::te
Real te
Definition: Cubic.h:83
rl::math::Cubic::a
T a(const Real &t) const
Definition: Cubic.h:60
Real.h
rl::math::Cubic::c3
T c3
Definition: Cubic.h:102
rl::math::Real
double Real
Definition: Real.h:34
rl::math::Cubic::xe
T xe
Definition: Cubic.h:87
rl::math::Cubic::Cubic
Cubic()
Definition: Cubic.h:43
rl::math::Cubic::interpolate
void interpolate()
Definition: Cubic.h:65
rl
Definition: Ati.cpp:35