PolynomialRoots.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_MATH_POLYNOMIALROOTS_H
#define SURGSIM_MATH_POLYNOMIALROOTS_H
#include <iostream>
#include <algorithm>
#include "SurgSim/Math/Polynomial.h"
namespace SurgSim
{
namespace Math
{
template <typename T, int N> class PolynomialRoots;
template <typename T, int N>
class PolynomialRootsCommon
{
public:
static const int DEGENERATE = -1;
bool isDegenerate() const;
int getNumRoots() const;
T operator[](int i) const;
private:
PolynomialRootsCommon(const PolynomialRootsCommon&);
PolynomialRootsCommon& operator=(const PolynomialRootsCommon&);
protected:
PolynomialRootsCommon() {}
int m_numRoots;
std::array<T, N> m_roots;
};
template <typename T>
class PolynomialRoots<T, 1> : public PolynomialRootsCommon<T, 1>
{
public:
explicit PolynomialRoots(const Polynomial<T, 1>& p, const T& epsilon = 1.0e-09);
};
template <typename T>
class PolynomialRoots<T, 2> : public PolynomialRootsCommon<T, 2>
{
public:
explicit PolynomialRoots(const Polynomial<T, 2>& p, const T& epsilon = 1.0e-09);
};
template <typename T, int N>
void solve(const T& a, const T& b, const T& epsilon, int* numRoots, std::array<T, N>* roots);
template <typename T, int N>
void solve(const T& a, const T& b, const T& c, const T& epsilon, int* numRoots, std::array<T, N>* roots);
}; // Math
}; // SurgSim
#include "SurgSim/Math/PolynomialRoots-inl.h"
#endif // SURGSIM_MATH_POLYNOMIALROOTS_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Math::PolynomialRootsCommon::getNumRoots
int getNumRoots() const
Definition: PolynomialRoots-inl.h:32
SurgSim::Math::PolynomialRootsCommon::m_roots
std::array< T, N > m_roots
An array of up to N roots for a degree N polynomial ordered ascendingly.
Definition: PolynomialRoots.h:78
SurgSim::Math::PolynomialRootsCommon::operator=
PolynomialRootsCommon & operator=(const PolynomialRootsCommon &)
SurgSim::Math::PolynomialRootsCommon::PolynomialRootsCommon
PolynomialRootsCommon()
Constructor. Since the constructor must define the roots, only allow construction from a derived clas...
Definition: PolynomialRoots.h:72
Polynomial.h
SurgSim::Math::PolynomialRootsCommon::DEGENERATE
static const int DEGENERATE
Indicator for a degenerate polynomial (infinite number of roots).
Definition: PolynomialRoots.h:48
SurgSim::Math::Polynomial< T, 2 >
Polynomial<T, 2> specializes the Polynomial class for degree 2 (quadratic polynomials) ...
Definition: Polynomial.h:183
SurgSim::Math::PolynomialRoots
The (algebraic) roots of a Polynomial<N,T>.
Definition: PolynomialRoots.h:36
SurgSim::Math::PolynomialRootsCommon::operator[]
T operator[](int i) const
Read only access to the roots of the polynomial.
Definition: PolynomialRoots-inl.h:38
SurgSim::Math::PolynomialRootsCommon::isDegenerate
bool isDegenerate() const
Definition: PolynomialRoots-inl.h:26
PolynomialRoots-inl.h
SurgSim::Math::solve
void solve(const T &a, const T &b, const T &epsilon, int *numRoots, std::array< T, N > *roots)
Specialized solve routine for linear polynomials (2 coefficients)
Definition: PolynomialRoots-inl.h:64
SurgSim::Math::PolynomialRootsCommon::m_numRoots
int m_numRoots
The number of roots available for the polynomial, or DEGENERATE if there are infinite roots...
Definition: PolynomialRoots.h:75
SurgSim::Math::Polynomial< T, 1 >
Polynomial<T, 1> specializes the Polynomial class for degree 1 (linear polynomials) ...
Definition: Polynomial.h:117
SurgSim::Math::PolynomialRootsCommon
The common base class for PolynomialRoots specializations for various N.
Definition: PolynomialRoots.h:44