Добавлены матрицы 2x3 и 3x2, добавлены произведения матриц. Изменения в названиях функций

This commit is contained in:
Andrey Pokidov 2024-11-13 12:41:05 +07:00
parent 86486ac9cf
commit 049f09f3d4
31 changed files with 1831 additions and 1314 deletions

144
src/matrixes.h Normal file
View file

@ -0,0 +1,144 @@
#ifndef _GEOMETRY_MATRIX_TYPES_H_
#define _GEOMETRY_MATRIX_TYPES_H_
// ================== Matrix2x2 ================= //
typedef struct {
float r1c1, r1c2;
float r2c1, r2c2;
} SPMatrix2x2;
typedef struct {
double r1c1, r1c2;
double r2c1, r2c2;
} DPMatrix2x2;
// ================== Matrix2x3 ================= //
typedef struct {
float r1c1, r1c2;
float r2c1, r2c2;
float r3c1, r3c2;
} SPMatrix2x3;
typedef struct {
double r1c1, r1c2;
double r2c1, r2c2;
double r3c1, r3c2;
} DPMatrix2x3;
// ================== Matrix3x2 ================= //
typedef struct {
float r1c1, r1c2, r1c3;
float r2c1, r2c2, r2c3;
} SPMatrix3x2;
typedef struct {
double r1c1, r1c2, r1c3;
double r2c1, r2c2, r2c3;
} DPMatrix3x2;
// ================== Matrix3x3 ================= //
typedef struct {
float r1c1, r1c2, r1c3;
float r2c1, r2c2, r2c3;
float r3c1, r3c2, r3c3;
} SPMatrix3x3;
typedef struct {
double r1c1, r1c2, r1c3;
double r2c1, r2c2, r2c3;
double r3c1, r3c2, r3c3;
} DPMatrix3x3;
// ========== Matrix Product 2x2 at 2x2 ========= //
static inline void sp_matrix_product_2x2_at_2x2(const SPMatrix2x2* matrix1, const SPMatrix2x2* matrix2, SPMatrix2x2* result)
{
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
const float r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1;
const float r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2;
result->r1c1 = r1c1;
result->r1c2 = r1c2;
result->r2c1 = r2c1;
result->r2c2 = r2c2;
}
static inline void dp_matrix_product_2x2_at_2x2(const DPMatrix2x2* matrix1, const DPMatrix2x2* matrix2, DPMatrix2x2* result)
{
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
const double r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1;
const double r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2;
result->r1c1 = r1c1;
result->r1c2 = r1c2;
result->r2c1 = r2c1;
result->r2c2 = r2c2;
}
// ========== Matrix Product 2x2 at 3x2 ========= //
void sp_matrix_product_2x2_at_3x2(const SPMatrix2x2* matrix1, const SPMatrix3x2* matrix2, SPMatrix3x2* result);
void dp_matrix_product_2x2_at_3x2(const DPMatrix2x2* matrix1, const DPMatrix3x2* matrix2, DPMatrix3x2* result);
// ========== Matrix Product 2x3 at 2x2 ========= //
void sp_matrix_product_2x3_at_2x2(const SPMatrix2x3* matrix1, const SPMatrix2x2* matrix2, SPMatrix2x3* result);
void dp_matrix_product_2x3_at_2x2(const DPMatrix2x3* matrix1, const DPMatrix2x2* matrix2, DPMatrix2x3* result);
// ========== Matrix Product 2x3 at 3x2 ========= //
void sp_matrix_product_2x3_at_3x2(const SPMatrix2x3* matrix1, const SPMatrix3x2* matrix2, SPMatrix3x3* result);
void dp_matrix_product_2x3_at_3x2(const DPMatrix2x3* matrix1, const DPMatrix3x2* matrix2, DPMatrix3x3* result);
// ========== Matrix Product 3x2 at 2x3 ========= //
void sp_matrix_product_3x2_at_2x3(const SPMatrix3x2* matrix1, const SPMatrix2x3* matrix2, SPMatrix2x2* result)
{
result->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
result->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
result->r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1;
result->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2;
}
void dp_matrix_product_3x2_at_2x3(const DPMatrix3x2* matrix1, const DPMatrix2x3* matrix2, DPMatrix2x2* result)
{
result->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
result->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
result->r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1;
result->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2;
}
// ========== Matrix Product 3x2 at 3x3 ========= //
void sp_matrix_product_3x2_at_3x3(const SPMatrix3x2* matrix1, const SPMatrix3x3* matrix2, SPMatrix3x2* result);
void dp_matrix_product_3x2_at_3x3(const DPMatrix3x2* matrix1, const DPMatrix3x3* matrix2, DPMatrix3x2* result);
// ========== Matrix Product 3x3 at 2x3 ========= //
void sp_matrix_product_3x3_at_2x3(const SPMatrix3x3* matrix1, const SPMatrix2x3* matrix2, SPMatrix2x3* result);
void dp_matrix_product_3x3_at_2x3(const DPMatrix3x3* matrix1, const DPMatrix2x3* matrix2, DPMatrix2x3* result);
// ========== Matrix Product 3x3 at 3x3 ========= //
void sp_matrix_product_3x3_at_3x3(const SPMatrix3x3* matrix1, const SPMatrix3x3* matrix2, SPMatrix3x3* result);
void dp_matrix_product_3x3_at_3x3(const DPMatrix3x3* matrix1, const DPMatrix3x3* matrix2, DPMatrix3x3* result);
#endif // _GEOMETRY_MATRIX_TYPES_H_