Fawkes API Fawkes Development Version
sinusoidal.cpp
1
2/***************************************************************************
3 * sinusoidal.cpp - Sinusoidal interpolator
4 *
5 * Created: Tue Nov 18 11:27:44 2008
6 * Copyright 2008 Tim Niemueller [www.niemueller.de]
7 * 2008 Graeme McPhillips
8 * 2008 Stephen Marais
9 *
10 ****************************************************************************/
11
12/* This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version. A runtime exception applies to
16 * this software (see LICENSE.GPL_WRE file mentioned below for details).
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Library General Public License for more details.
22 *
23 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
24 */
25
26#include <utils/math/interpolation/sinusoidal.h>
27
28#include <cmath>
29
30namespace fawkes {
31
32/** @class SinusoidalInterpolator <utils/math/interpolation/linear.h>
33 * Sinusoidal 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 sinusoidal curve with a slow start, the
38 * greatest slope in the middle and then a slow down in the end. This
39 * interpolation is useful for example for smooth servo movements.
40 *
41 * The calculation is executed with the following equation:
42 * \f[
43 * \left(\frac{1}{2} \sin\left(\frac{1}{2} + \frac{t_\mathrm{current}}{t_\mathrm{end}} \pi \right) + \frac{1}{2}\right) \cdot (v_\mathrm{end} - v_\mathrm{start}) + v_\mathrm{start}
44 * \f]
45 *
46 * @author Tim Niemueller
47 * @author Graeme McPhillips
48 * @author Stephen Marais
49 */
50
51float
53 float t_end,
54 float t_step,
55 float v_start,
56 float v_end)
57{
58 return (sin((-0.5 + (t_current / t_end)) * M_PI) / 2.0 + 0.5) * (v_end - v_start) + v_start;
59}
60
61} // end namespace fawkes
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: sinusoidal.cpp:52
Fawkes library namespace.