Fawkes API  Fawkes Development Version
linear.cpp
1 
2 /***************************************************************************
3  * linear.cpp - Linear interpolator
4  *
5  * Created: Tue Nov 18 11:13:13 2008
6  * Copyright 2008 Tim Niemueller [www.niemueller.de]
7  * 2008 Graeme McPhillips
8  *
9  ****************************************************************************/
10 
11 /* This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version. A runtime exception applies to
15  * this software (see LICENSE.GPL_WRE file mentioned below for details).
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Library General Public License for more details.
21  *
22  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
23  */
24 
25 #include <utils/math/interpolation/linear.h>
26 
27 namespace fawkes {
28 #if 0 /* just to make Emacs auto-indent happy */
29 }
30 #endif
31 
32 /** @class LinearInterpolator <utils/math/interpolation/linear.h>
33  * Linear value interpolator.
34  * The interpolator creates intermediate points given a starting and and
35  * end point and time constraints. Times are supplied in a discrete unit like
36  * miliseconds or microseconds.
37  * The values are interpolated on a straight line between the starting and the
38  * end point.
39  *
40  * The calculation is executed with the following equation:
41  * \f[
42  * \frac{t_\mathrm{current}}{t_\mathrm{end}} \cdot (v_\mathrm{end} - v_\mathrm{start}) + v_\mathrm{start}
43  * \f]
44  *
45  * @author Tim Niemueller
46  * @author Graeme McPhillips
47  * @author Stephen Marais
48  */
49 
50 float
51 LinearInterpolator::interpolate(float t_current, float t_end, float t_step,
52  float v_start, float v_end)
53 {
54  return (t_current / t_end) * (v_end - v_start) + v_start;
55 }
56 
57 
58 } // end namespace fawkes
59 
Fawkes library namespace.
virtual float interpolate(float t_current, float t_end, float t_step, float v_start, float v_end)
Interpolate a point at a specific time.
Definition: linear.cpp:51