2#ifndef LIBSBX_MATH_MATRIX3X3_HPP_
3#define LIBSBX_MATH_MATRIX3X3_HPP_
14#include <fmt/format.h>
17#include <libsbx/math/vector3.hpp>
18#include <libsbx/math/vector4.hpp>
21#include <libsbx/math/traits.hpp>
30 template<scalar Other>
33 inline static constexpr auto x_axis = std::size_t{0u};
34 inline static constexpr auto y_axis = std::size_t{1u};
35 inline static constexpr auto z_axis = std::size_t{2u};
39 using value_type = base_type::value_type;
40 using reference = base_type::reference;
41 using const_reference = base_type::const_reference;
42 using size_type = base_type::size_type;
48 using base_type::base_type;
52 template<
typename Column0,
typename Column1,
typename Column2>
59 template<scalar Other>
61 Other x0, Other x1, Other x2,
62 Other y0, Other y1, Other y2,
63 Other z0, Other z1, Other z2
66 template<scalar Other>
67 constexpr basic_matrix3x3(
const Other v00,
const Other v11,
const Other v22)
noexcept;
69 template<scalar Other>
75 const auto m00 = matrix[0][0];
76 const auto m01 = matrix[0][1];
77 const auto m02 = matrix[0][2];
79 const auto m10 = matrix[1][0];
80 const auto m11 = matrix[1][1];
81 const auto m12 = matrix[1][2];
83 const auto m20 = matrix[2][0];
84 const auto m21 = matrix[2][1];
85 const auto m22 = matrix[2][2];
87 const auto determinant = m00 * (m11 * m22 - m21 * m12) - m10 * (m01 * m22 - m21 * m02) + m20 * (m01 * m12 - m11 * m02);
93 const auto inv_determinant = value_type{1} / determinant;
97 result[0][0] = (m11 * m22 - m21 * m12) * inv_determinant;
98 result[0][1] = (m21 * m02 - m01 * m22) * inv_determinant;
99 result[0][2] = (m01 * m12 - m11 * m02) * inv_determinant;
101 result[1][0] = (m20 * m12 - m10 * m22) * inv_determinant;
102 result[1][1] = (m00 * m22 - m20 * m02) * inv_determinant;
103 result[1][2] = (m10 * m02 - m00 * m12) * inv_determinant;
105 result[2][0] = (m10 * m21 - m20 * m11) * inv_determinant;
106 result[2][1] = (m20 * m01 - m00 * m21) * inv_determinant;
107 result[2][2] = (m00 * m11 - m10 * m01) * inv_determinant;
115 result[0][0] = matrix[0][0];
116 result[0][1] = matrix[1][0];
117 result[0][2] = matrix[2][0];
119 result[1][0] = matrix[0][1];
120 result[1][1] = matrix[1][1];
121 result[1][2] = matrix[2][1];
123 result[2][0] = matrix[0][2];
124 result[2][1] = matrix[1][2];
125 result[2][2] = matrix[2][2];
135 const auto x_length = x.length();
136 const auto y_length = y.length();
137 const auto z_length = z.length();
139 if (x_length < math::epsilon_v<value_type> || y_length < math::epsilon_v<value_type> || z_length < math::epsilon_v<value_type>) {
148 if (x_length >= y_length && x_length >= z_length) {
150 }
else if (y_length >= z_length) {
157 x = math::vector3::normalized(x);
158 y = math::vector3::normalized(y - x * math::vector3::dot(x, y));
159 z = math::vector3::cross(x, y);
184 constexpr auto operator[](size_type index)
const noexcept ->
const column_type&;
186 constexpr auto operator[](size_type index)
noexcept ->
column_type&;
199template<scalar Lhs, scalar Rhs>
202template<scalar Lhs, scalar Rhs>
216template<sbx::math::scalar Type>
217struct fmt::formatter<sbx::math::basic_matrix3x3<Type>> {
219 template<
typename ParseContext>
220 constexpr auto parse(ParseContext& context)
const ->
decltype(context.begin()) {
221 return context.begin();
224 template<
typename FormatContext>
226 if constexpr (sbx::math::is_floating_point_v<Type>) {
227 return fmt::format_to(context.out(),
228 "\n{:.2f}, {:.2f}, {:.2f}\n{:.2f}, {:.2f}, {:.2f}\n{:.2f}, {:.2f}, {:.2f}",
229 matrix[0][0], matrix[1][0], matrix[2][0],
230 matrix[0][1], matrix[1][1], matrix[2][1],
231 matrix[0][2], matrix[1][2], matrix[2][2]
234 return fmt::format_to(context.out(),
235 "\n{}, {}, {}\n{}, {}, {}\n{}, {}, {}\n{}, {}, {}",
236 matrix[0][0], matrix[1][0], matrix[2][0],
237 matrix[0][1], matrix[1][1], matrix[2][1],
238 matrix[0][2], matrix[1][2], matrix[2][2]
245#include <libsbx/math/matrix3x3.ipp>
Angle types and utilities.
constexpr auto operator*(basic_degree< Type > lhs, const Other rhs) noexcept -> basic_degree< Type >
Multiplies a degree value by a scalar factor.
Definition: angle.ipp:105
Definition: matrix3x3.hpp:26
Fixed-size column-major matrix.
Definition: matrix.hpp:48
static constexpr auto identity(const value_type value=static_cast< value_type >(1)) noexcept -> basic_matrix
Constructs an identity matrix.
Definition: matrix.ipp:113
Definition: vector3.hpp:23
static constexpr auto abs(const basic_vector< Size, Lhs > &vector) noexcept -> basic_vector
Returns the component-wise absolute value of a vector.
Definition: vector.ipp:71
Core numeric concepts and type traits.
Generic fixed-size matrix type.
Definition: traits.hpp:11