From b150ea2a0d8288506df7faee198ccbb5d5ed6148 Mon Sep 17 00:00:00 2001 From: Vesa Date: Sun, 13 Apr 2014 10:34:38 +0300 Subject: [PATCH] Add some fancy new interpolation algorithms --- include/interpolation.h | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/include/interpolation.h b/include/interpolation.h index 0ca1d4e06..e58be7be3 100644 --- a/include/interpolation.h +++ b/include/interpolation.h @@ -101,4 +101,50 @@ inline float linearInterpolate( float v0, float v1, float x ) } +inline float optimalInterpolate( float v0, float v1, float x ) +{ + const float z = x - 0.5f; + const float even = v1 + v0; + const float odd = v1 - v0; + + const float c0 = even * 0.50037842517188658; + const float c1 = odd * 1.00621089801788210; + const float c2 = even * -0.004541102062639801; + const float c3 = odd * -1.57015627178718420; + + return ( ( c3*z + c2 ) * z + c1 ) * z + c0; +} + + +inline float optimal4pInterpolate( float v0, float v1, float v2, float v3, float x ) +{ + const float z = x - 0.5f; + const float even1 = v2 + v1; + const float odd1 = v2 - v1; + const float even2 = v3 + v0; + const float odd2 = v3 - v0; + + const float c0 = even1 * 0.45868970870461956 + even2 * 0.04131401926395584; + const float c1 = odd1 * 0.48068024766578432 + odd2 * 0.17577925564495955; + const float c2 = even1 * -0.246185007019907091 + even2 * 0.24614027139700284; + const float c3 = odd1 * -0.36030925263849456 + odd2 * 0.10174985775982505; + + return ( ( c3*z + c2 ) * z + c1 ) * z + c0; +} + + + +inline float lagrangeInterpolate( float v0, float v1, float v2, float v3, float x ) +{ + const float c0 = v1; + const float c1 = v2 - v0 * ( 1.0f / 3.0f ) - v1 * 0.5f - v3 * ( 1.0f / 6.0f ); + const float c2 = 0.5f * (v0 + v2) - v1; + const float c3 = ( 1.0f/6.0f ) * ( v3 - v0 ) + 0.5f * ( v1 - v2 ); + return ( ( c3*x + c2 ) * x + c1 ) * x + c0; +} + + + + + #endif