From 06dfb3b0c0273b9f23705877979bdabbb4fef291 Mon Sep 17 00:00:00 2001 From: Guillaume Bittoun Date: Tue, 2 Dec 2014 21:36:56 +0000 Subject: [PATCH] simplex_interpolator: removing tests and correcting skew matrix --- src/lol/math/all.h | 2 -- src/lol/math/simplex_interpolator.h | 32 +++++++++++++++++++++-------- src/t/Makefile.am | 2 +- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/lol/math/all.h b/src/lol/math/all.h index 0a0320dd..a1695a93 100644 --- a/src/lol/math/all.h +++ b/src/lol/math/all.h @@ -22,5 +22,3 @@ #include #include #include -#include - diff --git a/src/lol/math/simplex_interpolator.h b/src/lol/math/simplex_interpolator.h index 97825107..5d5f70b3 100644 --- a/src/lol/math/simplex_interpolator.h +++ b/src/lol/math/simplex_interpolator.h @@ -124,18 +124,32 @@ protected: inline void InitBase() { + /* Matrix coordinate transformation to skew simplex referential is done + by inversing the base matrix M which is written as follows: + + M = | a b b b … | M^(-1) = | c d d d … | + | b a b b … | | d c d d … | + | b b a b … | | d d c d … | + | … | | … | + + where a and b are computed below ↴ + */ + + T b = (1 - sqrt((N+1)))/(N * N * N)); + T a = b + sqrt((N+1)/N); + + // determinant of matrix M + T det = a * (a + (N-2) * b) - (b * b) * (N-1); + + T c = (a + (N-2)*b) / det; + T d = b / det; + for (int i = 0; i < N; ++i) { - for (int j = 0; j < i; ++j) - { - m_base[j][i] = 0; - m_base_inverse[j][i] = 0; - } - - for (int j = i; j < N; ++j) + for (int j = 0; j < N; ++j) { - m_base[j][i] = sqrt((i+2)/((float)(2*i+2))) / (j > i ? i+2 : 1); - m_base_inverse[j][i] = sqrt((2*j+2) / ((float)(j+2))) * (j > i ? (-1 / (float)(j+1)) : 1); + m_base[i][j] = (i == j ? a : b); + m_base_inverse[i][j] = (i == j ? c : d); } } } diff --git a/src/t/Makefile.am b/src/t/Makefile.am index 11755436..e6d91686 100644 --- a/src/t/Makefile.am +++ b/src/t/Makefile.am @@ -20,7 +20,7 @@ test_math_SOURCES = test-common.cpp \ math/array2d.cpp math/array3d.cpp math/arraynd.cpp math/box.cpp \ math/cmplx.cpp math/half.cpp math/interp.cpp math/matrix.cpp \ math/quat.cpp math/rand.cpp math/real.cpp math/rotation.cpp \ - math/trig.cpp math/vector.cpp math/simplex_interpolator.cpp + math/trig.cpp math/vector.cpp test_math_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/tools/lolunit test_math_DEPENDENCIES = @LOL_DEPS@