Wm4Polynomial1.h

Go to the documentation of this file.
00001 // Wild Magic Source Code
00002 // David Eberly
00003 // http://www.geometrictools.com
00004 // Copyright (c) 1998-2007
00005 //
00006 // This library is free software; you can redistribute it and/or modify it
00007 // under the terms of the GNU Lesser General Public License as published by
00008 // the Free Software Foundation; either version 2.1 of the License, or (at
00009 // your option) any later version.  The license is available for reading at
00010 // either of the locations:
00011 //     http://www.gnu.org/copyleft/lgpl.html
00012 //     http://www.geometrictools.com/License/WildMagicLicense.pdf
00013 // The license applies to versions 0 through 4 of Wild Magic.
00014 //
00015 // Version: 4.0.0 (2006/06/28)
00016 
00017 #ifndef WM4POLYNOMIAL1_H
00018 #define WM4POLYNOMIAL1_H
00019 
00020 #include "Wm4FoundationLIB.h"
00021 #include "Wm4Math.h"
00022 
00023 namespace Wm4
00024 {
00025 
00026 template <class Real>
00027 class Polynomial1
00028 {
00029 public:
00030     // construction and destruction
00031     Polynomial1 (int iDegree = -1);
00032     Polynomial1 (const Polynomial1& rkPoly);
00033     ~Polynomial1 ();
00034 
00035     // member access
00036     void SetDegree (int iDegree);
00037     int GetDegree () const;
00038     operator const Real* () const;
00039     operator Real* ();
00040     Real operator[] (int i) const;
00041     Real& operator[] (int i);
00042 
00043     // assignment
00044     Polynomial1& operator= (const Polynomial1& rkPoly);
00045 
00046     // evaluation
00047     Real operator() (Real fT) const;
00048 
00049     // arithmetic operations
00050     Polynomial1 operator+ (const Polynomial1& rkPoly) const;
00051     Polynomial1 operator- (const Polynomial1& rkPoly) const;
00052     Polynomial1 operator* (const Polynomial1& rkPoly) const;
00053     Polynomial1 operator+ (Real fScalar) const;  // input is degree 0 poly
00054     Polynomial1 operator- (Real fScalar) const;  // input is degree 0 poly
00055     Polynomial1 operator* (Real fScalar) const;
00056     Polynomial1 operator/ (Real fScalar) const;
00057     Polynomial1 operator- () const;
00058 
00059     // arithmetic updates
00060     Polynomial1& operator += (const Polynomial1& rkPoly);
00061     Polynomial1& operator -= (const Polynomial1& rkPoly);
00062     Polynomial1& operator *= (const Polynomial1& rkPoly);
00063     Polynomial1& operator += (Real fScalar);  // input is degree 0 poly
00064     Polynomial1& operator -= (Real fScalar);  // input is degree 0 poly
00065     Polynomial1& operator *= (Real fScalar);
00066     Polynomial1& operator /= (Real fScalar);
00067 
00068     // derivation
00069     Polynomial1 GetDerivative () const;
00070 
00071     // inversion ( invpoly[i] = poly[degree-i] for 0 <= i <= degree )
00072     Polynomial1 GetInversion () const;
00073 
00074     // Reduce degree by eliminating all (nearly) zero leading coefficients
00075     // and by making the leading coefficient one.  The input parameter is
00076     // the threshold for specifying that a coefficient is effectively zero.
00077     void Compress (Real fEpsilon);
00078 
00079     // If 'this' is P(t) and the divisor is D(t) with degree(P) >= degree(D),
00080     // then P(t) = Q(t)*D(t)+R(t) where Q(t) is the quotient with
00081     // degree(Q) = degree(P) - degree(D) and R(t) is the remainder with
00082     // degree(R) < degree(D).  If this routine is called with
00083     // degree(P) < degree(D), then Q = 0 and R = P are returned.  The value
00084     // of epsilon is used as a threshold on the coefficients of the remainder
00085     // polynomial.  If smaller, the coefficient is assumed to be zero.
00086     void Divide (const Polynomial1& rkDiv, Polynomial1& rkQuot,
00087         Polynomial1& rkRem, Real fEpsilon) const;
00088 
00089 protected:
00090     int m_iDegree;
00091     Real* m_afCoeff;
00092 };
00093 
00094 template <class Real>
00095 Polynomial1<Real> operator* (Real fScalar, const Polynomial1<Real>& rkPoly);
00096 
00097 } // namespace Wm4
00098 
00099 #include "Wm4Polynomial1.inl"
00100 
00101 namespace Wm4
00102 {
00103 typedef Polynomial1<float> Polynomial1f;
00104 typedef Polynomial1<double> Polynomial1d;
00105 }
00106 
00107 #endif

Generated on Wed Nov 23 19:01:06 2011 for FreeCAD by  doxygen 1.6.1