PolynomialValues-inl.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_MATH_POLYNOMIALVALUES_INL_H
17 #define SURGSIM_MATH_POLYNOMIALVALUES_INL_H
18 
19 namespace SurgSim
20 {
21 namespace Math
22 {
23 
24 template <class T>
26 {
27 }
28 
29 template <class T>
31 {
32  return m_polynomial;
33 }
34 
35 template <class T>
37 {
38  return Interval<T>(m_polynomial.evaluate(0), m_polynomial.evaluate(0));
39 }
40 
41 template <class T>
43 
44 template <class T>
46 {
47  return m_polynomial;
48 }
49 
50 template <class T>
52 {
53  return Interval<T>::minToMax(m_polynomial.evaluate(interval.getMin()),
54  m_polynomial.evaluate(interval.getMax()));
55 }
56 
57 template <class T>
59  m_derivative(m_polynomial.derivative()),
60  m_locationOfExtremum(m_derivative)
61 {
62 }
63 
64 template <class T>
66 {
67  return m_polynomial;
68 }
69 
70 template <class T>
72 {
73  return m_derivative;
74 }
75 
76 template <class T>
78 {
79  return m_locationOfExtremum;
80 }
81 
82 template <class T>
84 {
85  // Always consider the endpoints.
86  Interval<T> result = Interval<T>::minToMax(m_polynomial.evaluate(interval.getMin()),
87  m_polynomial.evaluate(interval.getMax()));
88 
89  if (m_locationOfExtremum.getNumRoots() > 0)
90  {
91  // There is an extremum (min or max)...
92  if (interval.contains(m_locationOfExtremum[0]))
93  {
94  //...and it occurs somewhere in the middle of the interval.
95  // The value at the extremum needs to be made a part of the result interval.
96  result.extendToInclude(m_polynomial.evaluate(m_locationOfExtremum[0]));
97  }
98  }
99  return result;
100 }
101 
102 template <class T>
104  m_derivative(m_polynomial.derivative()),
105  m_locationOfExtremum(m_derivative)
106 {
107 }
108 
109 template <class T>
111 {
112  return m_polynomial;
113 }
114 
115 template <class T>
117 {
118  return m_derivative;
119 }
120 
121 template <class T>
123 {
124  return m_locationOfExtremum;
125 }
126 
127 template <class T>
129 {
130  // Always consider the endpoints.
131  Interval<T> result = Interval<T>::minToMax(m_polynomial.evaluate(interval.getMin()),
132  m_polynomial.evaluate(interval.getMax()));
133 
134  for (int i = 0; i < m_locationOfExtremum.getNumRoots(); ++i)
135  {
136  // There is an extremum (min or max)...
137  if (interval.contains(m_locationOfExtremum[i]))
138  {
139  //...and it occurs somewhere in the middle of the interval.
140  // The value at the extremum needs to be made a part of the result interval.
141  result.extendToInclude(m_polynomial.evaluate(m_locationOfExtremum[i]));
142  }
143  }
144  return result;
145 }
146 
147 template <class T, int N>
149 {
150  return PolynomialValues<T, N>(p).valuesOverInterval(interval);
151 }
152 
153 }; // Math
154 }; // SurgSim
155 
156 #endif // SURGSIM_MATH_POLYNOMIALVALUES_INL_H
SurgSim::Math::valuesOverInterval
Interval< T > valuesOverInterval(const Polynomial< T, N > &p, const Interval< T > &interval)
Calculate the minimum and maximum values of the dependent variable over a specified range of the inde...
Definition: PolynomialValues-inl.h:148
SurgSim::Math::Polynomial< T, 0 >
Polynomial<T, 0> specializes the Polynomial class for degree 0 (constant polynomials)
Definition: Polynomial.h:56
SurgSim::Math::Interval::getMax
T getMax() const
Definition: IntervalArithmetic-inl.h:289
SurgSim::Math::PolynomialRoots< T, 1 >
PolynomialRoots<T, 1> specializes the PolynomialRoots class for degree 1 (linear polynomials)
Definition: PolynomialRoots.h:84
SurgSim::Math::PolynomialRoots< T, 2 >
PolynomialRoots<T, 2> specializes the PolynomialRoots class for degree 2 (quadratic polynomials)
Definition: PolynomialRoots.h:96
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Math::PolynomialValues
Class to manage polynomial based calculations of interval boundaries.
Definition: PolynomialValues.h:33
SurgSim::Math::Polynomial
Polynomial<T, N> defines the concept of an N degree polynomial with type T coefficients and provides ...
Definition: Polynomial.h:47
SurgSim::Math::Interval
Interval defines the concept of a mathematical interval and provides operations on it including arith...
Definition: IntervalArithmetic.h:34
SurgSim::Math::Polynomial< T, 1 >
Polynomial<T, 1> specializes the Polynomial class for degree 1 (linear polynomials)
Definition: Polynomial.h:117
SurgSim::Math::Interval::minToMax
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
SurgSim::Math::Interval::getMin
T getMin() const
Definition: IntervalArithmetic-inl.h:283
SurgSim::Math::Polynomial< T, 3 >
Polynomial<T, 3> specializes the Polynomial class for degree 3 (cubic polynomials)
Definition: Polynomial.h:255
SurgSim::Math::Interval::extendToInclude
Interval< T > & extendToInclude(const T &x)
Widens the current interval on one end to include x.
Definition: IntervalArithmetic-inl.h:130
SurgSim::Math::Interval::contains
bool contains(const T &val) const
Definition: IntervalArithmetic-inl.h:92
SurgSim::Math::Polynomial< T, 2 >
Polynomial<T, 2> specializes the Polynomial class for degree 2 (quadratic polynomials)
Definition: Polynomial.h:183