From 8159718fafc57cfbc9da7f706e599a91caccfa42 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 9 Oct 2015 20:55:15 +0200 Subject: BLI: add SVD solver for mat3 (using eigen3). --- source/blender/blenlib/BLI_math_solvers.h | 1 + source/blender/blenlib/intern/math_solvers.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) (limited to 'source/blender') diff --git a/source/blender/blenlib/BLI_math_solvers.h b/source/blender/blenlib/BLI_math_solvers.h index ec9ba5538e2..810c84cc830 100644 --- a/source/blender/blenlib/BLI_math_solvers.h +++ b/source/blender/blenlib/BLI_math_solvers.h @@ -46,6 +46,7 @@ extern "C" { bool BLI_eigen_solve_selfadjoint_m3(const float m3[3][3], float r_eigen_values[3], float r_eigen_vectors[3][3]); +void BLI_svd_m3(const float m3[3][3], float r_U[3][3], float r_S[], float r_V[3][3]); /**************************** Inline Definitions ******************************/ #if 0 /* None so far. */ diff --git a/source/blender/blenlib/intern/math_solvers.c b/source/blender/blenlib/intern/math_solvers.c index 2f962714c8c..d1dad9a6269 100644 --- a/source/blender/blenlib/intern/math_solvers.c +++ b/source/blender/blenlib/intern/math_solvers.c @@ -59,3 +59,16 @@ bool BLI_eigen_solve_selfadjoint_m3(const float m3[3][3], float r_eigen_values[3 return EG3_self_adjoint_eigen_solve(3, (const float *)m3, r_eigen_values, (float *)r_eigen_vectors); } + +/** + * \brief Compute the SVD (Singular Values Decomposition) of given 3D matrix (m3 = USV*). + * + * \param m3 the matrix to decompose. + * \return r_U the computed left singular vector of \a m3 (NULL if not needed). + * \return r_S the computed singular values of \a m3 (NULL if not needed). + * \return r_V the computed right singular vector of \a m3 (NULL if not needed). + */ +void BLI_svd_m3(const float m3[3][3], float r_U[3][3], float r_S[3], float r_V[3][3]) +{ + EG3_svd_square_matrix(3, (const float *)m3, (float *)r_U, (float *)r_S, (float *)r_V); +} -- cgit v1.2.3