mt.glm.linear
Additional functions for PyGLM
Reimplementation of MT’s GLSL implementation of some linear algebra functions in 3D.
Source: CRL_oven/assets/glsl/linear.glsl
Functions
mat3diag()
: Constructs a 3x3 diagonal matrix.diag3()
: Extracts the diagonal vector of a 3x3 matrix.sort3()
: Sorts 3 elements in descending order in-place.cbrt()
: Cubic root.solveCubic()
: Solves cubic polynomial in-place.ldu3()
: Computes the LDUP decomposition (LU with partial pivoting) in-placelduBSolve3()
: Does the backward-solve step, or U*x = yevd3()
: Eigenvalue decomposes a symmetric positive semidefinite 3x3 matrixsvd3()
: Singularvalue decomposes a 3x3 matrix.sop3()
: Finds the nearest rotation.mat2diag()
: Constructs a 2x2 diagonal matrix.diag2()
: Extracts the diagonal vector of a 2x2 matrix.rot2()
: Gets a 2D rotation matrix given the rotation angle in radian.svd2()
: Singularvalue decomposes a 2x2 matrix.evd2()
: Eigenvalue decomposes a symmetric positive semidefinite 2x2 matrix
- mt.glm.linear.mat3diag(x: vec3) mat3x3
Constructs a 3x3 diagonal matrix.
- mt.glm.linear.diag3(x: mat3x3) vec3
Extracts the diagonal vector of a 3x3 matrix.
- mt.glm.linear.sort3(x: vec3) vec3
Sorts 3 elements in descending order in-place.
- mt.glm.linear.cbrt(x: float) float
Cubic root.
- mt.glm.linear.solveCubic(c: vec3) vec3
Solves cubic polynomial in-place.
Given polynomial: c[0] + c[1]*x + c[2]*x^2 + x^3 = 0, assuming it has 3 real roots, find the roots and store them in c[0], c[1], c[2].
- mt.glm.linear.ldu3(A: mat3x3) Tuple[mat3x3, ivec3]
Computes the LDUP decomposition (LU with partial pivoting) in-place
- Parameters:
A (glm.mat3) – the input and output matrix
- Returns:
A (glm.mat3) – the input and output matrix
P (glm.ivec3) – the output pivoting integer vector
- mt.glm.linear.lduBSolve3(y: vec3, LDU: mat3x3, P: ivec3) vec3
Does the backward-solve step, or U*x = y
- mt.glm.linear.evd3(A: mat3x3) Tuple[mat3x3, vec3]
Eigenvalue decomposes a symmetric positive semidefinite 3x3 matrix
Compute: A = V mat3diag(S) V.T. Eigenvalues are sorted in the descending order.
- Parameters:
A (glm.mat3) – input 3x3 matrix
- Returns:
V (glm.mat3) – output rotation matrix
S (glm.vec3) – output diagonal vector
- mt.glm.linear.svd3(A: mat3x3, thr: float = 1e-06) Tuple[mat3x3, vec3, mat3x3]
Singularvalue decomposes a 3x3 matrix.
Compute A = U mat3diag(S) V^T. Singularvalues are sorted in descending order.
- Parameters:
A (glm.mat3) – input 3x3 matrix
thr (float) – small threshold for computing the rank
- Returns:
U (glm.mat3) – output rotation matrix
S (glm.vec3) – output diagonal vector
V (glm.mat3) – output rotation matrix
- mt.glm.linear.sop3(A: mat3x3) mat3x3
Finds the nearest rotation.
- mt.glm.linear.mat2diag(x: vec2) mat2x2
Constructs a 2x2 diagonal matrix.
- mt.glm.linear.diag2(x: mat2x2) vec2
Extracts the diagonal vector of a 2x2 matrix.
- mt.glm.linear.rot2(angle: float) mat2x2
Gets a 2D rotation matrix given the rotation angle in radian.
- mt.glm.linear.svd2(A: mat2x2) vec4
Singularvalue decomposes a 2x2 matrix.
Compute A = U mat2diag(S) V^T. Singularvalues are sorted in descending order.
Source from here
- Parameters:
A (glm.mat2) – input 2x2 matrix
- Returns:
Parameter (s1, s2, u, v) where A = rot2(u) * mat2diag(s1, s2) * rot2(-v).
- Return type:
glm.vec4
- mt.glm.linear.evd2(A: mat2x2) vec3
Eigenvalue decomposes a symmetric positive semidefinite 2x2 matrix
Compute: A = V mat2diag(S) V.T. Eigenvalues are sorted in the descending order.
- Parameters:
A (glm.mat2) – input 2x2 matrix
- Returns:
Parameter (s1, s2, u) where A = rot2(u) * mat2diag(s1, s2) * rot2(-u).
- Return type:
glm.vec3