00001 00002 /*************************************************************************** 00003 * linear.cpp - Linear interpolator 00004 * 00005 * Created: Tue Nov 18 11:13:13 2008 00006 * Copyright 2008 Tim Niemueller [www.niemueller.de] 00007 * 2008 Graeme McPhillips 00008 * 00009 ****************************************************************************/ 00010 00011 /* This program is free software; you can redistribute it and/or modify 00012 * it under the terms of the GNU General Public License as published by 00013 * the Free Software Foundation; either version 2 of the License, or 00014 * (at your option) any later version. A runtime exception applies to 00015 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00016 * 00017 * This program is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU Library General Public License for more details. 00021 * 00022 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00023 */ 00024 00025 #include <utils/math/interpolation/linear.h> 00026 00027 namespace fawkes { 00028 #if 0 /* just to make Emacs auto-indent happy */ 00029 } 00030 #endif 00031 00032 /** @class LinearInterpolator <utils/math/interpolation/linear.h> 00033 * Linear value interpolator. 00034 * The interpolator creates intermediate points given a starting and and 00035 * end point and time constraints. Times are supplied in a discrete unit like 00036 * miliseconds or microseconds. 00037 * The values are interpolated on a straight line between the starting and the 00038 * end point. 00039 * 00040 * The calculation is executed with the following equation: 00041 * \f[ 00042 * \frac{t_\mathrm{current}}{t_\mathrm{end}} \cdot (v_\mathrm{end} - v_\mathrm{start}) + v_\mathrm{start} 00043 * \f] 00044 * 00045 * @author Tim Niemueller 00046 * @author Graeme McPhillips 00047 * @author Stephen Marais 00048 */ 00049 00050 float 00051 LinearInterpolator::interpolate(float t_current, float t_end, float t_step, 00052 float v_start, float v_end) 00053 { 00054 return (t_current / t_end) * (v_end - v_start) + v_start; 00055 } 00056 00057 00058 } // end namespace fawkes 00059