mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-28 00:40:39 +02:00
add m_determinant
This commit is contained in:
20
src/experimental/_impl/_m_determinant_impl.scad
Normal file
20
src/experimental/_impl/_m_determinant_impl.scad
Normal 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);
|
3
src/experimental/m_determinant.scad
Normal file
3
src/experimental/m_determinant.scad
Normal file
@@ -0,0 +1,3 @@
|
||||
use <experimental/_impl/_m_determinant_impl.scad>;
|
||||
|
||||
function m_determinant(matrix) = _m_determinant(matrix);
|
Reference in New Issue
Block a user