Adding code

This commit is contained in:
2023-12-26 13:24:13 -06:00
parent d456d05c3d
commit d9bd070fd1
40 changed files with 1610 additions and 1656 deletions

View File

@@ -0,0 +1,99 @@
#include <J3ML/LinearAlgebra/Matrix3x3.h>
namespace LinearAlgebra {
const Matrix3x3 Matrix3x3::Zero = Matrix3x3(0, 0, 0, 0, 0, 0, 0, 0, 0);
const Matrix3x3 Matrix3x3::Identity = Matrix3x3(1, 0, 0, 0, 1, 0, 0, 0, 1);
const Matrix3x3 Matrix3x3::NaN = Matrix3x3(NAN);
Matrix3x3::Matrix3x3(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21,
float m22) {
this->elems[0][0] = m00;
this->elems[0][1] = m01;
this->elems[0][2] = m02;
this->elems[1][0] = m10;
this->elems[1][1] = m11;
this->elems[1][2] = m12;
this->elems[2][0] = m20;
this->elems[2][1] = m21;
this->elems[2][2] = m22;
}
Vector3 Matrix3x3::GetRow(int index) const {
float x = this->elems[index][0];
float y = this->elems[index][1];
float z = this->elems[index][2];
return {x, y, z};
}
Vector3 Matrix3x3::GetColumn(int index) const {
float x = this->elems[0][index];
float y = this->elems[1][index];
float z = this->elems[2][index];
return {x, y, z};
}
float Matrix3x3::At(int x, int y) const {
return this->elems[x][y];
}
Vector3 Matrix3x3::operator*(const Vector3 &rhs) const {
return {
At(0, 0) * rhs.x + At(0, 1) * rhs.y + At(0, 2) * rhs.z,
At(1, 0) * rhs.x + At(1, 1) * rhs.y + At(1, 2) * rhs.z,
At(2, 0) * rhs.x + At(2, 1) * rhs.y + At(2, 2) * rhs.z
};
}
Matrix3x3 Matrix3x3::operator*(const Matrix3x3 &rhs) const {
//Matrix3x3 r;
auto m00 = At(0, 0) * rhs.At(0, 0) + At(0, 1) * rhs.At(1, 0) + At(0, 2) * rhs.At(2, 0);
auto m01 = At(0, 0) * rhs.At(0, 1) + At(0, 1) * rhs.At(1, 1) + At(0, 2) * rhs.At(2, 1);
auto m02 = At(0, 0) * rhs.At(0, 2) + At(0, 1) * rhs.At(1, 2) + At(0, 2) * rhs.At(2, 2);
auto m10 = At(1, 0) * rhs.At(0, 0) + At(1, 1) * rhs.At(1, 0) + At(1, 2) * rhs.At(2, 0);
auto m11 = At(1, 0) * rhs.At(0, 1) + At(1, 1) * rhs.At(1, 1) + At(1, 2) * rhs.At(2, 1);
auto m12 = At(1, 0) * rhs.At(0, 2) + At(1, 1) * rhs.At(1, 2) + At(1, 2) * rhs.At(2, 2);
auto m20 = At(2, 0) * rhs.At(0, 0) + At(2, 1) * rhs.At(1, 0) + At(2, 2) * rhs.At(2, 0);
auto m21 = At(2, 0) * rhs.At(0, 1) + At(2, 1) * rhs.At(1, 1) + At(2, 2) * rhs.At(2, 1);
auto m22 = At(2, 0) * rhs.At(0, 2) + At(2, 1) * rhs.At(1, 2) + At(2, 2) * rhs.At(2, 2);
return Matrix3x3({m00, m01, m02}, {m10, m11, m12}, {m20, m21, m22});
}
Matrix3x3::Matrix3x3(float val) {
this->elems[0][0] = val;
this->elems[0][1] = val;
this->elems[0][2] = val;
this->elems[1][0] = val;
this->elems[1][1] = val;
this->elems[1][2] = val;
this->elems[2][0] = val;
this->elems[2][1] = val;
this->elems[2][2] = val;
}
Matrix3x3::Matrix3x3(const Vector3 &r1, const Vector3 &r2, const Vector3 &r3) {
this->elems[0][0] = r1.x;
this->elems[0][1] = r1.y;
this->elems[0][2] = r1.z;
this->elems[1][0] = r2.x;
this->elems[1][1] = r2.y;
this->elems[1][2] = r2.z;
this->elems[2][0] = r3.x;
this->elems[2][1] = r3.y;
this->elems[2][2] = r3.z;
}
}