hermite  0.0.1
hermite_sub.hpp
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include <algorithm>
10 #include <cstddef>
11 
15 
16 namespace hermite {
23 template <std::size_t D> class HermiteSub : public BaseInterpol<D> {
24 public:
31  HermiteSub() : m_lower{0}, m_upper{1} {};
32 
45  HermiteSub(const Vector<D> p0, const Vector<D> pf, const Vector<D> v0,
46  const Vector<D> vf, const double lower, const double upper)
47  : m_lower{lower}, m_upper{upper}, m_unit{p0, pf, v0 * (upper - lower),
48  vf * (upper - lower)} {};
49 
53  HermiteSub(const HermiteSub<D> &other)
54  : m_lower{other.m_lower}, m_upper{other.m_upper}, m_unit{other.m_unit} {}
55 
60  // check if assigning to self
61  if (this == &other) {
62  return *this;
63  }
64 
65  m_unit = other.m_unit;
66  m_lower = other.m_lower;
67  m_upper = other.m_upper;
68 
69  return *this;
70  }
71 
75  ~HermiteSub() override = default;
76 
89  Vector<D> getPos(const double t) const override {
90  Vector<D> res;
91  const double tNew = (t - m_lower) / (m_upper - m_lower);
92  res = m_unit.getPos(tNew);
93  return res;
94  }
95 
106  Vector<D> getVel(const double t) const override {
107  Vector<D> res;
108  const double tNew = (t - m_lower) / (m_upper - m_lower);
109  res = m_unit.getVel(tNew) * (1 / (m_upper - m_lower)); // multiply by chain
110  return res;
111  }
112 
123  Vector<D> getAcc(const double t) const override {
124  Vector<D> res;
125  const double tNew = (t - m_lower) / (m_upper - m_lower);
126  res = m_unit.getAcc(tNew) * (1 / (m_upper - m_lower)) *
127  (1 / (m_upper -
128  m_lower)); // multiply by chain; don't need to add product rule
129  // because second derivative of tNew(t) = 0
130  return res;
131  }
132 
133 private:
134  double m_lower;
135  double m_upper;
136  HermiteUnit<D> m_unit;
137 };
138 } // namespace hermite
Base class for interpolation functions.
Definition: base_interpol.hpp:23
A hermite spline on a subinterval.
Definition: hermite_sub.hpp:23
Vector< D > getPos(const double t) const override
Gets position at a certain time.
Definition: hermite_sub.hpp:89
HermiteSub()
Default constructor.
Definition: hermite_sub.hpp:31
HermiteSub(const HermiteSub< D > &other)
Copy constructor.
Definition: hermite_sub.hpp:53
HermiteSub< D > & operator=(const HermiteSub< D > &other)
Assignment operator.
Definition: hermite_sub.hpp:59
Vector< D > getVel(const double t) const override
Gets velocity at a certain time.
Definition: hermite_sub.hpp:106
~HermiteSub() override=default
Destructor.
HermiteSub(const Vector< D > p0, const Vector< D > pf, const Vector< D > v0, const Vector< D > vf, const double lower, const double upper)
Constructor.
Definition: hermite_sub.hpp:45
Vector< D > getAcc(const double t) const override
Gets acceleration of the function at a certain time.
Definition: hermite_sub.hpp:123
Interpolates on the unit interval.
Definition: hermite_unit.hpp:29
A base vector representation.
Definition: simplevectors.hpp:63