libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo is the group of objects and functions that executes the basic operations of Moldeo 1.0 Platform.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
moMathPolynomial.h
Go to the documentation of this file.
1 /*******************************************************************************
2 
3  moMathPolynomial.h
4 
5  ****************************************************************************
6  * *
7  * This source is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This code is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15  * General Public License for more details. *
16  * *
17  * A copy of the GNU General Public License is available on the World *
18  * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
19  * obtain it by writing to the Free Software Foundation, *
20  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  * *
22  ****************************************************************************
23 
24  Copyright(C) 2006 Fabricio Costa
25 
26  Authors:
27  Fabricio Costa
28  Andrés Colubri
29 
30  Portions taken from
31  Wild Magic Source Code
32  David Eberly
33  http://www.geometrictools.com
34  Copyright (c) 1998-2007
35 
36 *******************************************************************************/
37 
38 #include "moMath.h"
39 
40 #ifndef __MO_MATH_POLYNOMIAL_H__
41 #define __MO_MATH_POLYNOMIAL_H__
42 
43 template <class Real>
45 {
46 public:
47  // construction and destruction
48  moPolynomial1 (int iDegree = -1);
49  moPolynomial1 (const moPolynomial1& rkPoly);
50  ~moPolynomial1 ();
51 
52  // member access
53  void SetDegree (int iDegree);
54  int GetDegree () const;
55  operator const Real* () const;
56  operator Real* ();
57  Real operator[] (int i) const;
58  Real& operator[] (int i);
59 
60  // assignment
61  moPolynomial1& operator= (const moPolynomial1& rkPoly);
62 
63  // evaluation
64  Real operator() (Real fT) const;
65 
66  // arithmetic operations
67  moPolynomial1 operator+ (const moPolynomial1& rkPoly) const;
68  moPolynomial1 operator- (const moPolynomial1& rkPoly) const;
69  moPolynomial1 operator* (const moPolynomial1& rkPoly) const;
70  moPolynomial1 operator+ (Real fScalar) const; // input is degree 0 poly
71  moPolynomial1 operator- (Real fScalar) const; // input is degree 0 poly
72  moPolynomial1 operator* (Real fScalar) const;
73  moPolynomial1 operator/ (Real fScalar) const;
74  moPolynomial1 operator- () const;
75 
76  // arithmetic updates
80  moPolynomial1& operator += (Real fScalar); // input is degree 0 poly
81  moPolynomial1& operator -= (Real fScalar); // input is degree 0 poly
82  moPolynomial1& operator *= (Real fScalar);
83  moPolynomial1& operator /= (Real fScalar);
84 
85  // derivation
86  moPolynomial1 GetDerivative () const;
87 
88  // inversion ( invpoly[i] = poly[degree-i] for 0 <= i <= degree )
89  moPolynomial1 GetInversion () const;
90 
91  // Reduce degree by eliminating all (nearly) zero leading coefficients
92  // and by making the leading coefficient one. The input parameter is
93  // the threshold for specifying that a coefficient is effectively zero.
94  void Compress (Real fEpsilon);
95 
96  // If 'this' is P(t) and the divisor is D(t) with degree(P) >= degree(D),
97  // then P(t) = Q(t)*D(t)+R(t) where Q(t) is the quotient with
98  // degree(Q) = degree(P) - degree(D) and R(t) is the remainder with
99  // degree(R) < degree(D). If this routine is called with
100  // degree(P) < degree(D), then Q = 0 and R = P are returned. The value
101  // of epsilon is used as a threshold on the coefficients of the remainder
102  // polynomial. If smaller, the coefficient is assumed to be zero.
103  void Divide (const moPolynomial1& rkDiv, moPolynomial1& rkQuot,
104  moPolynomial1& rkRem, Real fEpsilon) const;
105 
106 protected:
108  Real* m_afCoeff;
109 };
110 
111 template <class Real>
113 {
114  moPolynomial1<Real> kProd(rkPoly.GetDegree());
115  for (int i = 0; i <= rkPoly.GetDegree(); i++)
116  {
117  kProd[i] = fScalar*rkPoly[i];
118  }
119 
120  return kProd;
121 }
122 
123 #ifndef MO_MACOSX
124 #ifndef MO_RASPBIAN
125 #ifndef MO_WIN32
128 #endif
129 #endif
130 #endif
131 
132 typedef moPolynomial1<MOfloat> moPolynomial1f;
133 typedef moPolynomial1<MOdouble> moPolynomial1d;
134 
135 #endif
136 
moPolynomial1< MOdouble > moPolynomial1d
moMatrix3 operator-(const moMatrix3 &rkM) const
moMatrix3 operator/(Real fScalar) const
Clase base abstracta de donde deben derivar los objetos [virtual pura].
Definition: moAbstract.h:191
#define LIBMOLDEO_API
Definition: moTypes.h:180
int GetDegree() const
moMatrix3 & operator-=(const moMatrix3 &rkM)
moPolynomial1< Real > operator*(Real fScalar, const moPolynomial1< Real > &rkPoly)
moPolynomial1< MOfloat > moPolynomial1f
moMatrix3 & operator/=(Real fScalar)
moMatrix3 & operator*=(Real fScalar)
moMatrix3 & operator=(const moMatrix3 &rkM)
Real operator()(int iRow, int iCol) const
moMatrix3 operator+(const moMatrix3 &rkM) const
moMatrix3 & operator+=(const moMatrix3 &rkM)
const Real * operator[](int iRow) const