41 #ifndef FCL_CCD_TAYLOR_MODEL_INL_H 42 #define FCL_CCD_TAYLOR_MODEL_INL_H 44 #include "fcl/math/motion/taylor_model/taylor_model.h" 51 class TaylorModel<double>;
55 TaylorModel<double> operator * (
double d,
const TaylorModel<double>& a);
59 TaylorModel<double> operator + (
double d,
const TaylorModel<double>& a);
63 TaylorModel<double> operator - (
double d,
const TaylorModel<double>& a);
67 void generateTaylorModelForCosFunc(TaylorModel<double>& tm,
double w,
double q0);
71 void generateTaylorModelForSinFunc(TaylorModel<double>& tm,
double w,
double q0);
75 void generateTaylorModelForLinearFunc(TaylorModel<double>& tm,
double p,
double v);
79 void TaylorModel<S>::setTimeInterval(S l, S r)
81 time_interval_->setValue(l, r);
86 void TaylorModel<S>::setTimeInterval(
const std::shared_ptr<TimeInterval<S> >& time_interval)
88 time_interval_ = time_interval;
93 const std::shared_ptr<TimeInterval<S> >&TaylorModel<S>::getTimeInterval()
const 95 return time_interval_;
100 S TaylorModel<S>::coeff(std::size_t i)
const 106 template <
typename S>
107 S&TaylorModel<S>::coeff(std::size_t i)
113 template <
typename S>
114 const Interval<S>&TaylorModel<S>::remainder()
const 120 template <
typename S>
121 Interval<S>&TaylorModel<S>::remainder()
127 template <
typename S>
128 TaylorModel<S>::TaylorModel()
130 coeffs_[0] = coeffs_[1] = coeffs_[2] = coeffs_[3] = 0;
134 template <
typename S>
135 TaylorModel<S>::TaylorModel(
const std::shared_ptr<TimeInterval<S>>& time_interval) : time_interval_(time_interval)
137 coeffs_[0] = coeffs_[1] = coeffs_[2] = coeffs_[3] = 0;
141 template <
typename S>
142 TaylorModel<S>::TaylorModel(S coeff,
const std::shared_ptr<TimeInterval<S>>& time_interval) : time_interval_(time_interval)
145 coeffs_[1] = coeffs_[2] = coeffs_[3] = r_[0] = r_[1] = 0;
149 template <
typename S>
150 TaylorModel<S>::TaylorModel(S coeffs[3],
const Interval<S>& r,
const std::shared_ptr<TimeInterval<S>>& time_interval) : time_interval_(time_interval)
152 coeffs_[0] = coeffs[0];
153 coeffs_[1] = coeffs[1];
154 coeffs_[2] = coeffs[2];
155 coeffs_[3] = coeffs[3];
161 template <
typename S>
162 TaylorModel<S>::TaylorModel(S c0, S c1, S c2, S c3,
const Interval<S>& r,
const std::shared_ptr<TimeInterval<S>>& time_interval) : time_interval_(time_interval)
173 template <
typename S>
174 TaylorModel<S> TaylorModel<S>::operator + (S d)
const 176 return TaylorModel(coeffs_[0] + d, coeffs_[1], coeffs_[2], coeffs_[3], r_, time_interval_);
180 template <
typename S>
181 TaylorModel<S>& TaylorModel<S>::operator += (S d)
188 template <
typename S>
189 TaylorModel<S> TaylorModel<S>::operator - (S d)
const 191 return TaylorModel(coeffs_[0] - d, coeffs_[1], coeffs_[2], coeffs_[3], r_, time_interval_);
195 template <
typename S>
196 TaylorModel<S>& TaylorModel<S>::operator -= (S d)
203 template <
typename S>
204 TaylorModel<S> TaylorModel<S>::operator + (
const TaylorModel<S>& other)
const 206 assert(other.time_interval_ == time_interval_);
207 return TaylorModel(coeffs_[0] + other.coeffs_[0], coeffs_[1] + other.coeffs_[1], coeffs_[2] + other.coeffs_[2], coeffs_[3] + other.coeffs_[3], r_ + other.r_, time_interval_);
211 template <
typename S>
212 TaylorModel<S> TaylorModel<S>::operator - (
const TaylorModel<S>& other)
const 214 assert(other.time_interval_ == time_interval_);
215 return TaylorModel(coeffs_[0] - other.coeffs_[0], coeffs_[1] - other.coeffs_[1], coeffs_[2] - other.coeffs_[2], coeffs_[3] - other.coeffs_[3], r_ - other.r_, time_interval_);
219 template <
typename S>
220 TaylorModel<S>& TaylorModel<S>::operator += (
const TaylorModel<S>& other)
222 assert(other.time_interval_ == time_interval_);
223 coeffs_[0] += other.coeffs_[0];
224 coeffs_[1] += other.coeffs_[1];
225 coeffs_[2] += other.coeffs_[2];
226 coeffs_[3] += other.coeffs_[3];
232 template <
typename S>
233 TaylorModel<S>& TaylorModel<S>::operator -= (
const TaylorModel<S>& other)
235 assert(other.time_interval_ == time_interval_);
236 coeffs_[0] -= other.coeffs_[0];
237 coeffs_[1] -= other.coeffs_[1];
238 coeffs_[2] -= other.coeffs_[2];
239 coeffs_[3] -= other.coeffs_[3];
258 template <
typename S>
267 template <
typename S>
270 return TaylorModel(coeffs_[0] * d, coeffs_[1] * d, coeffs_[2] * d, coeffs_[3] * d, r_ * d, time_interval_);
274 template <
typename S>
277 assert(other.time_interval_ == time_interval_);
278 register S c0, c1, c2, c3;
279 register S c0b = other.coeffs_[0], c1b = other.coeffs_[1], c2b = other.coeffs_[2], c3b = other.coeffs_[3];
283 c0 = coeffs_[0] * c0b;
284 c1 = coeffs_[0] * c1b + coeffs_[1] * c0b;
285 c2 = coeffs_[0] * c2b + coeffs_[1] * c1b + coeffs_[2] * c0b;
286 c3 = coeffs_[0] * c3b + coeffs_[1] * c2b + coeffs_[2] * c1b + coeffs_[3] * c0b;
289 register S tempVal = coeffs_[1] * c3b + coeffs_[2] * c2b + coeffs_[3] * c1b;
290 remainder += time_interval_->t4_ * tempVal;
292 tempVal = coeffs_[2] * c3b + coeffs_[3] * c2b;
293 remainder += time_interval_->t5_ * tempVal;
295 tempVal = coeffs_[3] * c3b;
296 remainder += time_interval_->t6_ * tempVal;
298 remainder += ((
Interval<S>(coeffs_[0]) + time_interval_->t_ * coeffs_[1] + time_interval_->t2_ * coeffs_[2] + time_interval_->t3_ * coeffs_[3]) * rb +
299 (
Interval<S>(c0b) + time_interval_->t_ * c1b + time_interval_->t2_ * c2b + time_interval_->t3_ * c3b) * r_);
312 template <
typename S>
324 template <
typename S>
327 return TaylorModel(-coeffs_[0], -coeffs_[1], -coeffs_[2], -coeffs_[3], -r_, time_interval_);
331 template <
typename S>
334 std::cout << coeffs_[0] <<
"+" << coeffs_[1] <<
"*t+" << coeffs_[2] <<
"*t^2+" << coeffs_[3] <<
"*t^3+[" << r_[0] <<
"," << r_[1] <<
"]" << std::endl;
338 template <
typename S>
341 return Interval<S>(coeffs_[0] + t * (coeffs_[1] + t * (coeffs_[2] + t * coeffs_[3]))) + r_;
345 template <
typename S>
352 return Interval<S>(coeffs_[0]) + t * coeffs_[1] + t2 * coeffs_[2] + t3 * coeffs_[3] + r_;
356 template <
typename S>
359 return Interval<S>(coeffs_[0] + r_[0], coeffs_[1] + r_[1]) + time_interval_->t_ * coeffs_[1] + time_interval_->t2_ * coeffs_[2] + time_interval_->t3_ * coeffs_[3];
363 template <
typename S>
366 if(t0 < time_interval_->t_[0]) t0 = time_interval_->t_[0];
367 if(t1 > time_interval_->t_[1]) t1 = time_interval_->t_[1];
371 register S a = -coeffs_[1] / (2 * coeffs_[2]);
373 if(a <= t1 && a >= t0)
375 S AQ = coeffs_[0] + a * (coeffs_[1] + a * coeffs_[2]);
377 S LQ = coeffs_[0] + t * (coeffs_[1] + t * coeffs_[2]);
379 S RQ = coeffs_[0] + t * (coeffs_[1] + t * coeffs_[2]);
381 S minQ = LQ, maxQ = RQ;
388 if(minQ > AQ) minQ = AQ;
389 if(maxQ < AQ) maxQ = AQ;
396 S LQ = coeffs_[0] + t * (coeffs_[1] + t * coeffs_[2]);
398 S RQ = coeffs_[0] + t * (coeffs_[1] + t * coeffs_[2]);
400 if(LQ > RQ) polybounds.
setValue(RQ, LQ);
404 return polybounds + r_;
409 S LQ = coeffs_[0] + t * (coeffs_[1] + t * (coeffs_[2] + t * coeffs_[3]));
411 S RQ = coeffs_[0] + t * (coeffs_[1] + t * (coeffs_[2] + t * coeffs_[3]));
422 S delta = coeffs_[2] * coeffs_[2] - 3 * coeffs_[1] * coeffs_[3];
426 S r1 = (-coeffs_[2]-sqrt(delta))/(3*coeffs_[3]);
427 S r2 = (-coeffs_[2]+sqrt(delta))/(3*coeffs_[3]);
429 if(r1 <= t1 && r1 >= t0)
431 S Q = coeffs_[0] + r1 * (coeffs_[1] + r1 * (coeffs_[2] + r1 * coeffs_[3]));
433 else if(Q > RQ) RQ = Q;
436 if(r2 <= t1 && r2 >= t0)
438 S Q = coeffs_[0] + r2 * (coeffs_[1] + r2 * (coeffs_[2] + r2 * coeffs_[3]));
440 else if(Q > RQ) RQ = Q;
448 template <
typename S>
451 return getTightBound(time_interval_->t_[0], time_interval_->t_[1]);
455 template <
typename S>
458 coeffs_[0] = coeffs_[1] = coeffs_[2] = coeffs_[3] = 0;
463 template <
typename S>
471 res.remainder() *= d;
476 template <
typename S>
483 template <
typename S>
490 template <
typename S>
493 S a = tm.getTimeInterval()->t_.center();
501 tm.coeff(0) = fa-a*(fda-0.5*a*(fdda-1.0/3.0*a*fddda));
502 tm.coeff(1) = fda-a*fdda+0.5*a*a*fddda;
503 tm.coeff(2) = 0.5*(fdda-a*fddda);
504 tm.coeff(3) = 1.0/6.0*fddda;
511 S cosQL = cos(tm.getTimeInterval()->t_[0] * w + q0);
512 S cosQR = cos(tm.getTimeInterval()->t_[1] * w + q0);
514 if(cosQL < cosQR) fddddBounds.
setValue(cosQL, cosQR);
515 else fddddBounds.
setValue(cosQR, cosQL);
518 fddddBounds[0] -= 1e-15;
519 fddddBounds[1] += 1e-15;
530 if(ceil(k2) - floor(k1) > 1) fddddBounds[1] = 1;
533 if(ceil(k2) - floor(k1) > 1) fddddBounds[0] = -1;
537 if(ceil(k1) - floor(k2) > 1) fddddBounds[1] = 1;
540 if(ceil(k1) - floor(k2) > 1) fddddBounds[0] = -1;
547 S midSize = 0.5 * (tm.getTimeInterval()->t_[1] - tm.getTimeInterval()->t_[0]);
548 S midSize2 = midSize * midSize;
549 S midSize4 = midSize2 * midSize2;
552 if(fddddBounds[0] > 0)
553 tm.remainder().setValue(0, fddddBounds[1] * midSize4 * (1.0 / 24));
554 else if(fddddBounds[0] < 0)
555 tm.remainder().setValue(fddddBounds[0] * midSize4 * (1.0 / 24), 0);
557 tm.remainder().setValue(fddddBounds[0] * midSize4 * (1.0 / 24), fddddBounds[1] * midSize4 * (1.0 / 24));
561 template <
typename S>
564 S a = tm.getTimeInterval()->t_.center();
572 tm.coeff(0) = fa-a*(fda-0.5*a*(fdda-1.0/3.0*a*fddda));
573 tm.coeff(1) = fda-a*fdda+0.5*a*a*fddda;
574 tm.coeff(2) = 0.5*(fdda-a*fddda);
575 tm.coeff(3) = 1.0/6.0*fddda;
584 S sinQL = sin(w * tm.getTimeInterval()->t_[0] + q0);
585 S sinQR = sin(w * tm.getTimeInterval()->t_[1] + q0);
587 if(sinQL < sinQR) fddddBounds.
setValue(sinQL, sinQR);
588 else fddddBounds.
setValue(sinQR, sinQL);
591 fddddBounds[0] -= 1e-15;
592 fddddBounds[1] += 1e-15;
597 S k1 = (tm.getTimeInterval()->t_[0] * w + q0) / (2 *
constants<S>::pi()) - 0.25;
598 S k2 = (tm.getTimeInterval()->t_[1] * w + q0) / (2 *
constants<S>::pi()) - 0.25;
602 if(ceil(k2) - floor(k1) > 1) fddddBounds[1] = 1;
605 if(ceil(k2) - floor(k1) > 1) fddddBounds[0] = -1;
609 if(ceil(k1) - floor(k2) > 1) fddddBounds[1] = 1;
612 if(ceil(k1) - floor(k2) > 1) fddddBounds[0] = -1;
618 S midSize = 0.5 * (tm.getTimeInterval()->t_[1] - tm.getTimeInterval()->t_[0]);
619 S midSize2 = midSize * midSize;
620 S midSize4 = midSize2 * midSize2;
623 if(fddddBounds[0] > 0)
624 tm.remainder().setValue(0, fddddBounds[1] * midSize4 * (1.0 / 24));
625 else if(fddddBounds[0] < 0)
626 tm.remainder().setValue(fddddBounds[0] * midSize4 * (1.0 / 24), 0);
628 tm.remainder().setValue(fddddBounds[0] * midSize4 * (1.0 / 24), fddddBounds[1] * midSize4 * (1.0 / 24));
633 template <
typename S>
640 tm.remainder()[0] = 0;
641 tm.remainder()[1] = 0;
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
Interval class for [a, b].
Definition: interval.h:50
TaylorModel operator*(const TaylorModel &other) const
Taylor model multiplication: f(t) = c0+c1*t+c2*t^2+c3*t^3+[a,b] g(t) = c0'+c1'*t+c2'*t^2+c3'*t^2+[c,d] f(t)g(t)= c0c0'+ (c0c1'+c1c0')t+ (c0c2'+c1c1'+c2c0')t^2+ (c0c3'+c1c2'+c2c1'+c3c0')t^3+ [a,b][c,d]+ (c1c3'+c2c2'+c3c1')t^4+ (c2c3'+c3c2')t^5+ (c3c3')t^6+ (c0+c1*t+c2*t^2+c3*t^3)[c,d]+ (c0'+c1'*t+c2'*t^2+c3'*c^3)[a,b].
Definition: taylor_model-inl.h:259
void setValue(S a, S b)
construct interval [left, right]
Definition: interval-inl.h:82
Definition: constants.h:46
TaylorModel implements a third order Taylor model, i.e., a cubic approximation of a function over a t...
Definition: taylor_model.h:58