Commit 600a9641 authored by Julius NehringWirxel's avatar Julius NehringWirxel

WIP on eigenvaluedecomposition.

parent 740df0c1
This diff is collapsed.
#pragma once
#include <typed-geometry/types/comp.hh>
#include <typed-geometry/types/array.hh>
#include <typed-geometry/types/mat.hh>
#include <typed-geometry/types/vec.hh>
#include <typed-geometry/functions/basic/scalar_math.hh>
#include <typed-geometry/functions/matrix/transpose.hh>
namespace tg
{
template <class T>
[[nodiscard]] constexpr comp<2, T> eigenvalues(mat<2, 2, T> const& m)
template <int D, class ScalarT>
struct eigen_decomposition_result
{
auto mp_half = (m[0][0] + m[1][1]) / T(2);
vec<D, ScalarT> eigenvector;
ScalarT eigenvalue;
};
template <class ScalarT>
[[nodiscard]] constexpr array<eigen_decomposition_result<2, ScalarT>, 2> eigen_decomposition(mat<2, 2, ScalarT> const& m)
{
// todo
}
template <class ScalarT>
[[nodiscard]] constexpr array<eigen_decomposition_result<3, ScalarT>, 3> eigen_decomposition(mat<3, 3, ScalarT> const& m);
template <class ScalarT>
[[nodiscard]] constexpr array<eigen_decomposition_result<4, ScalarT>, 4> eigen_decomposition(mat<4, 4, ScalarT> const& m);
template <>
[[nodiscard]] inline constexpr array<eigen_decomposition_result<3, float>, 3> eigen_decomposition(mat<3, 3, float> const& m);
template <>
[[nodiscard]] inline constexpr array<eigen_decomposition_result<4, float>, 4> eigen_decomposition(mat<4, 4, float> const& m);
template <>
[[nodiscard]] inline constexpr array<eigen_decomposition_result<3, double>, 3> eigen_decomposition(mat<3, 3, double> const& m);
template <>
[[nodiscard]] inline constexpr array<eigen_decomposition_result<4, double>, 4> eigen_decomposition(mat<4, 4, double> const& m);
template <class ScalarT>
[[nodiscard]] constexpr array<ScalarT, 2> eigenvalues(mat<2, 2, ScalarT> const& m)
{
auto mp_half = (m[0][0] + m[1][1]) / ScalarT(2);
auto q = m[0][0] * m[1][1] - m[1][0] * m[0][1];
auto d = sqrt(max(T(0), mp_half * mp_half - q));
auto d = sqrt(max(ScalarT(0), mp_half * mp_half - q));
return {mp_half + d, mp_half - d};
}
template <class T>
[[nodiscard]] constexpr comp<2, T> singular_values(mat<2, 2, T> const& m)
template <class ScalarT>
[[nodiscard]] constexpr array<ScalarT, 3> eigenvalues(mat<3, 3, ScalarT> const& m)
{
// todo
}
template <class ScalarT>
[[nodiscard]] constexpr array<ScalarT, 4> eigenvalues(mat<4, 4, ScalarT> const& m)
{
// todo
}
template <class ScalarT>
[[nodiscard]] constexpr array<vec<2, ScalarT>, 2> eigenvectors(mat<2, 2, ScalarT> const& m)
{
// todo
}
template <class ScalarT>
[[nodiscard]] constexpr array<vec<3, ScalarT>, 3> eigenvectors(mat<3, 3, ScalarT> const& m)
{
// todo
}
template <class ScalarT>
[[nodiscard]] constexpr array<vec<4, ScalarT>, 4> eigenvectors(mat<4, 4, ScalarT> const& m)
{
// todo
}
template <class ScalarT>
[[nodiscard]] constexpr array<ScalarT, 2> singular_values(mat<2, 2, ScalarT> const& m)
{
auto [s0, s1] = eigenvalues(m * transpose(m));
return {sqrt(s0), sqrt(s1)};
}
template <class ScalarT>
[[nodiscard]] constexpr array<ScalarT, 3> singular_values(mat<3, 3, ScalarT> const& m)
{
// todo
}
template <class ScalarT>
[[nodiscard]] constexpr array<ScalarT, 4> singular_values(mat<4, 4, ScalarT> const& m)
{
// todo
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment