@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
27 lines (24 loc) • 1.26 kB
JavaScript
import { m2_multiply } from "../../../geom/mat2/m2_multiply.js";
import { m2_polar_decomp_noS } from "./m2_polar_decomp_noS.js";
/**
* Performs a polar decomposition of a 2x2 matrix.
* This function decomposes a 2x2 matrix `m` into two matrices, `R` and `S`,
* such that m = S * R, where:
* - R is a 2x2 orthogonal matrix (representing a rotation).
* - S is a 2x2 symmetric positive semi-definite matrix.
* The input matrix `m` and output matrices `R` and `S` are stored in a flattened,
* transposed format (consistent with the Taichi programming language convention).
*
* @param {number[]} R Output: 2x2 orthogonal matrix (rotation), stored as a flattened
* array [c, s, -s, c], where 'c' is the cosine and 's' is the sine of the rotation
* angle. Modified in-place.
* @param {number[]} S Output: 2x2 symmetric positive semi-definite matrix,
* stored as a flattened array. Modified in-place.
* @param {number[]} m Input: 2x2 matrix, stored as a flattened, *transposed* array [a, b, c, d],
* representing the matrix [[a, c], [b, d]]. Will be read from, but NOT modified.
*/
export function m2_polar_decomp(R, S, m) {
// transposed as in taichi
m2_polar_decomp_noS(R, m);
m2_multiply(S, m, R);
}