1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-28 08:50:30 +02:00

add m_determinant

This commit is contained in:
Justin Lin
2020-02-26 09:36:55 +08:00
parent 67982f450d
commit 2ec87b2287
2 changed files with 23 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
use <util/slice.scad>;
function _m_determinant_sum(lt, leng, i = 0) =
i == leng ? 0 : (lt[i] + _m_determinant_sum(lt, leng, i + 1));
function _m_determinant_sub(matrix, leng, fc) =
let(
init_sub_m = [for(i = [1:leng - 1]) matrix[i]],
sub_m = [for(i = [0:len(init_sub_m) - 1])
concat(slice(init_sub_m[i], 0, fc), slice(init_sub_m[i], fc + 1))
],
sgn = pow(-1, fc % 2)
)
sgn * matrix[0][fc] * _m_determinant(sub_m);
function _m_determinant(matrix) =
let(leng = len(matrix))
leng == 2 ? matrix[0][0] * matrix[1][1] - matrix[1][0] * matrix[0][1] :
let(indices = [for(i = [0:leng - 1]) i])
_m_determinant_sum([for(fc = indices) _m_determinant_sub(matrix, leng, fc)], leng);

View File

@@ -0,0 +1,3 @@
use <experimental/_impl/_m_determinant_impl.scad>;
function m_determinant(matrix) = _m_determinant(matrix);