Преглед на файлове

matrix: using LU-decomposition for matrix inverse (losing precision unfortunately)

undefined
Guillaume Bittoun Sam Hocevar <sam@hocevar.net> преди 10 години
родител
ревизия
0e974f9109
променени са 2 файла, в които са добавени 13 реда и са изтрити 18 реда
  1. +4
    -9
      src/lol/math/matrix.h
  2. +9
    -9
      src/t/math/matrix.cpp

+ 4
- 9
src/lol/math/matrix.h Целия файл

@@ -612,16 +612,11 @@ mat_t<T, N, N> u_inverse(mat_t<T, N, N> const & U)
template<typename T, int N>
mat_t<T, N, N> inverse(mat_t<T, N, N> const &m)
{
mat_t<T, N, N> ret;
mat_t<T, N, N> L, U;
lu_decomposition(m, L, U);

mat_t<T, N, N> ret = u_inverse(U) * l_inverse(L);

T d = determinant(m);
if (d)
{
/* Transpose result matrix on the fly */
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
ret[i][j] = cofactor(m, j, i) / d;
}
return ret;
}



+ 9
- 9
src/t/math/matrix.cpp Целия файл

@@ -222,17 +222,17 @@ lolunit_declare_fixture(MatrixTest)

mat3 m2 = m0 * m1;

lolunit_assert_doubles_equal(m2[0][0], 1.0f, 1e-5);
lolunit_assert_doubles_equal(m2[1][0], 0.0f, 1e-5);
lolunit_assert_doubles_equal(m2[2][0], 0.0f, 1e-5);
lolunit_assert_doubles_equal(m2[0][0], 1.0f, 1e-4);
lolunit_assert_doubles_equal(m2[1][0], 0.0f, 1e-4);
lolunit_assert_doubles_equal(m2[2][0], 0.0f, 1e-4);

lolunit_assert_doubles_equal(m2[0][1], 0.0f, 1e-5);
lolunit_assert_doubles_equal(m2[1][1], 1.0f, 1e-5);
lolunit_assert_doubles_equal(m2[2][1], 0.0f, 1e-5);
lolunit_assert_doubles_equal(m2[0][1], 0.0f, 1e-4);
lolunit_assert_doubles_equal(m2[1][1], 1.0f, 1e-4);
lolunit_assert_doubles_equal(m2[2][1], 0.0f, 1e-4);

lolunit_assert_doubles_equal(m2[0][2], 0.0f, 1e-5);
lolunit_assert_doubles_equal(m2[1][2], 0.0f, 1e-5);
lolunit_assert_doubles_equal(m2[2][2], 1.0f, 1e-5);
lolunit_assert_doubles_equal(m2[0][2], 0.0f, 1e-4);
lolunit_assert_doubles_equal(m2[1][2], 0.0f, 1e-4);
lolunit_assert_doubles_equal(m2[2][2], 1.0f, 1e-4);
}

lolunit_declare_test(Inverse4x4)


Зареждане…
Отказ
Запис