del_geo/
mat2.rs

1//! methods for 2x2 matrix
2pub fn polar_decomposition<T>(
3    m: &nalgebra::Matrix2<T>,
4) -> (nalgebra::Matrix2<T>, nalgebra::Matrix2<T>)
5where
6    T: nalgebra::RealField + Copy,
7{
8    let x = m[(0, 0)] + m[(1, 1)];
9    let y = m[(1, 0)] - m[(0, 1)];
10    let scale = T::one() / (x * x + y * y).sqrt();
11    let c = x * scale;
12    let s = y * scale;
13    let u_mat = nalgebra::Matrix2::<T>::new(c, -s, s, c);
14    let p_mat = u_mat * m;
15    (u_mat, p_mat)
16}