polynomial.h
Go to the documentation of this file.
00001 /* -*- mode: C++ -*-
00002  *
00003  *  Description: Polynomial class
00004  *
00005  *  Copyright (C) 2009 Austin Robot Technology                    
00006  *  License: Modified BSD Software License Agreement
00007  *
00008  *  $Id: polynomial.h 630 2010-09-25 16:20:42Z jack.oquin $
00009  */
00010 
00011 #ifndef _POLYNOMIAL_HH_
00012 #define _POLYNOMIAL_HH_
00013 
00019 #include <math.h>
00020 #include <vector>
00021 
00022 
00023 #define POLYNOMIAL_NAME_SIZE 32
00024 
00026 class Polynomial
00027 {
00028  public:
00029 
00033   Polynomial(const char *pname)
00034     {
00035       strncpy(name, pname, sizeof(name));
00036       coef.clear();
00037     }
00038 
00039   virtual ~Polynomial() {};
00040 
00046   void inline add_coef(float term)
00047   {
00048     coef.push_back(term);
00049   }
00050 
00051 #if 0
00052 
00053   void inline configure()
00054   {
00055     unsigned len = cf->GetTupleCount(section, name);
00056     if (len > 0)                        // tuple defined
00057       {
00058         coef.clear();
00059         for (unsigned i = 0; i < len; ++i)
00060           {
00061             float val = cf->ReadTupleFloat(section, name, i, 0.0);
00062             coef.push_back(val);
00063           }
00064       }
00065 
00066     // log the coefficients
00067     for (unsigned i = 0; i < coef.size(); ++i)
00068       ROS_INFO("Polynomial constructor: %s[%d] = %.7f", name, i, coef.at(i));
00069   };
00070 #endif
00071 
00075   float inline value(const float x)
00076   {
00077     float retval = 0.0;
00078     float pow = 1.0;
00079     for (unsigned i = 0; i < coef.size(); ++i)
00080       {
00081         retval += pow * coef.at(i);
00082         pow *= x;
00083       }
00084     return retval;
00085   }
00086 
00087   // coef[i] applies to the x**i term
00088   std::vector<float> coef;             
00090 protected:
00091 
00092   char name[POLYNOMIAL_NAME_SIZE];      
00094 };
00095 
00096 #endif // _POLYNOMIAL_HH_ //


art_common
Author(s): Austin Robot Technology
autogenerated on Fri Jan 3 2014 11:08:22