MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MatrixHelper.cpp
Go to the documentation of this file.
1#include "MatrixHelper.hpp"
2
3namespace MayaFlux::Yantra {
4
5Eigen::MatrixXd create_rotation_matrix(double angle, uint32_t axis, uint32_t dimensions)
6{
7 if (dimensions == 2) {
8 Eigen::Matrix2d rotation;
9 rotation << std::cos(angle), -std::sin(angle),
10 std::sin(angle), std::cos(angle);
11 return rotation;
12 }
13
14 if (dimensions == 3) {
15 Eigen::Matrix3d rotation = Eigen::Matrix3d::Identity();
16
17 switch (axis) {
18 case 0:
19 rotation << 1, 0, 0,
20 0, std::cos(angle), -std::sin(angle),
21 0, std::sin(angle), std::cos(angle);
22 break;
23 case 1:
24 rotation << std::cos(angle), 0, std::sin(angle),
25 0, 1, 0,
26 -std::sin(angle), 0, std::cos(angle);
27 break;
28 case 2:
29 default:
30 rotation << std::cos(angle), -std::sin(angle), 0,
31 std::sin(angle), std::cos(angle), 0,
32 0, 0, 1;
33 break;
34 }
35 return rotation;
36 }
37
38 return Eigen::MatrixXd::Identity(dimensions, dimensions);
39}
40
41Eigen::MatrixXd create_scaling_matrix(const std::vector<double>& scale_factors)
42{
43 if (scale_factors.empty()) {
44 return Eigen::MatrixXd::Identity(1, 1);
45 }
46
47 Eigen::MatrixXd scaling = Eigen::MatrixXd::Zero(scale_factors.size(), scale_factors.size());
48
49 auto indices = std::views::iota(size_t { 0 }, scale_factors.size());
50 std::ranges::for_each(indices, [&](size_t i) {
51 scaling(i, i) = scale_factors[i];
52 });
53
54 return scaling;
55}
56
57} // namespace MayaFlux::Yantra
Region-aware and matrix transformation functions leveraging existing ecosystem.
Eigen::MatrixXd create_rotation_matrix(double angle, uint32_t axis, uint32_t dimensions)
Eigen::MatrixXd create_scaling_matrix(const std::vector< double > &scale_factors)