00001 // Linear_Interpolator.h - a piecewise-linear interpolator. 00002 // 00003 // Vamos Automotive Simulator 00004 // Copyright (C) 2003 Sam Varner 00005 // 00006 // This program is free software; you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation; either version 2 of the License, or 00009 // (at your option) any later version. 00010 // 00011 // This program is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with this program; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 #ifndef _LINEAR_INTERPOLATOR_H_ 00021 #define _LINEAR_INTERPOLATOR_H_ 00022 00023 #include <vamos/geometry/Interpolator.h> 00024 #include <vamos/geometry/Two_Point.h> 00025 #include <vector> 00026 00027 namespace Vamos_Geometry 00028 { 00029 class Linear_Interpolator : public Interpolator 00030 { 00031 std::vector <Two_Point> m_points; 00032 00033 mutable double m_delta_x; 00034 mutable double m_delta_y; 00035 00036 public: 00037 // Construct an empty curve. 00038 Linear_Interpolator (); 00039 00040 // Construct a cuvre from an array of points. 00041 Linear_Interpolator (const std::vector <Two_Point>& points); 00042 00043 // Add a point to the curve. 00044 void load (const Two_Point& point); 00045 00046 // Add multiple points to the curve. 00047 void load (const std::vector <Two_Point>& points); 00048 00049 // Remove all points from the curve. 00050 void clear (); 00051 00052 // Remove points with x > LIMIT. 00053 void remove_greater (double limit); 00054 00055 // Scale all of the x values by FACTOR. 00056 void scale (double factor); 00057 00058 // Return the y value at the x value DIST 00059 double interpolate (double dist) const; 00060 00061 // Return the normal to the tanget at DIST. 00062 Two_Point normal (double dist) const; 00063 }; 00064 } 00065 00066 #endif
1.4.6