Kaynağa Gözat

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

undefined
Guillaume Bittoun Sam Hocevar <sam@hocevar.net> 9 yıl önce
ebeveyn
işleme
0e974f9109
2 değiştirilmiş dosya ile 13 ekleme ve 18 silme
  1. +4
    -9
      src/lol/math/matrix.h
  2. +9
    -9
      src/t/math/matrix.cpp

+ 4
- 9
src/lol/math/matrix.h Dosyayı Görüntüle

@@ -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 Dosyayı Görüntüle

@@ -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)


Yükleniyor…
İptal
Kaydet