Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Polynomial.h
1 /*
2 Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7 
8 Redistributions of source code must retain the above copyright notice, this list of
9 conditions and the following disclaimer. Redistributions in binary form must reproduce
10 the above copyright notice, this list of conditions and the following disclaimer
11 in the documentation and/or other materials provided with the distribution.
12 
13 Neither the name of the Johns Hopkins University nor the names of its contributors
14 may be used to endorse or promote products derived from this software without specific
15 prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES
19 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
20 SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26 DAMAGE.
27 */
28 
29 #ifndef POLYNOMIAL_INCLUDED
30 #define POLYNOMIAL_INCLUDED
31 
32 #include <vector>
33 
34 template<int Degree>
35 class Polynomial{
36 public:
37  double coefficients[Degree+1];
38 
39  Polynomial(void);
40  template<int Degree2>
42  double operator()( double t ) const;
43  double integral( double tMin , double tMax ) const;
44 
45  int operator == (const Polynomial& p) const;
46  int operator != (const Polynomial& p) const;
47  int isZero(void) const;
48  void setZero(void);
49 
50  template<int Degree2>
51  Polynomial& operator = (const Polynomial<Degree2> &p);
52  Polynomial& operator += (const Polynomial& p);
53  Polynomial& operator -= (const Polynomial& p);
54  Polynomial operator - (void) const;
55  Polynomial operator + (const Polynomial& p) const;
56  Polynomial operator - (const Polynomial& p) const;
57  template<int Degree2>
58  Polynomial<Degree+Degree2> operator * (const Polynomial<Degree2>& p) const;
59 
60  Polynomial& operator += ( double s );
61  Polynomial& operator -= ( double s );
62  Polynomial& operator *= ( double s );
63  Polynomial& operator /= ( double s );
64  Polynomial operator + ( double s ) const;
65  Polynomial operator - ( double s ) const;
66  Polynomial operator * ( double s ) const;
67  Polynomial operator / ( double s ) const;
68 
69  Polynomial scale( double s ) const;
70  Polynomial shift( double t ) const;
71 
72  Polynomial<Degree-1> derivative(void) const;
73  Polynomial<Degree+1> integral(void) const;
74 
75  void printnl(void) const;
76 
77  Polynomial& addScaled(const Polynomial& p,double scale);
78 
79  static void Negate(const Polynomial& in,Polynomial& out);
80  static void Subtract(const Polynomial& p1,const Polynomial& p2,Polynomial& q);
81  static void Scale(const Polynomial& p,double w,Polynomial& q);
82  static void AddScaled(const Polynomial& p1,double w1,const Polynomial& p2,double w2,Polynomial& q);
83  static void AddScaled(const Polynomial& p1,const Polynomial& p2,double w2,Polynomial& q);
84  static void AddScaled(const Polynomial& p1,double w1,const Polynomial& p2,Polynomial& q);
85 
86  void getSolutions(double c,std::vector<double>& roots,double EPS) const;
87 
88  static Polynomial BSplineComponent( int i );
89 };
90 
91 #include "Polynomial.inl"
92 #endif // POLYNOMIAL_INCLUDED