mirror of
https://github.com/Relintai/pmlpp.git
synced 2025-01-02 16:29:35 +01:00
Implemented MLPPMatrix::rotate.
This commit is contained in:
parent
8104b7a9ff
commit
593cab5a5b
@ -1501,21 +1501,6 @@ Ref<MLPPVector> MLPPLinAlg::cosnv(const Ref<MLPPVector> &a) {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
std::vector<std::vector<real_t>> MLPPLinAlg::rotate(std::vector<std::vector<real_t>> A, real_t theta, int axis) {
|
|
||||||
std::vector<std::vector<real_t>> rotationMatrix = { { Math::cos(theta), -Math::sin(theta) }, { Math::sin(theta), Math::cos(theta) } };
|
|
||||||
if (axis == 0) {
|
|
||||||
rotationMatrix = { { 1, 0, 0 }, { 0, Math::cos(theta), -Math::sin(theta) }, { 0, Math::sin(theta), Math::cos(theta) } };
|
|
||||||
} else if (axis == 1) {
|
|
||||||
rotationMatrix = { { Math::cos(theta), 0, Math::sin(theta) }, { 0, 1, 0 }, { -Math::sin(theta), 0, Math::cos(theta) } };
|
|
||||||
} else if (axis == 2) {
|
|
||||||
rotationMatrix = { { Math::cos(theta), -Math::sin(theta), 0 }, { Math::sin(theta), Math::cos(theta), 0 }, { 1, 0, 0 } };
|
|
||||||
}
|
|
||||||
|
|
||||||
return matmult(A, rotationMatrix);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
Ref<MLPPMatrix> MLPPLinAlg::maxnm(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B) {
|
Ref<MLPPMatrix> MLPPLinAlg::maxnm(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B) {
|
||||||
Ref<MLPPMatrix> C;
|
Ref<MLPPMatrix> C;
|
||||||
C.instance();
|
C.instance();
|
||||||
|
@ -82,8 +82,6 @@ public:
|
|||||||
Ref<MLPPMatrix> sinnm(const Ref<MLPPMatrix> &A);
|
Ref<MLPPMatrix> sinnm(const Ref<MLPPMatrix> &A);
|
||||||
Ref<MLPPMatrix> cosnm(const Ref<MLPPMatrix> &A);
|
Ref<MLPPMatrix> cosnm(const Ref<MLPPMatrix> &A);
|
||||||
|
|
||||||
//std::vector<std::vector<real_t>> rotate(std::vector<std::vector<real_t>> A, real_t theta, int axis = -1);
|
|
||||||
|
|
||||||
Ref<MLPPMatrix> maxnm(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
Ref<MLPPMatrix> maxnm(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
||||||
|
|
||||||
//real_t max(std::vector<std::vector<real_t>> A);
|
//real_t max(std::vector<std::vector<real_t>> A);
|
||||||
|
@ -1839,20 +1839,85 @@ void MLPPMatrix::cosb(const Ref<MLPPMatrix> &A) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
Ref<MLPPMatrix> MLPPMatrix::create_rotation_matrix(real_t theta, int axis) {
|
||||||
std::vector<std::vector<real_t>> MLPPMatrix::rotate(std::vector<std::vector<real_t>> A, real_t theta, int axis) {
|
Ref<MLPPMatrix> rotation_matrix;
|
||||||
std::vector<std::vector<real_t>> rotationMatrix = { { Math::cos(theta), -Math::sin(theta) }, { Math::sin(theta), Math::cos(theta) } };
|
rotation_matrix.instance();
|
||||||
if (axis == 0) {
|
|
||||||
rotationMatrix = { { 1, 0, 0 }, { 0, Math::cos(theta), -Math::sin(theta) }, { 0, Math::sin(theta), Math::cos(theta) } };
|
if (axis == -1) {
|
||||||
|
rotation_matrix->resize(Size2(2, 2));
|
||||||
|
real_t *rptr = rotation_matrix->ptrw();
|
||||||
|
|
||||||
|
rptr[rotation_matrix->calculate_index(0, 0)] = Math::cos(theta);
|
||||||
|
rptr[rotation_matrix->calculate_index(0, 1)] = -Math::sin(theta);
|
||||||
|
|
||||||
|
rptr[rotation_matrix->calculate_index(1, 0)] = Math::cos(theta);
|
||||||
|
rptr[rotation_matrix->calculate_index(1, 1)] = Math::cos(theta);
|
||||||
|
} else if (axis == 0) {
|
||||||
|
rotation_matrix->resize(Size2(3, 3));
|
||||||
|
real_t *rptr = rotation_matrix->ptrw();
|
||||||
|
|
||||||
|
rptr[rotation_matrix->calculate_index(0, 0)] = 1;
|
||||||
|
rptr[rotation_matrix->calculate_index(0, 1)] = 0;
|
||||||
|
rptr[rotation_matrix->calculate_index(0, 2)] = 0;
|
||||||
|
|
||||||
|
rptr[rotation_matrix->calculate_index(1, 0)] = 0;
|
||||||
|
rptr[rotation_matrix->calculate_index(1, 1)] = Math::cos(theta);
|
||||||
|
rptr[rotation_matrix->calculate_index(1, 2)] = -Math::sin(theta);
|
||||||
|
|
||||||
|
rptr[rotation_matrix->calculate_index(2, 0)] = 0;
|
||||||
|
rptr[rotation_matrix->calculate_index(2, 1)] = Math::sin(theta);
|
||||||
|
rptr[rotation_matrix->calculate_index(2, 2)] = Math::cos(theta);
|
||||||
} else if (axis == 1) {
|
} else if (axis == 1) {
|
||||||
rotationMatrix = { { Math::cos(theta), 0, Math::sin(theta) }, { 0, 1, 0 }, { -Math::sin(theta), 0, Math::cos(theta) } };
|
rotation_matrix->resize(Size2(3, 3));
|
||||||
|
real_t *rptr = rotation_matrix->ptrw();
|
||||||
|
|
||||||
|
rptr[rotation_matrix->calculate_index(0, 0)] = Math::cos(theta);
|
||||||
|
rptr[rotation_matrix->calculate_index(0, 1)] = 0;
|
||||||
|
rptr[rotation_matrix->calculate_index(0, 2)] = Math::sin(theta);
|
||||||
|
|
||||||
|
rptr[rotation_matrix->calculate_index(1, 0)] = 0;
|
||||||
|
rptr[rotation_matrix->calculate_index(1, 1)] = 1;
|
||||||
|
rptr[rotation_matrix->calculate_index(1, 2)] = 0;
|
||||||
|
|
||||||
|
rptr[rotation_matrix->calculate_index(2, 0)] = -Math::sin(theta);
|
||||||
|
rptr[rotation_matrix->calculate_index(2, 1)] = 0;
|
||||||
|
rptr[rotation_matrix->calculate_index(2, 2)] = Math::cos(theta);
|
||||||
|
|
||||||
} else if (axis == 2) {
|
} else if (axis == 2) {
|
||||||
rotationMatrix = { { Math::cos(theta), -Math::sin(theta), 0 }, { Math::sin(theta), Math::cos(theta), 0 }, { 1, 0, 0 } };
|
rotation_matrix->resize(Size2(3, 3));
|
||||||
|
real_t *rptr = rotation_matrix->ptrw();
|
||||||
|
|
||||||
|
rptr[rotation_matrix->calculate_index(0, 0)] = Math::cos(theta);
|
||||||
|
rptr[rotation_matrix->calculate_index(0, 1)] = -Math::sin(theta);
|
||||||
|
rptr[rotation_matrix->calculate_index(0, 2)] = 0;
|
||||||
|
|
||||||
|
rptr[rotation_matrix->calculate_index(1, 0)] = Math::sin(theta);
|
||||||
|
rptr[rotation_matrix->calculate_index(1, 1)] = Math::cos(theta);
|
||||||
|
rptr[rotation_matrix->calculate_index(1, 2)] = 0;
|
||||||
|
|
||||||
|
rptr[rotation_matrix->calculate_index(2, 0)] = 1;
|
||||||
|
rptr[rotation_matrix->calculate_index(2, 1)] = 0;
|
||||||
|
rptr[rotation_matrix->calculate_index(2, 2)] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return matmult(A, rotationMatrix);
|
return rotation_matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MLPPMatrix::rotate(real_t theta, int axis) {
|
||||||
|
Ref<MLPPMatrix> rm = create_rotation_matrix(theta, axis);
|
||||||
|
|
||||||
|
mult(rm);
|
||||||
|
}
|
||||||
|
Ref<MLPPMatrix> MLPPMatrix::rotaten(real_t theta, int axis) {
|
||||||
|
Ref<MLPPMatrix> rm = create_rotation_matrix(theta, axis);
|
||||||
|
|
||||||
|
return multn(rm);
|
||||||
|
}
|
||||||
|
void MLPPMatrix::rotateb(const Ref<MLPPMatrix> &A, real_t theta, int axis) {
|
||||||
|
Ref<MLPPMatrix> rm = create_rotation_matrix(theta, axis);
|
||||||
|
|
||||||
|
multb(A, rm);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
void MLPPMatrix::max(const Ref<MLPPMatrix> &B) {
|
void MLPPMatrix::max(const Ref<MLPPMatrix> &B) {
|
||||||
ERR_FAIL_COND(!B.is_valid());
|
ERR_FAIL_COND(!B.is_valid());
|
||||||
@ -3257,6 +3322,12 @@ void MLPPMatrix::_bind_methods() {
|
|||||||
ClassDB::bind_method(D_METHOD("cosn"), &MLPPMatrix::cosn);
|
ClassDB::bind_method(D_METHOD("cosn"), &MLPPMatrix::cosn);
|
||||||
ClassDB::bind_method(D_METHOD("cosb", "A"), &MLPPMatrix::cosb);
|
ClassDB::bind_method(D_METHOD("cosb", "A"), &MLPPMatrix::cosb);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("create_rotation_matrix", "theta", "axis"), &MLPPMatrix::create_rotation_matrix, -1);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("rotate", "theta", "axis"), &MLPPMatrix::rotate, -1);
|
||||||
|
ClassDB::bind_method(D_METHOD("rotaten", "theta", "axis"), &MLPPMatrix::rotaten, -1);
|
||||||
|
ClassDB::bind_method(D_METHOD("rotateb", "A", "theta", "axis"), &MLPPMatrix::rotateb, -1);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("max", "B"), &MLPPMatrix::max);
|
ClassDB::bind_method(D_METHOD("max", "B"), &MLPPMatrix::max);
|
||||||
ClassDB::bind_method(D_METHOD("maxn", "B"), &MLPPMatrix::maxn);
|
ClassDB::bind_method(D_METHOD("maxn", "B"), &MLPPMatrix::maxn);
|
||||||
ClassDB::bind_method(D_METHOD("maxb", "A", "B"), &MLPPMatrix::maxb);
|
ClassDB::bind_method(D_METHOD("maxb", "A", "B"), &MLPPMatrix::maxb);
|
||||||
|
@ -14,19 +14,18 @@
|
|||||||
|
|
||||||
#include "core/object/resource.h"
|
#include "core/object/resource.h"
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
#include "core/containers/vector.h"
|
||||||
#include "core/defs.h"
|
#include "core/defs.h"
|
||||||
#include "core/math_funcs.h"
|
#include "core/math_funcs.h"
|
||||||
#include "core/pool_arrays.h"
|
|
||||||
#include "core/containers/vector.h"
|
|
||||||
#include "core/os/memory.h"
|
#include "core/os/memory.h"
|
||||||
|
#include "core/pool_arrays.h"
|
||||||
|
|
||||||
#include "gen/resource.h"
|
#include "gen/resource.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "mlpp_vector.h"
|
#include "mlpp_vector.h"
|
||||||
|
|
||||||
class Image;
|
class Image;
|
||||||
@ -245,7 +244,11 @@ public:
|
|||||||
Ref<MLPPMatrix> cosn() const;
|
Ref<MLPPMatrix> cosn() const;
|
||||||
void cosb(const Ref<MLPPMatrix> &A);
|
void cosb(const Ref<MLPPMatrix> &A);
|
||||||
|
|
||||||
//std::vector<std::vector<real_t>> rotate(std::vector<std::vector<real_t>> A, real_t theta, int axis = -1);
|
Ref<MLPPMatrix> create_rotation_matrix(real_t theta, int axis = -1);
|
||||||
|
|
||||||
|
void rotate(real_t theta, int axis = -1);
|
||||||
|
Ref<MLPPMatrix> rotaten(real_t theta, int axis = -1);
|
||||||
|
void rotateb(const Ref<MLPPMatrix> &A, real_t theta, int axis = -1);
|
||||||
|
|
||||||
void max(const Ref<MLPPMatrix> &B);
|
void max(const Ref<MLPPMatrix> &B);
|
||||||
Ref<MLPPMatrix> maxn(const Ref<MLPPMatrix> &B) const;
|
Ref<MLPPMatrix> maxn(const Ref<MLPPMatrix> &B) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user