added unprojection into homogenous space for matrices

This commit is contained in:
Hartmut Seichter 2024-07-27 18:10:57 +02:00
parent 564cda1345
commit 55189a70b5
3 changed files with 17 additions and 11 deletions

View file

@ -23,6 +23,7 @@
#ifndef PW_CORE_MATRIX_HPP
#define PW_CORE_MATRIX_HPP
#include "vector.hpp"
#include <pw/core/globals.hpp>
#include <pw/core/math.hpp>
#include <pw/core/vector.hpp>
@ -205,6 +206,15 @@ struct matrix final {
}(std::make_index_sequence<RowsSlice>{}); // rowwise expansion
}
constexpr auto unproject(const Scalar& w) const noexcept
-> matrix<Scalar, Rows + 1, Cols + 1> {
return [&w, this]<std::size_t... Rs>(std::index_sequence<Rs...>) {
return matrix<Scalar, Rows + 1, Cols + 1>{
(Rs < Rows) ? (*this)[Rs].unproject(0)
: vector<Scalar, Cols + 1>::basis(Cols) * w...};
}(std::make_index_sequence<Rows + 1>{}); // rowwise expansion
}
//
// Iterators
//

View file

@ -24,20 +24,11 @@
#define PW_CORE_POINT_HPP
#include <pw/core/globals.hpp>
#include <pw/core/vector.hpp>
namespace pw {
template <typename Scalar> struct point final {
using value_type = Scalar;
Scalar x{}, y{};
template <typename ScalarOut>
constexpr auto cast() const noexcept -> point<ScalarOut> {
return {.x{ScalarOut(x)}, .y{ScalarOut(y)}};
}
};
template <typename Scalar> using point = vector<Scalar, 2>;
} // namespace pw

View file

@ -65,4 +65,9 @@ auto main() -> int {
// octave/matlab style output
std::print("\nm33=[{}]\n", m33);
auto m44 = m33.unproject(1);
std::print("\nm44=[{}]\n", m44);
}