16 #ifndef SURGSIM_MATH_LINEARMOTIONARITHMETIC_INL_H 17 #define SURGSIM_MATH_LINEARMOTIONARITHMETIC_INL_H 50 m_start = std::move(m.m_start);
51 m_end = std::move(m.m_end);
76 return (std::abs(m_start - m.m_start) <= epsilon) && (std::abs(m_end - m.m_end) <= epsilon);
82 return ((m_start == m.m_start) && (m_end == m.m_end));
100 m_start += m.m_start;
105 template <
typename T>
111 template <
typename T>
114 m_start -= m.m_start;
119 template <
typename T>
125 template <
typename T>
131 template <
typename T>
137 template <
typename T>
143 template <
typename T>
146 return ((static_cast<T>(1) - t) * m_start + t * m_end);
149 template <
typename T>
152 return LinearMotion<T>(m_start, (m_start + m_end) * static_cast<T>(0.5));
155 template <
typename T>
158 return LinearMotion<T>((m_start + m_end) * static_cast<T>(0.5), m_end);
162 template <
typename T,
int N>
167 template <
typename T,
int N>
173 template <
typename T,
int N>
176 m_motion = motion.m_motion;
179 template <
typename T,
int N>
182 *
this = std::move(motion);
185 template <
typename T,
int N>
188 for (
int i = 0; i < N; ++i)
194 template <
typename T,
int N>
197 m_motion = motion.m_motion;
201 template <
typename T,
int N>
206 m_motion = std::move(motion.m_motion);
212 template <
typename T,
int N>
215 std::array<Interval<T>, N> motions;
216 for (
int i = 0; i < N; ++i)
218 motions[i] = m_motion[i].toInterval();
224 template <
typename T,
int N>
227 for (
int i = 0; i < N; i++)
229 if (!m_motion[i].
isApprox(motion.m_interval[i], epsilon))
237 template <
typename T,
int N>
240 return (m_motion == motion.m_motion);
243 template <
typename T,
int N>
249 template <
typename T,
int N>
257 template <
typename T,
int N>
260 for (
int i = 0; i < N; ++i)
262 m_motion[i] += m.m_motion[i];
267 template <
typename T,
int N>
275 template <
typename T,
int N>
278 for (
int i = 0; i < N; ++i)
280 m_motion[i] -= m.m_motion[i];
285 template <
typename T,
int N>
291 template <
typename T,
int N>
297 template <
typename T,
int N>
300 Interval<T> ret(static_cast<T>(0), static_cast<T>(0));
301 for (
int i = 0 ; i < N ; i++)
303 ret += m_motion[i] * motion.m_motion[i];
308 template <
typename T,
int N>
311 SURGSIM_ASSERT((i >= 0) && (i < N)) <<
"Asking for an axis greater than the dimensionality of the linear motion";
315 template <
typename T,
int N>
318 for (
int i = 0; i < N; ++i)
320 (*start)[i] = m_motion[i].getStart();
324 template <
typename T,
int N>
327 for (
int i = 0; i < N; ++i)
329 (*end)[i] = m_motion[i].getEnd();
333 template <
typename T,
int N>
337 for (
int i = 0; i < N; ++i)
339 ret.m_motion[i] = m_motion[i].firstHalf();
344 template <
typename T,
int N>
348 for (
int i = 0; i < N; ++i)
350 ret.m_motion[i] = m_motion[i].secondHalf();
356 template <
typename T>
361 template <
typename T>
369 template <
typename T>
377 template <
typename T>
380 m_motion[0] = motion.m_motion[0];
381 m_motion[1] = motion.m_motion[1];
382 m_motion[2] = motion.m_motion[2];
385 template <
typename T>
388 *
this = std::move(motion);
391 template <
typename T>
399 template <
typename T>
407 template <
typename T>
410 m_motion[0] = motion.m_motion[0];
411 m_motion[1] = motion.m_motion[1];
412 m_motion[2] = motion.m_motion[2];
416 template <
typename T>
419 m_motion[0] = std::move(motion.m_motion[0]);
420 m_motion[1] = std::move(motion.m_motion[1]);
421 m_motion[2] = std::move(motion.m_motion[2]);
425 template <
typename T>
428 std::array<Interval<T>, 3> intervals;
429 intervals[0] = m_motion[0].toInterval();
430 intervals[1] = m_motion[1].toInterval();
431 intervals[2] = m_motion[2].toInterval();
435 template <
typename T>
438 return (m_motion[0].
isApprox(motion.m_motion[0], epsilon) &&
439 m_motion[1].isApprox(motion.m_motion[1], epsilon) &&
440 m_motion[2].isApprox(motion.m_motion[2], epsilon));
443 template <
typename T>
446 return (m_motion[0] == motion.m_motion[0] &&
447 m_motion[1] == motion.m_motion[1] &&
448 m_motion[2] == motion.m_motion[2]);
451 template <
typename T>
457 template <
typename T>
465 template <
typename T>
468 m_motion[0] += m.m_motion[0];
469 m_motion[1] += m.m_motion[1];
470 m_motion[2] += m.m_motion[2];
474 template <
typename T>
482 template <
typename T>
485 m_motion[0] -= m.m_motion[0];
486 m_motion[1] -= m.m_motion[1];
487 m_motion[2] -= m.m_motion[2];
491 template <
typename T>
497 template <
typename T>
503 template <
typename T>
506 return valuesOverInterval(analyticDotProduct(*
this, motion), range);
509 template <
typename T>
515 return IntervalND<T, 3>(valuesOverInterval(analyticCrossProductAxis<double, 0>(*
this, motion), range),
516 valuesOverInterval(analyticCrossProductAxis<double, 1>(*
this, motion), range),
517 valuesOverInterval(analyticCrossProductAxis<double, 2>(*
this, motion), range));
520 template <
typename T>
523 return valuesOverInterval(analyticMagnitudeSquared(*
this), range);
526 template <
typename T>
534 template <
typename T>
537 SURGSIM_ASSERT((i >= 0) && (i < 3)) <<
"Asking for an axis greater than the dimensionality of the linear motion";
541 template <
typename T>
544 (*start)[0] = m_motion[0].getStart();
545 (*start)[1] = m_motion[1].getStart();
546 (*start)[2] = m_motion[2].getStart();
549 template <
typename T>
552 (*end)[0] = m_motion[0].getEnd();
553 (*end)[1] = m_motion[1].getEnd();
554 (*end)[2] = m_motion[2].getEnd();
557 template <
typename T>
563 template <
typename T>
569 template <
typename T>
575 template <
typename T>
579 ret.m_motion[0] = m_motion[0].firstHalf();
580 ret.m_motion[1] = m_motion[1].firstHalf();
581 ret.m_motion[2] = m_motion[2].firstHalf();
585 template <
typename T>
589 ret.m_motion[0] = m_motion[0].secondHalf();
590 ret.m_motion[1] = m_motion[1].secondHalf();
591 ret.m_motion[2] = m_motion[2].secondHalf();
598 template <
typename T>
599 std::ostream& operator<<(std::ostream& o, const LinearMotion<T>& motion)
601 o <<
"(" << motion.
getStart() <<
" -> " << motion.getEnd() <<
")";
606 template <
typename T,
int N>
607 std::ostream& operator<<(std::ostream& o, const LinearMotionND<T, N>& motion)
609 o <<
"([" << motion.getAxis(0).getStart();
610 for (
int i = 1; i < N; ++i)
612 o <<
"," << motion.getAxis(i).getStart();
614 o <<
"] -> [" << motion.getAxis(0).getEnd();
615 for (
int i = 1; i < N; ++i)
617 o <<
"," << motion.getAxis(i).getEnd();
624 template <
typename T>
627 return a.
getAxis(0).toPolynomial() * b.
getAxis(0).toPolynomial() +
632 template <
typename T,
int A>
646 template <
typename T>
649 return analyticCrossProductAxis<double, 0>(a, b);
652 template <
typename T>
655 return analyticCrossProductAxis<double, 1>(a, b);
658 template <
typename T>
661 return analyticCrossProductAxis<double, 2>(a, b);
664 template <
typename T>
668 (*resultXAxis) = analyticCrossProductXAxis(a, b);
669 (*resultYAxis) = analyticCrossProductYAxis(a, b);
670 (*resultZAxis) = analyticCrossProductZAxis(a, b);
673 template <
typename T>
686 return ((bY * cZ - bZ * cY) * aX + (bZ * cX - bX * cZ) * aY + (bX * cY - bY * cX) * aZ);
689 template <
typename T>
693 return valuesOverInterval(analyticTripleProduct(a, b, c), range);
696 template <
typename T>
699 return analyticDotProduct(motion, motion);
705 #endif // SURGSIM_MATH_LINEARMOTIONARITHMETIC_INL_H LinearMotionND()
Constructor.
Definition: LinearMotionArithmetic-inl.h:163
IntervalND< T, N > operator/(const LinearMotionND< T, N > &m) const
Standard arithmetic operators extended to interval groups.
Definition: LinearMotionArithmetic-inl.h:292
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
T getMin() const
Definition: IntervalArithmetic-inl.h:283
bool isApprox(const LinearMotion< T > &i, const T &epsilon) const
Definition: LinearMotionArithmetic-inl.h:74
T getEnd() const
Definition: LinearMotionArithmetic-inl.h:138
IntervalND<T,3> defines the concept of a group of mathematical intervals specialized to 3 intervals a...
Definition: IntervalArithmetic.h:307
const LinearMotion< T > & getAxis(int i) const
Definition: LinearMotionArithmetic-inl.h:535
IntervalND< T, 3 > toInterval() const
Convert from LinearMotion to an Interval.
Definition: LinearMotionArithmetic-inl.h:426
void getStart(std::array< T, 3 > *start) const
Definition: LinearMotionArithmetic-inl.h:542
LinearMotionND<T, 3> specializes the LinearMotionND<T, N> class for 3 dimensions. ...
Definition: LinearMotionArithmetic.h:258
Interval< T > dotProduct(const LinearMotionND< T, N > &motion) const
Definition: LinearMotionArithmetic-inl.h:298
#define SURGSIM_ASSERT(condition)
Assert that condition is true.
Definition: Assert.h:77
T getMax() const
Definition: IntervalArithmetic-inl.h:289
void getEnd(std::array< T, N > *end) const
Definition: LinearMotionArithmetic-inl.h:325
Polynomial<T, 3> specializes the Polynomial class for degree 3 (cubic polynomials) ...
Definition: Polynomial.h:255
IntervalND defines the concept of a group of mathematical intervals and provides operations on them i...
Definition: IntervalArithmetic.h:199
LinearMotionND< T, N > secondHalf() const
Definition: LinearMotionArithmetic-inl.h:345
LinearMotion< T > firstHalf() const
Definition: LinearMotionArithmetic-inl.h:150
bool isApprox(const LinearMotionND< T, N > &motion, const T &epsilon) const
Definition: LinearMotionArithmetic-inl.h:225
Polynomial<T, 2> specializes the Polynomial class for degree 2 (quadratic polynomials) ...
Definition: Polynomial.h:183
LinearMotion< T > secondHalf() const
Definition: LinearMotionArithmetic-inl.h:156
IntervalND< T, N > operator*(const LinearMotionND< T, N > &m) const
Standard arithmetic operators extended to interval groups.
Definition: LinearMotionArithmetic-inl.h:286
T getStart() const
Definition: LinearMotionArithmetic-inl.h:132
bool containsZero() const
Definition: LinearMotionArithmetic-inl.h:68
LinearMotionND< T, N > operator+(const LinearMotionND< T, N > &m) const
Definition: LinearMotionArithmetic-inl.h:250
void getStart(std::array< T, N > *start) const
Definition: LinearMotionArithmetic-inl.h:316
LinearMotionND< T, N > & operator=(const LinearMotionND< T, N > &motion)
Assignment operator.
Definition: LinearMotionArithmetic-inl.h:195
Interval< T > operator/(const LinearMotion< T > &m) const
Standard arithmetic operators extended to interval groups.
Definition: LinearMotionArithmetic-inl.h:126
LinearMotion< T > & operator=(const LinearMotion< T > &m)
Assignment operator.
Definition: LinearMotionArithmetic-inl.h:40
Eigen::Matrix< T, 3, 1 > Vector3
Typedef for a vector 3 return.
Definition: LinearMotionArithmetic.h:262
bool operator!=(const LinearMotion< T > &m) const
Definition: LinearMotionArithmetic-inl.h:86
const LinearMotion< T > & getAxis(int i) const
Definition: LinearMotionArithmetic-inl.h:309
LinearMotion()
Constructor.
Definition: LinearMotionArithmetic-inl.h:25
Interval defines the concept of a mathematical interval and provides operations on it including arith...
Definition: IntervalArithmetic.h:34
Interval< T > operator*(const LinearMotion< T > &m) const
Standard arithmetic operators extended to interval groups.
Definition: LinearMotionArithmetic-inl.h:120
LinearMotion< T > operator+(const LinearMotion< T > &m) const
Definition: LinearMotionArithmetic-inl.h:92
Interval< T > toInterval() const
Convert from LinearMotion to an Interval.
Definition: LinearMotionArithmetic-inl.h:56
LinearMotionND<T, N> defines the concept of a group of linear motions and provides operations on them...
Definition: LinearMotionArithmetic.h:156
Polynomial< T, 1 > toPolynomial() const
Returns a linear expression (degree-1 polynomial) whose value for t=0..1 progresses from `start' to `...
Definition: LinearMotionArithmetic-inl.h:62
Polynomial<T, 1> specializes the Polynomial class for degree 1 (linear polynomials) ...
Definition: Polynomial.h:117
T atTime(const T &t) const
Definition: LinearMotionArithmetic-inl.h:144
bool operator==(const LinearMotion< T > &m) const
Definition: LinearMotionArithmetic-inl.h:80
LinearMotionND< T, N > firstHalf() const
Definition: LinearMotionArithmetic-inl.h:334
LinearMotion is (intentionally) a lot like Interval, but it deals with linear motion where all operan...
Definition: LinearMotionArithmetic.h:50
IntervalND< T, N > toInterval() const
Convert from LinearMotion to an Interval.
Definition: LinearMotionArithmetic-inl.h:213
bool operator==(const LinearMotionND< T, N > &motion) const
Definition: LinearMotionArithmetic-inl.h:238
bool operator!=(const LinearMotionND< T, N > &motion) const
Definition: LinearMotionArithmetic-inl.h:244
static Interval< T > minToMax(const T &a1, const T &a2)
Generate an interval from min to max based on the inputs.
Definition: IntervalArithmetic-inl.h:62