akreon-linalg
Fixed-size linear algebra and numerical methods in C++26.
Loading...
Searching...
No Matches
affine_transforms.hpp
Go to the documentation of this file.
1/*
2 * Copyright © 2025-2026 Akreon LLC
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6#pragma once
7
8#include <utility>
9
10#include "affine_map.hpp"
13
14namespace affine {
15
23template <typename T>
25struct Rotation2d {
26 constexpr auto operator()(T phi) const {
27 const auto cz = linalg::constexpr_cos(phi);
28 const auto sz = linalg::constexpr_sin(phi);
29 return linalg::Matrix<T, 2, 2>{linalg::Vector<T, 2>{cz, T(-1) * sz},
30 linalg::Vector<T, 2>{sz, cz}};
31 }
32};
33
37template <typename T>
39struct Rotation3d {
40 constexpr auto x(T phi) const {
41 const auto cx = linalg::constexpr_cos(phi);
42 const auto sx = linalg::constexpr_sin(phi);
43 return linalg::Matrix<T, 3, 3>{linalg::Vector<T, 3>{T(1), T(0), T(0)},
44 linalg::Vector<T, 3>{T(0), cx, T(-1) * sx},
45 linalg::Vector<T, 3>{T(0), sx, cx}};
46 }
47
48 constexpr auto y(T theta) const {
49 const auto cy = linalg::constexpr_cos(theta);
50 const auto sy = linalg::constexpr_sin(theta);
52 linalg::Vector<T, 3>{T(0), T(1), T(0)},
53 linalg::Vector<T, 3>{T(-1) * sy, T(0), cy}};
54 }
55
56 constexpr auto z(T psi) const {
57 const auto cz = linalg::constexpr_cos(psi);
58 const auto sz = linalg::constexpr_sin(psi);
59 return linalg::Matrix<T, 3, 3>{linalg::Vector<T, 3>{cz, T(-1) * sz, T(0)},
60 linalg::Vector<T, 3>{sz, cz, T(0)},
61 linalg::Vector<T, 3>{T(0), T(0), T(1)}};
62 }
63};
64
68template <typename T, std::size_t N>
69 requires(linalg::Field<T> && !linalg::is_complex_v<T> && N > 0)
70struct Scale {
71 template <typename... Scalars>
72 constexpr auto operator()(Scalars... scalars) const {
74 int i = 0;
75 auto set_elem = [&](const auto& s) {
76 S(i, i) *= s;
77 i++;
78 };
79 ((void)set_elem(std::forward<Scalars>(scalars)), ...);
80 return S;
81 }
82};
83
87template <typename T, std::size_t N>
88 requires(linalg::Field<T> && !linalg::is_complex_v<T> && N > 0)
89struct Shear {
90 constexpr auto operator()(std::size_t i, std::size_t j, T s) const {
91 AK_ASSERT((i < N && j < N) &&
92 "Shear transform indices must be within matrix bounds");
94 H(i, j) = s;
95 return H;
96 }
97};
98
99} // namespace affine
#define AK_ASSERT(x)
Definition assert.hpp:13
Registered scalar supporting the Akreon Linalg's field arithmetic interface.
constexpr auto constexpr_sin(T x, int terms=16)
Approximate sine with a truncated Taylor recurrence.
constexpr auto constexpr_cos(T x, int terms=16)
Approximate cosine with a truncated Taylor recurrence.
constexpr std::size_t mat_rows_v
Registered compile-time row count after cv/ref normalization.
Euler angle rotation about 2d plane.
constexpr auto operator()(T phi) const
Euler angle rotation about 3d roll, pitch, and yaw angles.
constexpr auto x(T phi) const
constexpr auto z(T psi) const
constexpr auto y(T theta) const
Scale directions spanning N dim space.
constexpr auto operator()(Scalars... scalars) const
Shear transform where jth component "shears" ith direction.
constexpr auto operator()(std::size_t i, std::size_t j, T s) const
Owning, fixed-size, row-major matrix container over a scalar field.
Definition matrix.hpp:44
Owning, fixed-size vector container.
Definition vector.hpp:36