17 #ifndef AGXCOLLIDE_POLYNOMIAL_H 18 #define AGXCOLLIDE_POLYNOMIAL_H 82 m_coefficients = coefficients;
91 switch(m_coefficients.
size()) {
97 intervalStart, intervalEnd, rootsMinor );
114 switch (m_coefficients.
size()) {
124 intervalStart, intervalEnd, rootsMinor );
132 for (
size_t i = 1; i < m_coefficients.
size(); ++i)
133 coefficientsWithoutLeading.push_back( m_coefficients[i] );
134 Polynomial<N - 1> withoutLeadingCoefficient( coefficientsWithoutLeading );
136 withoutLeadingCoefficient.findRealRootsInInterval( intervalStart, intervalEnd, rootsMinor );
143 polyDer.findRealRootsInInterval( intervalStart, intervalEnd, rootsOfDerivative );
147 intervalBorders.
push_back( intervalStart );
148 if (rootsOfDerivative.size() > 0) {
149 intervalBorders.
push_back( rootsOfDerivative[0] );
150 for (
size_t i = 1; i < rootsOfDerivative.size(); ++i) {
151 if (!
agx::equalsZero( rootsOfDerivative[i] - rootsOfDerivative[i - 1] ))
152 intervalBorders.
push_back( rootsOfDerivative[i] );
155 intervalBorders.
push_back( intervalEnd );
159 const size_t maxIter = 50;
161 for (
size_t intervalNr = 0; intervalNr < intervalBorders.
size() - 1; intervalNr++) {
162 const agx::Real localMin = intervalBorders[intervalNr];
163 const agx::Real localMax = intervalBorders[intervalNr + 1];
164 const agx::Real localEps =
std::min(eps, (localMax - localMin) * 0.001);
171 agx::Real fAtMin =
evaluateAt( localMin + localEps);
172 agx::Real fAtMax =
evaluateAt( localMax - localEps);
174 agx::Real xTmp =
agx::Real(0.5) * (localMin + localMax);
176 size_t localIter = 0;
178 agx::Real fPrevious = f;
179 agx::Real factor = 1.0;
181 agx::Real df = polyDer.evaluateAt( xTmp );
182 xTmp -= factor * f/df;
183 xTmp =
agx::clamp(xTmp, localMin + localEps, localMax - localEps);
206 for (
int i = 0; i < int(m_coefficients.
size()) - 1; ++i)
207 deriveCoefficients.push_back( (agx::Real)(m_coefficients.
size() - 1 - i) * m_coefficients[i] );
209 return Polynomial<N - 1>( deriveCoefficients );
218 for (
size_t i = 0; i < m_coefficients.
size(); ++i)
219 polyVal = m_coefficients[i] + polyVal * x;
235 if (xTmp >= intervalStart && xTmp <= intervalEnd)
261 if (xTmp >= intervalStart && xTmp <= intervalEnd)
269 if (xTmp >= intervalStart && xTmp <= intervalEnd)
272 if (xTmp2 >= intervalStart && xTmp2 <= intervalEnd)
282 #endif // AGXCOLLIDE_POLYNOMIAL_H static void findRootsOfQuadraticInInterval(const agx::Real a, const agx::Real b, const agx::Real c, const agx::Real intervalStart, const agx::Real intervalEnd, agx::StackArray< agx::Real, 2 > &roots)
Solves quadratic function a x^2 + bx + c, returns only agx::Real solutions within time interval...
Vec3T< T > min(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
This namespace consists of a set of classes for handling geometric intersection tests including boole...
bool geq(double a, double b, double eps=(double) AGX_EQUIVALENT_EPSILON)
Polynomial(const agx::StackArray< agx::Real, N > &coefficients)
Constructor: creates a Polynomial with given coefficients.
AGXCORE_EXPORT const Real REAL_SQRT_EPSILON
void push_back(const T &value)
AGXPHYSICS_EXPORT agx::Bool equivalent(const agx::AddedMassInteraction::Matrix6x6 &lhs, const agx::AddedMassInteraction::Matrix6x6 &rhs, agx::Real eps=agx::RealEpsilon)
size_t size() const
Get the size of the array (number of filled slots).
T absolute(T v)
return the absolute value.
T1 clamp(T1 v, T2 minimum, T3 maximum)
void findRealRootsInInterval(const agx::Real intervalStart, const agx::Real intervalEnd, agx::StackArray< agx::Real, N - 1 > &roots) const
Calculates agx::Real roots of a single variable polynomial within a given boundary.
AGXPHYSICS_EXPORT agx::Bool equalsZero(const agx::AddedMassInteraction::Matrix6x6 &matrix, agx::Real eps=agx::RealEpsilon)
AGXCORE_EXPORT Component * root()
static void findRootsOfLinearInInterval(const agx::Real a, const agx::Real b, const agx::Real intervalStart, const agx::Real intervalEnd, agx::StackArray< agx::Real, 1 > &root)
Solves linear function ax + b = 0; returns only agx::Real solutions within given interval Assume it h...
agx::Real evaluateAt(const agx::Real x) const
Evaluates polynomial given by polyCoefficients at value x.
Polynomial< N-1 > derive() const
Calculates derivation of a polygon.