|
Robotics Library
0.7.0
|
Go to the documentation of this file.
27 #ifndef RL_MATH_QUATERNIONSPLINE_H
28 #define RL_MATH_QUATERNIONSPLINE_H
44 typedef ::std::vector<Polynomial<Quaternion>>::const_iterator
ConstIterator;
48 typedef ::std::vector<Polynomial<Quaternion>>::iterator
Iterator;
69 assert(x.size() == y.size());
71 ::std::size_t n = x.size();
75 ::std::vector<Real> dtheta(n - 1);
76 ::std::vector<Real> dx(n - 1);
77 ::std::vector<Vector3> e(n - 1);
79 for (::std::size_t i = 0; i < n - 1; ++i)
81 dx[i] = x[i + 1] - x[i];
82 dtheta[i] = y[i].angularDistance(y[i + 1]);
83 e[i] = (y[i].inverse() * y[i + 1]).vec();
85 if (e[i].norm() <= ::std::numeric_limits<Real>::epsilon())
95 ::std::vector<Real> a(n);
96 ::std::vector<Real> b(n);
97 ::std::vector<Real> c(n);
98 ::std::vector<Vector3> d(n);
100 ::std::vector<Vector3> omega(n, Vector3::Zero());
101 ::std::vector<Vector3> omegaprev(n);
105 for (::std::size_t i = 1; i < n - 1; ++i)
107 omegaprev[i] = omega[i];
110 for (::std::size_t i = 1; i < n - 1; ++i)
112 a[i] = 2 / dx[i - 1];
113 b[i] = 4 / dx[i - 1] + 4 / dx[i];
115 d[i] = (6 * e[i - 1] * dtheta[i - 1]) / ::
std::pow(dx[i - 1], 2) + (6 * e[i] * dtheta[i]) / ::
std::pow(dx[i], 2) - R(e[i - 1], dtheta[i - 1], omegaprev[i]);
120 d[1] -= a[1] * B(e[0], dtheta[0], yd0);
121 d[n - 2] -= c[n - 2] * invB(e[n - 2], dtheta[n - 2], yd1);
124 for (::std::size_t i = 2; i < n - 1; ++i)
126 b[i] -= c[i - 1] * a[i] / b[i - 1];
127 d[i] -= (a[i] / b[i - 1]) * B(e[i - 1], dtheta[i - 1], d[i - 1]);
132 omega[n - 2] = d[n - 2] / b[n - 2];
135 for (::std::size_t i = 1; i < n - 2; ++i)
137 omega[n - 2 - i] = (d[n - 2 - i] - c[n - 2 - i] * invB(e[n - 2 - i], dtheta[n - 2 - i], omega[n - 2 - i + 1])) / b[n - 2 - i];
142 for (::std::size_t i = 1; i < n - 1; ++i)
144 dOmega += (omega[i] - omegaprev[i]).norm();
147 while (dOmega > 1.0e-6f);
152 for (::std::size_t i = 0; i < n - 1; ++i)
157 fi.
coefficient(2) = dx[i] * invB(e[i], dtheta[i], omega[i + 1]) - 3 * e[i] * dtheta[i];
319 ConstReverseIterator
rend()
const
344 if (dtheta <= ::std::numeric_limits<Real>::epsilon())
349 Real cosdtheta = ::std::cos(dtheta);
350 Real sindtheta = ::std::sin(dtheta);
352 return x.dot(e) * e + sindtheta / dtheta * e.cross(x).cross(e) - (1 - cosdtheta) / dtheta * e.cross(x);
357 if (dtheta <= ::std::numeric_limits<Real>::epsilon())
362 Real cosdtheta = ::std::cos(dtheta);
363 Real sindtheta = ::std::sin(dtheta);
365 return e.dot(x) * e + 0.5f * (dtheta * sindtheta) / (1 - cosdtheta) * e.cross(x).cross(e) + 0.5f * dtheta * e.cross(x);
370 if (dtheta <= ::std::numeric_limits<Real>::epsilon())
372 return Vector3::Zero();
375 Real cosdtheta = ::std::cos(dtheta);
376 Real sindtheta = ::std::sin(dtheta);
378 Real r0 = 0.5f * (dtheta - sindtheta) / (1 - cosdtheta);
379 Real r1 = (dtheta * sindtheta - 2 * (1 - cosdtheta)) / (dtheta * (1 - cosdtheta));
381 return r0 * (omega.dot(omega) -
::std::pow(e.dot(omega), 2)) * e + r1 * e.dot(omega) * e.cross(omega).cross(e);
387 #endif // RL_MATH_QUATERNIONSPLINE_H
Quaternion< Scalar > pow(const Scalar &t) const
Definition: QuaternionBaseAddons.h:128
Iterator begin()
Definition: SplineQuaternion.h:187
static Spline< Quaternion > CubicFirst(const ::std::vector< Real > &x, const ::std::vector< Quaternion > &y, const Vector3 &yd0, const Vector3 &yd1)
Definition: SplineQuaternion.h:66
Real duration() const
Definition: PolynomialQuaternion.h:130
A mathematical mapping from Real -> ArrayX.
Definition: Function.h:45
Real x1
Definition: Function.h:104
::Eigen::Matrix< Real, 3, 1 > Vector3
Definition: Vector.h:46
Iterator end()
Definition: SplineQuaternion.h:217
Real x0
Definition: SplineQuaternion.h:337
Polynomial< Quaternion > & back()
Definition: SplineQuaternion.h:177
ConstIterator begin() const
Definition: SplineQuaternion.h:192
ConstIterator end() const
Definition: SplineQuaternion.h:222
Definition: PolynomialQuaternion.h:45
Spline derivative() const
Definition: Spline.h:720
ReverseIterator rbegin()
Definition: SplineQuaternion.h:304
::std::size_t size() const
Definition: SplineQuaternion.h:299
Real & upper()
Definition: SplineQuaternion.h:324
const Polynomial< Quaternion > & at(const ::std::size_t &i) const
Definition: SplineQuaternion.h:172
::std::vector< Polynomial< T > > polynomials
Definition: Spline.h:920
::std::vector< Polynomial< Quaternion > > polynomials
Definition: SplineQuaternion.h:335
const Real & upper() const
Definition: SplineQuaternion.h:329
Real duration() const
Definition: SplineQuaternion.h:207
Real & upper()
Definition: Function.h:74
Real x1
Definition: SplineQuaternion.h:339
Definition: SplineQuaternion.h:42
static Vector3 R(const Vector3 &e, const Real &dtheta, const Vector3 &omega)
Definition: SplineQuaternion.h:368
static Vector3 B(const Vector3 &e, const Real &dtheta, const Vector3 &x)
Definition: SplineQuaternion.h:342
::std::vector< Polynomial< Quaternion > >::const_iterator ConstIterator
Definition: SplineQuaternion.h:44
const Polynomial< Quaternion > & front() const
Definition: SplineQuaternion.h:232
const Real & lower() const
Definition: SplineQuaternion.h:242
void pop_back()
Definition: SplineQuaternion.h:274
Real & upper()
Definition: PolynomialQuaternion.h:216
Quaternion operator()(const Real &x, const ::std::size_t &derivative=0) const
Evaluates the function or a derivative thereof for a given value x.
Definition: SplineQuaternion.h:247
Spline< Quaternion > * clone() const
Definition: SplineQuaternion.h:202
::std::vector< Polynomial< Quaternion > >::iterator Iterator
Definition: SplineQuaternion.h:48
Vector3 & coefficient(const ::std::size_t &i)
Definition: PolynomialQuaternion.h:115
Real & lower()
Definition: SplineQuaternion.h:237
Real x0
Definition: Function.h:102
ConstReverseIterator rbegin() const
Definition: SplineQuaternion.h:309
ConstReverseIterator rend() const
Definition: SplineQuaternion.h:319
void push_back(Polynomial< Quaternion > &polynomial)
Definition: SplineQuaternion.h:288
Polynomial< Quaternion > & at(const ::std::size_t &i)
Definition: SplineQuaternion.h:167
ReverseIterator rend()
Definition: SplineQuaternion.h:314
::Eigen::Quaternion< Real > Quaternion
Definition: Quaternion.h:42
static const Real FUNCTION_BOUNDARY
Definition: Function.h:110
bool empty()
Definition: SplineQuaternion.h:212
const Polynomial< Quaternion > & back() const
Definition: SplineQuaternion.h:182
Real & lower()
Definition: PolynomialQuaternion.h:135
Real & lower()
Definition: Function.h:64
void clear()
Definition: SplineQuaternion.h:197
Quaternion y0
Definition: PolynomialQuaternion.h:226
double Real
Definition: Real.h:42
const Polynomial< Quaternion > & operator[](const ::std::size_t &i) const
Definition: SplineQuaternion.h:269
Polynomial< Quaternion > & operator[](const ::std::size_t &i)
Definition: SplineQuaternion.h:264
A piecewise Function of Polynomial functions.
Definition: Spline.h:53
::std::vector< Polynomial< T > >::reverse_iterator ReverseIterator
Definition: Spline.h:61
::std::vector< Polynomial< Quaternion > >::const_reverse_iterator ConstReverseIterator
Definition: SplineQuaternion.h:46
static Vector3 invB(const Vector3 &e, const Real &dtheta, const Vector3 &x)
Definition: SplineQuaternion.h:355
Polynomial< Quaternion > & front()
Definition: SplineQuaternion.h:227
Robotics Library.
Definition: AnalogInput.cpp:30