Добавлены матрицы 2x3 и 3x2, добавлены произведения матриц. Изменения в названиях функций
This commit is contained in:
parent
86486ac9cf
commit
049f09f3d4
31 changed files with 1831 additions and 1314 deletions
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_workspace_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveProject path="dev/geometry-dev.cbp" />
|
||||
<ActiveProject path="src/geometry.cbp" />
|
||||
<PreferredTarget name="Debug" />
|
||||
</CodeBlocks_workspace_layout_file>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Release" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<File name="main.c" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="3262" topLine="102" />
|
||||
<Cursor1 position="3793" topLine="116" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
||||
|
|
17
dev/main.c
17
dev/main.c
|
@ -135,7 +135,7 @@ void print_matrix(const DPMatrix3x3* matrix)
|
|||
printf("(%lf, %lf, %lf)\n", matrix->r2c1, matrix->r2c2, matrix->r2c3);
|
||||
printf("(%lf, %lf, %lf)\n\n", matrix->r3c1, matrix->r3c2, matrix->r3c3);
|
||||
}
|
||||
|
||||
/*
|
||||
int main()
|
||||
{
|
||||
DPMatrix3x3 m1, m2, check;
|
||||
|
@ -170,3 +170,18 @@ int main()
|
|||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
int main()
|
||||
{
|
||||
SPVector2 vector;
|
||||
|
||||
sp_vector2_set(0, 0, &vector);
|
||||
|
||||
printf("SPVector2(%f, %f), module = %d\n",
|
||||
vector.x1,
|
||||
vector.x2,
|
||||
sp_vector2_is_zero(&vector)
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
|
BIN
docs/documentation.odt
Normal file
BIN
docs/documentation.odt
Normal file
Binary file not shown.
|
@ -58,10 +58,16 @@
|
|||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="matrix2x2.h" />
|
||||
<Unit filename="matrix2x3.h" />
|
||||
<Unit filename="matrix3x2.h" />
|
||||
<Unit filename="matrix3x3.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="matrix3x3.h" />
|
||||
<Unit filename="matrixes.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="matrixes.h" />
|
||||
<Unit filename="quaternion.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
|
|
|
@ -8,7 +8,9 @@
|
|||
#include "vector2.h"
|
||||
#include "vector3.h"
|
||||
|
||||
#include "matrixes.h"
|
||||
#include "matrix2x2.h"
|
||||
#include "matrix2x3.h"
|
||||
#include "matrix3x3.h"
|
||||
|
||||
#include "rotation3.h"
|
||||
|
|
|
@ -2,59 +2,19 @@
|
|||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<File name="matrix3x3.c" open="1" top="1" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="quaternion.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="3207" topLine="198" />
|
||||
<Cursor1 position="1849" topLine="67" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="angle.c" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="vector2.h" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
<Cursor1 position="2293" topLine="74" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="matrix3x3.h" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="basis.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="6363" topLine="266" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="vector2.c" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1940" topLine="25" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="vector3.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="quaternion.c" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="6789" topLine="145" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="rotation3.c" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="154" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="matrix2x2.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="305" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="geometry.h" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="315" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="quaternion.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="3387" topLine="111" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="rotation3.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="305" topLine="29" />
|
||||
<Cursor1 position="103" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="angle.h" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
|
@ -62,34 +22,34 @@
|
|||
<Cursor1 position="1082" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="vector2.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="matrix3x3.c" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
<Cursor1 position="23" topLine="72" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="basis.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="matrix3x2.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="103" topLine="8" />
|
||||
<Cursor1 position="897" topLine="36" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="matrix2x3.h" open="1" top="1" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1596" topLine="54" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="matrix2x2.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="6700" topLine="238" />
|
||||
<Cursor1 position="2885" topLine="183" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="versor.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="vector3.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="3718" topLine="116" />
|
||||
<Cursor1 position="2779" topLine="79" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="basis.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="versor.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="20" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="vector3.c" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1436" topLine="15" />
|
||||
<Cursor1 position="27" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="versor.c" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
|
@ -97,4 +57,54 @@
|
|||
<Cursor1 position="504" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="quaternion.c" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="6789" topLine="145" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="vector3.c" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1436" topLine="15" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="rotation3.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="305" topLine="29" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="matrix2x2.c" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="24" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="matrix3x3.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="3618" topLine="127" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="rotation3.c" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="154" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="geometry.h" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="316" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="vector2.c" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1940" topLine="25" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="basis.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="20" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="angle.c" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
||||
|
|
|
@ -1,24 +1 @@
|
|||
#include "matrix2x2.h"
|
||||
|
||||
#include <math.h>
|
||||
#include "angle.h"
|
||||
|
||||
const SPMatrix2x2 SP_ZERO_MATRIX2X2 = {
|
||||
0.0f, 0.0f,
|
||||
0.0f, 0.0f
|
||||
};
|
||||
|
||||
const DPMatrix2x2 DP_ZERO_MATRIX2X2 = {
|
||||
0.0, 0.0,
|
||||
0.0, 0.0
|
||||
};
|
||||
|
||||
const SPMatrix2x2 SP_IDENTITY_MATRIX2X2 = {
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f
|
||||
};
|
||||
|
||||
const DPMatrix2x2 DP_IDENTITY_MATRIX2X2 = {
|
||||
1.0, 0.0,
|
||||
0.0, 1.0
|
||||
};
|
||||
|
|
159
src/matrix2x2.h
159
src/matrix2x2.h
|
@ -3,24 +3,7 @@
|
|||
|
||||
#include "angle.h"
|
||||
#include "vector2.h"
|
||||
|
||||
typedef struct {
|
||||
float r1c1, r1c2;
|
||||
float r2c1, r2c2;
|
||||
} SPMatrix2x2;
|
||||
|
||||
typedef struct {
|
||||
double r1c1, r1c2;
|
||||
double r2c1, r2c2;
|
||||
} DPMatrix2x2;
|
||||
|
||||
extern const SPMatrix2x2 SP_ZERO_MATRIX2X2;
|
||||
|
||||
extern const DPMatrix2x2 DP_ZERO_MATRIX2X2;
|
||||
|
||||
extern const SPMatrix2x2 SP_IDENTITY_MATRIX2X2;
|
||||
|
||||
extern const DPMatrix2x2 DP_IDENTITY_MATRIX2X2;
|
||||
#include "matrixes.h"
|
||||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
|
@ -124,22 +107,24 @@ static inline void dp_matrix2x2_copy(const DPMatrix2x2* from, DPMatrix2x2* to)
|
|||
|
||||
// ============= Copy to twin type ============== //
|
||||
|
||||
static inline void sp_matrix2x2_copy_to_double(const SPMatrix2x2* from, DPMatrix2x2* to)
|
||||
{
|
||||
to->r1c1 = (double)from->r1c1;
|
||||
to->r1c2 = (double)from->r1c2;
|
||||
to->r2c1 = (double)from->r2c1;
|
||||
to->r2c2 = (double)from->r2c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_copy_to_single(const DPMatrix2x2* from, SPMatrix2x2* to)
|
||||
static inline void sp_matrix2x2_set_from_double(const DPMatrix2x2* from, SPMatrix2x2* to)
|
||||
{
|
||||
to->r1c1 = (float)from->r1c1;
|
||||
to->r1c2 = (float)from->r1c2;
|
||||
|
||||
to->r2c1 = (float)from->r2c1;
|
||||
to->r2c2 = (float)from->r2c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_set_from_single(const SPMatrix2x2* from, DPMatrix2x2* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r1c2;
|
||||
|
||||
to->r2c1 = from->r2c1;
|
||||
to->r2c2 = from->r2c2;
|
||||
}
|
||||
|
||||
// ================ Determinant ================= //
|
||||
|
||||
static inline float sp_matrix2x2_get_determinant(const SPMatrix2x2* matrix)
|
||||
|
@ -232,98 +217,78 @@ static inline int dp_matrix2x2_invert(DPMatrix2x2* matrix)
|
|||
return 1;
|
||||
}
|
||||
|
||||
// =============== Make Transposed ============== //
|
||||
// =============== Set Transposed =============== //
|
||||
|
||||
static inline void sp_matrix2x2_make_transposed(const SPMatrix2x2* matrix, SPMatrix2x2* result)
|
||||
static inline void sp_matrix2x2_set_transposed(const SPMatrix2x2* from, SPMatrix2x2* to)
|
||||
{
|
||||
if (matrix == result) {
|
||||
sp_matrix2x2_transpose(result);
|
||||
return;
|
||||
}
|
||||
float tmp = from->r1c2;
|
||||
|
||||
result->r1c1 = matrix->r1c1;
|
||||
result->r1c2 = matrix->r2c1;
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
|
||||
result->r2c1 = matrix->r1c2;
|
||||
result->r2c2 = matrix->r2c2;
|
||||
to->r2c1 = tmp;
|
||||
to->r2c2 = from->r2c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_make_transposed(const DPMatrix2x2* matrix, DPMatrix2x2* result)
|
||||
static inline void dp_matrix2x2_set_transposed(const DPMatrix2x2* from, DPMatrix2x2* to)
|
||||
{
|
||||
if (matrix == result) {
|
||||
dp_matrix2x2_transpose(result);
|
||||
return;
|
||||
}
|
||||
double tmp = from->r1c2;
|
||||
|
||||
result->r1c1 = matrix->r1c1;
|
||||
result->r1c2 = matrix->r1c2;
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
|
||||
result->r2c1 = matrix->r2c1;
|
||||
result->r2c2 = matrix->r2c2;
|
||||
to->r2c1 = tmp;
|
||||
to->r2c2 = from->r2c2;
|
||||
}
|
||||
|
||||
// ================ Make Inverted =============== //
|
||||
// ================ Set Inverted ================ //
|
||||
|
||||
static inline int sp_matrix2x2_make_inverted(const SPMatrix2x2* matrix, SPMatrix2x2* result)
|
||||
static inline int sp_matrix2x2_set_inverted(const SPMatrix2x2* from, SPMatrix2x2* to)
|
||||
{
|
||||
const float determinant = sp_matrix2x2_get_determinant(matrix);
|
||||
const float determinant = sp_matrix2x2_get_determinant(from);
|
||||
|
||||
if (-SP_EPSYLON <= determinant && determinant <= SP_EPSYLON) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float r1c1 = matrix->r2c2;
|
||||
const float r1c2 = -matrix->r1c2;
|
||||
const float r1c1 = from->r2c2;
|
||||
const float r1c2 = -from->r1c2;
|
||||
|
||||
const float r2c1 = -matrix->r2c1;
|
||||
const float r2c2 = matrix->r1c1;
|
||||
const float r2c1 = -from->r2c1;
|
||||
const float r2c2 = from->r1c1;
|
||||
|
||||
result->r1c1 = r1c1 / determinant;
|
||||
result->r1c2 = r1c2 / determinant;
|
||||
to->r1c1 = r1c1 / determinant;
|
||||
to->r1c2 = r1c2 / determinant;
|
||||
|
||||
result->r2c1 = r2c1 / determinant;
|
||||
result->r2c2 = r2c2 / determinant;
|
||||
to->r2c1 = r2c1 / determinant;
|
||||
to->r2c2 = r2c2 / determinant;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline int dp_matrix2x2_make_inverted(const DPMatrix2x2* matrix, DPMatrix2x2* result)
|
||||
static inline int dp_matrix2x2_set_inverted(const DPMatrix2x2* from, DPMatrix2x2* to)
|
||||
{
|
||||
const double determinant = dp_matrix2x2_get_determinant(matrix);
|
||||
const double determinant = dp_matrix2x2_get_determinant(from);
|
||||
|
||||
if (-DP_EPSYLON <= determinant && determinant <= DP_EPSYLON) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double r1c1 = matrix->r2c2;
|
||||
const double r1c2 = -matrix->r1c2;
|
||||
const double r1c1 = from->r2c2;
|
||||
const double r1c2 = -from->r1c2;
|
||||
|
||||
const double r2c1 = -matrix->r2c1;
|
||||
const double r2c2 = matrix->r1c1;
|
||||
const double r2c1 = -from->r2c1;
|
||||
const double r2c2 = from->r1c1;
|
||||
|
||||
result->r1c1 = r1c1 / determinant;
|
||||
result->r1c2 = r1c2 / determinant;
|
||||
to->r1c1 = r1c1 / determinant;
|
||||
to->r1c2 = r1c2 / determinant;
|
||||
|
||||
result->r2c1 = r2c1 / determinant;
|
||||
result->r2c2 = r2c2 / determinant;
|
||||
to->r2c1 = r2c1 / determinant;
|
||||
to->r2c2 = r2c2 / determinant;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ================ Set Diagonal ================ //
|
||||
|
||||
static inline void sp_matrix2x2_set_main_diagonal(const float d1, const float d2, SPMatrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = d1;
|
||||
matrix->r2c2 = d2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_set_main_diagonal(const double d1, const double d2, DPMatrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = d1;
|
||||
matrix->r2c2 = d2;
|
||||
}
|
||||
|
||||
// ================= Set Row 1 ================== //
|
||||
|
||||
static inline void sp_matrix2x2_set_row1(const float c1, const float c2, SPMatrix2x2* matrix)
|
||||
|
@ -720,36 +685,4 @@ static inline void dp_matrix2x2_right_product(const DPMatrix2x2* matrix, const D
|
|||
);
|
||||
}
|
||||
|
||||
// =============== Matrix Product =============== //
|
||||
|
||||
static inline void sp_matrix2x2_matrix_product(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_matrix2x2_matrix_product(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;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
141
src/matrix2x3.h
Normal file
141
src/matrix2x3.h
Normal file
|
@ -0,0 +1,141 @@
|
|||
#ifndef _GEOMETRY_MATRIX2X3_H_
|
||||
#define _GEOMETRY_MATRIX2X3_H_
|
||||
|
||||
#include "vector2.h"
|
||||
#include "vector3.h"
|
||||
#include "matrixes.h"
|
||||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
static inline void sp_matrix2x3_reset(SPMatrix2x3* matrix)
|
||||
{
|
||||
matrix->r1c1 = 0.0f;
|
||||
matrix->r1c2 = 0.0f;
|
||||
|
||||
matrix->r2c1 = 0.0f;
|
||||
matrix->r2c2 = 0.0f;
|
||||
|
||||
matrix->r3c1 = 0.0f;
|
||||
matrix->r3c2 = 0.0f;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_reset(DPMatrix2x3* matrix)
|
||||
{
|
||||
matrix->r1c1 = 0.0;
|
||||
matrix->r1c2 = 0.0;
|
||||
|
||||
matrix->r2c1 = 0.0;
|
||||
matrix->r2c2 = 0.0;
|
||||
|
||||
matrix->r3c1 = 0.0;
|
||||
matrix->r3c2 = 0.0;
|
||||
}
|
||||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
static inline void sp_matrix2x3_copy(const SPMatrix2x3* from, SPMatrix2x3* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r1c2;
|
||||
to->r1c3 = from->r1c3;
|
||||
|
||||
to->r2c1 = from->r2c1;
|
||||
to->r2c2 = from->r2c2;
|
||||
to->r2c3 = from->r2c3;
|
||||
|
||||
to->r3c1 = from->r3c1;
|
||||
to->r3c2 = from->r3c2;
|
||||
to->r3c3 = from->r3c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_copy(const DPMatrix2x3* from, DPMatrix2x3* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r1c2;
|
||||
|
||||
to->r2c1 = from->r2c1;
|
||||
to->r2c2 = from->r2c2;
|
||||
|
||||
to->r3c1 = from->r3c1;
|
||||
to->r3c2 = from->r3c2;
|
||||
}
|
||||
|
||||
// ============= Copy to twin type ============== //
|
||||
|
||||
static inline void sp_matrix2x3_set_from_double(const DPMatrix2x3* from, SPMatrix2x3* to)
|
||||
{
|
||||
to->r1c1 = (float) from->r1c1;
|
||||
to->r1c2 = (float) from->r1c2;
|
||||
|
||||
to->r2c1 = (float) from->r2c1;
|
||||
to->r2c2 = (float) from->r2c2;
|
||||
|
||||
to->r3c1 = (float) from->r3c1;
|
||||
to->r3c2 = (float) from->r3c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_set_from_single(const SPMatrix2x3* from, DPMatrix2x3* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r1c2;
|
||||
|
||||
to->r2c1 = from->r2c1;
|
||||
to->r2c2 = from->r2c2;
|
||||
|
||||
to->r3c1 = from->r3c1;
|
||||
to->r3c2 = from->r3c2;
|
||||
}
|
||||
|
||||
// =============== Set transposed =============== //
|
||||
|
||||
static inline void sp_matrix2x3_set_transposed(const SPMatrix3x2* from, SPMatrix2x3* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
|
||||
to->r2c1 = from->r1c2;
|
||||
to->r2c2 = from->r2c2;
|
||||
|
||||
to->r3c1 = from->r1c3;
|
||||
to->r3c2 = from->r2c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_set_transposed(const DPMatrix3x2* from, DPMatrix2x3* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
|
||||
to->r2c1 = from->r1c2;
|
||||
to->r2c2 = from->r2c2;
|
||||
|
||||
to->r3c1 = from->r1c3;
|
||||
to->r3c2 = from->r2c3;
|
||||
}
|
||||
|
||||
// =============== Set transposed =============== //
|
||||
|
||||
static inline void sp_matrix2x3_transpose_double(const DPMatrix3x2* from, SPMatrix2x3* to)
|
||||
{
|
||||
to->r1c1 = (float) from->r1c1;
|
||||
to->r1c2 = (float) from->r2c1;
|
||||
|
||||
to->r2c1 = (float) from->r1c2;
|
||||
to->r2c2 = (float) from->r2c2;
|
||||
|
||||
to->r3c1 = (float) from->r1c3;
|
||||
to->r3c2 = (float) from->r2c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_transpose_single(const SPMatrix3x2* from, DPMatrix2x3* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
|
||||
to->r2c1 = from->r1c2;
|
||||
to->r2c2 = from->r2c2;
|
||||
|
||||
to->r3c1 = from->r1c3;
|
||||
to->r3c2 = from->r2c3;
|
||||
}
|
||||
|
||||
#endif
|
100
src/matrix3x2.h
Normal file
100
src/matrix3x2.h
Normal file
|
@ -0,0 +1,100 @@
|
|||
#ifndef _GEOMETRY_MATRIX3X2_H_
|
||||
#define _GEOMETRY_MATRIX3X2_H_
|
||||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
static inline void sp_matrix3x2_reset(SPMatrix3x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = 0.0f;
|
||||
matrix->r1c2 = 0.0f;
|
||||
matrix->r1c3 = 0.0f;
|
||||
|
||||
matrix->r2c1 = 0.0f;
|
||||
matrix->r2c2 = 0.0f;
|
||||
matrix->r2c3 = 0.0f;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x2_reset(DPMatrix3x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = 0.0;
|
||||
matrix->r1c2 = 0.0;
|
||||
matrix->r1c3 = 0.0;
|
||||
|
||||
matrix->r2c1 = 0.0;
|
||||
matrix->r2c2 = 0.0;
|
||||
matrix->r2c3 = 0.0;
|
||||
}
|
||||
|
||||
// ============= Set from twin type ============= //
|
||||
|
||||
static inline void sp_matrix3x2_set_from_double(const DPMatrix3x2* from, SPMatrix3x2* to)
|
||||
{
|
||||
to->r1c1 = (float) from->r1c1;
|
||||
to->r1c2 = (float) from->r1c2;
|
||||
to->r1c3 = (float) from->r1c3;
|
||||
|
||||
to->r2c1 = (float) from->r2c1;
|
||||
to->r2c2 = (float) from->r2c2;
|
||||
to->r2c3 = (float) from->r2c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x2_set_from_single(const SPMatrix3x2* from, DPMatrix3x2* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r1c2;
|
||||
to->r1c3 = from->r1c3;
|
||||
|
||||
to->r2c1 = from->r2c1;
|
||||
to->r2c2 = from->r2c2;
|
||||
to->r2c3 = from->r2c3;
|
||||
}
|
||||
|
||||
// =============== Set transposed =============== //
|
||||
|
||||
static inline void sp_matrix3x2_set_transposed(const SPMatrix2x3* from, SPMatrix3x2* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
to->r1c3 = from->r3c1;
|
||||
|
||||
to->r2c1 = from->r1c2;
|
||||
to->r2c2 = from->r2c2;
|
||||
to->r2c3 = from->r3c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x2_set_transposed(const DPMatrix2x3* from, DPMatrix3x2* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
to->r1c3 = from->r3c1;
|
||||
|
||||
to->r2c1 = from->r1c2;
|
||||
to->r2c2 = from->r2c2;
|
||||
to->r2c3 = from->r3c2;
|
||||
}
|
||||
|
||||
// =============== Set transposed =============== //
|
||||
|
||||
static inline void sp_matrix3x2_transpose_double(const DPMatrix2x3* from, SPMatrix3x2* to)
|
||||
{
|
||||
to->r1c1 = (float) from->r1c1;
|
||||
to->r1c2 = (float) from->r2c1;
|
||||
to->r1c3 = (float) from->r3c1;
|
||||
|
||||
to->r2c1 = (float) from->r1c2;
|
||||
to->r2c2 = (float) from->r2c2;
|
||||
to->r2c3 = (float) from->r3c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x2_transpose_single(const SPMatrix2x3* from, DPMatrix3x2* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
to->r1c3 = from->r3c1;
|
||||
|
||||
to->r2c1 = from->r1c2;
|
||||
to->r2c2 = from->r2c2;
|
||||
to->r2c3 = from->r3c2;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,29 +1,5 @@
|
|||
#include "matrix3x3.h"
|
||||
|
||||
const SPMatrix3x3 SP_ZERO_MATRIX3X3 = {
|
||||
0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f
|
||||
};
|
||||
|
||||
const DPMatrix3x3 DP_ZERO_MATRIX3X3 = {
|
||||
0.0, 0.0, 0.0,
|
||||
0.0, 0.0, 0.0,
|
||||
0.0, 0.0, 0.0
|
||||
};
|
||||
|
||||
const SPMatrix3x3 SP_IDENTITY_MATRIX3X3 = {
|
||||
1.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f
|
||||
};
|
||||
|
||||
const DPMatrix3x3 DP_IDENTITY_MATRIX3X3 = {
|
||||
1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0
|
||||
};
|
||||
|
||||
// ================= Inversion ================== //
|
||||
|
||||
int sp_matrix3x3_invert(SPMatrix3x3* matrix)
|
||||
|
@ -339,59 +315,3 @@ void dp_matrix3x3_get_weighted_sum5(
|
|||
sum->r3c2 = (matrix1->r3c2 * weight1 + matrix2->r3c2 * weight2) + (matrix3->r3c2 * weight3 + matrix4->r3c2 * weight4) + matrix5->r3c2 * weight5;
|
||||
sum->r3c3 = (matrix1->r3c3 * weight1 + matrix2->r3c3 * weight2) + (matrix3->r3c3 * weight3 + matrix4->r3c3 * weight4) + matrix5->r3c3 * weight5;
|
||||
}
|
||||
|
||||
// =============== Matrix Product =============== //
|
||||
|
||||
void sp_matrix3x3_matrix_product(const SPMatrix3x3* matrix1, const SPMatrix3x3* matrix2, SPMatrix3x3* result)
|
||||
{
|
||||
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||
const float r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3 + matrix1->r1c3 * matrix2->r3c3;
|
||||
|
||||
const float r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1;
|
||||
const float r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2;
|
||||
const float r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3 + matrix1->r2c3 * matrix2->r3c3;
|
||||
|
||||
const float r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1 + matrix1->r3c3 * matrix2->r3c1;
|
||||
const float r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2 + matrix1->r3c3 * matrix2->r3c2;
|
||||
const float r3c3 = matrix1->r3c1 * matrix2->r1c3 + matrix1->r3c2 * matrix2->r2c3 + matrix1->r3c3 * matrix2->r3c3;
|
||||
|
||||
result->r1c1 = r1c1;
|
||||
result->r1c2 = r1c2;
|
||||
result->r1c3 = r1c3;
|
||||
|
||||
result->r2c1 = r2c1;
|
||||
result->r2c2 = r2c2;
|
||||
result->r2c3 = r2c3;
|
||||
|
||||
result->r3c1 = r3c1;
|
||||
result->r3c2 = r3c2;
|
||||
result->r3c3 = r3c3;
|
||||
}
|
||||
|
||||
void dp_matrix3x3_matrix_product(const DPMatrix3x3* matrix1, const DPMatrix3x3* matrix2, DPMatrix3x3* result)
|
||||
{
|
||||
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||
const double r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3 + matrix1->r1c3 * matrix2->r3c3;
|
||||
|
||||
const double r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1;
|
||||
const double r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2;
|
||||
const double r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3 + matrix1->r2c3 * matrix2->r3c3;
|
||||
|
||||
const double r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1 + matrix1->r3c3 * matrix2->r3c1;
|
||||
const double r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2 + matrix1->r3c3 * matrix2->r3c2;
|
||||
const double r3c3 = matrix1->r3c1 * matrix2->r1c3 + matrix1->r3c2 * matrix2->r2c3 + matrix1->r3c3 * matrix2->r3c3;
|
||||
|
||||
result->r1c1 = r1c1;
|
||||
result->r1c2 = r1c2;
|
||||
result->r1c3 = r1c3;
|
||||
|
||||
result->r2c1 = r2c1;
|
||||
result->r2c2 = r2c2;
|
||||
result->r2c3 = r2c3;
|
||||
|
||||
result->r3c1 = r3c1;
|
||||
result->r3c2 = r3c2;
|
||||
result->r3c3 = r3c3;
|
||||
}
|
||||
|
|
|
@ -2,26 +2,7 @@
|
|||
#define _GEOMETRY_MATRIX3X3_H_
|
||||
|
||||
#include "vector3.h"
|
||||
|
||||
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;
|
||||
|
||||
extern const SPMatrix3x3 SP_ZERO_MATRIX3X3;
|
||||
|
||||
extern const DPMatrix3x3 DP_ZERO_MATRIX3X3;
|
||||
|
||||
extern const SPMatrix3x3 SP_IDENTITY_MATRIX3X3;
|
||||
|
||||
extern const DPMatrix3x3 DP_IDENTITY_MATRIX3X3;
|
||||
#include "matrixes.h"
|
||||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
|
@ -151,24 +132,9 @@ static inline void dp_matrix3x3_copy(const DPMatrix3x3* from, DPMatrix3x3* to)
|
|||
to->r3c3 = from->r3c3;
|
||||
}
|
||||
|
||||
// ============= Copy to twin type ============== //
|
||||
// ============= Set from twin type ============= //
|
||||
|
||||
static inline void sp_matrix3x3_copy_to_double(const SPMatrix3x3* from, DPMatrix3x3* to)
|
||||
{
|
||||
to->r1c1 = (double)from->r1c1;
|
||||
to->r1c2 = (double)from->r1c2;
|
||||
to->r1c3 = (double)from->r1c3;
|
||||
|
||||
to->r2c1 = (double)from->r2c1;
|
||||
to->r2c2 = (double)from->r2c2;
|
||||
to->r2c3 = (double)from->r2c3;
|
||||
|
||||
to->r3c1 = (double)from->r3c1;
|
||||
to->r3c2 = (double)from->r3c2;
|
||||
to->r3c3 = (double)from->r3c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_copy_to_single(const DPMatrix3x3* from, SPMatrix3x3* to)
|
||||
static inline void sp_matrix3x3_set_from_double(const DPMatrix3x3* from, SPMatrix3x3* to)
|
||||
{
|
||||
to->r1c1 = (float)from->r1c1;
|
||||
to->r1c2 = (float)from->r1c2;
|
||||
|
@ -183,6 +149,21 @@ static inline void dp_matrix3x3_copy_to_single(const DPMatrix3x3* from, SPMatrix
|
|||
to->r3c3 = (float)from->r3c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_set_from_single(const SPMatrix3x3* from, DPMatrix3x3* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r1c2;
|
||||
to->r1c3 = from->r1c3;
|
||||
|
||||
to->r2c1 = from->r2c1;
|
||||
to->r2c2 = from->r2c2;
|
||||
to->r2c3 = from->r2c3;
|
||||
|
||||
to->r3c1 = from->r3c1;
|
||||
to->r3c2 = from->r3c2;
|
||||
to->r3c3 = from->r3c3;
|
||||
}
|
||||
|
||||
// ================ Determinant ================= //
|
||||
|
||||
static inline float sp_matrix3x3_get_determinant(const SPMatrix3x3* matrix)
|
||||
|
@ -785,10 +766,4 @@ static inline void dp_matrix3x3_right_product(const DPMatrix3x3* matrix, const D
|
|||
);
|
||||
}
|
||||
|
||||
// =============== Matrix Product =============== //
|
||||
|
||||
void sp_matrix3x3_matrix_product(const SPMatrix3x3* matrix1, const SPMatrix3x3* matrix2, SPMatrix3x3* result);
|
||||
|
||||
void dp_matrix3x3_matrix_product(const DPMatrix3x3* matrix1, const DPMatrix3x3* matrix2, DPMatrix3x3* result);
|
||||
|
||||
#endif
|
||||
|
|
257
src/matrixes.c
Normal file
257
src/matrixes.c
Normal file
|
@ -0,0 +1,257 @@
|
|||
#include "matrixes.h"
|
||||
|
||||
// ========== Matrix Product 2x2 at 3x2 ========= //
|
||||
|
||||
void sp_matrix_product_2x2_at_3x2(const SPMatrix2x2* matrix1, const SPMatrix3x2* matrix2, SPMatrix3x2* 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 r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3;
|
||||
|
||||
const float r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1;
|
||||
const float r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2;
|
||||
const float r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3;
|
||||
|
||||
result->r1c1 = r1c1;
|
||||
result->r1c2 = r1c2;
|
||||
result->r1c3 = r1c3;
|
||||
|
||||
result->r2c1 = r2c1;
|
||||
result->r2c2 = r2c2;
|
||||
result->r2c3 = r2c3;
|
||||
}
|
||||
|
||||
void dp_matrix_product_2x2_at_3x2(const DPMatrix2x2* matrix1, const DPMatrix3x2* matrix2, DPMatrix3x2* 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 r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3;
|
||||
|
||||
const double r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1;
|
||||
const double r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2;
|
||||
const double r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3;
|
||||
|
||||
result->r1c1 = r1c1;
|
||||
result->r1c2 = r1c2;
|
||||
result->r1c3 = r1c3;
|
||||
|
||||
result->r2c1 = r2c1;
|
||||
result->r2c2 = r2c2;
|
||||
result->r2c3 = r2c3;
|
||||
}
|
||||
|
||||
// ========== Matrix Product 2x3 at 2x2 ========= //
|
||||
|
||||
void sp_matrix_product_2x3_at_2x2(const SPMatrix2x3* matrix1, const SPMatrix2x2* matrix2, SPMatrix2x3* 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;
|
||||
|
||||
const float r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1;
|
||||
const float r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2;
|
||||
|
||||
result->r1c1 = r1c1;
|
||||
result->r1c2 = r1c2;
|
||||
|
||||
result->r2c1 = r2c1;
|
||||
result->r2c2 = r2c2;
|
||||
|
||||
result->r3c1 = r3c1;
|
||||
result->r3c2 = r3c2;
|
||||
}
|
||||
|
||||
void dp_matrix_product_2x3_at_2x2(const DPMatrix2x3* matrix1, const DPMatrix2x2* matrix2, DPMatrix2x3* 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;
|
||||
|
||||
const double r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1;
|
||||
const double r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2;
|
||||
|
||||
result->r1c1 = r1c1;
|
||||
result->r1c2 = r1c2;
|
||||
|
||||
result->r2c1 = r2c1;
|
||||
result->r2c2 = r2c2;
|
||||
|
||||
result->r3c1 = r3c1;
|
||||
result->r3c2 = r3c2;
|
||||
}
|
||||
|
||||
// ========== Matrix Product 2x3 at 3x2 ========= //
|
||||
|
||||
void sp_matrix_product_2x3_at_3x2(const SPMatrix2x3* matrix1, const SPMatrix3x2* matrix2, SPMatrix3x3* result)
|
||||
{
|
||||
result->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
||||
result->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
||||
result->r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3;
|
||||
|
||||
result->r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1;
|
||||
result->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2;
|
||||
result->r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3;
|
||||
|
||||
result->r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1;
|
||||
result->r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2;
|
||||
result->r3c3 = matrix1->r3c1 * matrix2->r1c3 + matrix1->r3c2 * matrix2->r2c3;
|
||||
}
|
||||
|
||||
void dp_matrix_product_2x3_at_3x2(const DPMatrix2x3* matrix1, const DPMatrix3x2* matrix2, DPMatrix3x3* result)
|
||||
{
|
||||
result->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
||||
result->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
||||
result->r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3;
|
||||
|
||||
result->r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1;
|
||||
result->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2;
|
||||
result->r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3;
|
||||
|
||||
result->r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1;
|
||||
result->r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2;
|
||||
result->r3c3 = matrix1->r3c1 * matrix2->r1c3 + matrix1->r3c2 * matrix2->r2c3;
|
||||
}
|
||||
|
||||
// ========== Matrix Product 3x2 at 3x3 ========= //
|
||||
|
||||
void sp_matrix_product_3x2_at_3x3(const SPMatrix3x2* matrix1, const SPMatrix3x3* matrix2, SPMatrix3x2* result)
|
||||
{
|
||||
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||
const float r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3 + matrix1->r1c3 * matrix2->r3c3;
|
||||
|
||||
const float r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1;
|
||||
const float r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2;
|
||||
const float r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3 + matrix1->r2c3 * matrix2->r3c3;
|
||||
|
||||
result->r1c1 = r1c1;
|
||||
result->r1c2 = r1c2;
|
||||
result->r1c3 = r1c3;
|
||||
|
||||
result->r2c1 = r2c1;
|
||||
result->r2c2 = r2c2;
|
||||
result->r2c3 = r2c3;
|
||||
}
|
||||
|
||||
void dp_matrix_product_3x2_at_3x3(const DPMatrix3x2* matrix1, const DPMatrix3x3* matrix2, DPMatrix3x2* result)
|
||||
{
|
||||
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||
const float r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3 + matrix1->r1c3 * matrix2->r3c3;
|
||||
|
||||
const float r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1;
|
||||
const float r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2;
|
||||
const float r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3 + matrix1->r2c3 * matrix2->r3c3;
|
||||
|
||||
result->r1c1 = r1c1;
|
||||
result->r1c2 = r1c2;
|
||||
result->r1c3 = r1c3;
|
||||
|
||||
result->r2c1 = r2c1;
|
||||
result->r2c2 = r2c2;
|
||||
result->r2c3 = r2c3;
|
||||
}
|
||||
|
||||
// ========== Matrix Product 3x3 at 2x3 ========= //
|
||||
|
||||
void sp_matrix_product_3x3_at_2x3(const SPMatrix3x3* matrix1, const SPMatrix2x3* matrix2, SPMatrix2x3* result)
|
||||
{
|
||||
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||
|
||||
const double r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1;
|
||||
const double r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2;
|
||||
|
||||
const double r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1 + matrix1->r3c3 * matrix2->r3c1;
|
||||
const double r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2 + matrix1->r3c3 * matrix2->r3c2;
|
||||
|
||||
result->r1c1 = r1c1;
|
||||
result->r1c2 = r1c2;
|
||||
|
||||
result->r2c1 = r2c1;
|
||||
result->r2c2 = r2c2;
|
||||
|
||||
result->r3c1 = r3c1;
|
||||
result->r3c2 = r3c2;
|
||||
}
|
||||
|
||||
void dp_matrix_product_3x3_at_2x3(const DPMatrix3x3* matrix1, const DPMatrix2x3* matrix2, DPMatrix2x3* result)
|
||||
{
|
||||
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||
|
||||
const double r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1;
|
||||
const double r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2;
|
||||
|
||||
const double r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1 + matrix1->r3c3 * matrix2->r3c1;
|
||||
const double r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2 + matrix1->r3c3 * matrix2->r3c2;
|
||||
|
||||
result->r1c1 = r1c1;
|
||||
result->r1c2 = r1c2;
|
||||
|
||||
result->r2c1 = r2c1;
|
||||
result->r2c2 = r2c2;
|
||||
|
||||
result->r3c1 = r3c1;
|
||||
result->r3c2 = r3c2;
|
||||
}
|
||||
|
||||
// ========== Matrix Product 3x3 at 3x3 ========= //
|
||||
|
||||
void sp_matrix_product_3x3_at_3x3(const SPMatrix3x3* matrix1, const SPMatrix3x3* matrix2, SPMatrix3x3* result)
|
||||
{
|
||||
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||
const float r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3 + matrix1->r1c3 * matrix2->r3c3;
|
||||
|
||||
const float r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1;
|
||||
const float r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2;
|
||||
const float r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3 + matrix1->r2c3 * matrix2->r3c3;
|
||||
|
||||
const float r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1 + matrix1->r3c3 * matrix2->r3c1;
|
||||
const float r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2 + matrix1->r3c3 * matrix2->r3c2;
|
||||
const float r3c3 = matrix1->r3c1 * matrix2->r1c3 + matrix1->r3c2 * matrix2->r2c3 + matrix1->r3c3 * matrix2->r3c3;
|
||||
|
||||
result->r1c1 = r1c1;
|
||||
result->r1c2 = r1c2;
|
||||
result->r1c3 = r1c3;
|
||||
|
||||
result->r2c1 = r2c1;
|
||||
result->r2c2 = r2c2;
|
||||
result->r2c3 = r2c3;
|
||||
|
||||
result->r3c1 = r3c1;
|
||||
result->r3c2 = r3c2;
|
||||
result->r3c3 = r3c3;
|
||||
}
|
||||
|
||||
void dp_matrix_product_3x3_at_3x3(const DPMatrix3x3* matrix1, const DPMatrix3x3* matrix2, DPMatrix3x3* result)
|
||||
{
|
||||
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||
const double r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3 + matrix1->r1c3 * matrix2->r3c3;
|
||||
|
||||
const double r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1;
|
||||
const double r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2;
|
||||
const double r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3 + matrix1->r2c3 * matrix2->r3c3;
|
||||
|
||||
const double r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1 + matrix1->r3c3 * matrix2->r3c1;
|
||||
const double r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2 + matrix1->r3c3 * matrix2->r3c2;
|
||||
const double r3c3 = matrix1->r3c1 * matrix2->r1c3 + matrix1->r3c2 * matrix2->r2c3 + matrix1->r3c3 * matrix2->r3c3;
|
||||
|
||||
result->r1c1 = r1c1;
|
||||
result->r1c2 = r1c2;
|
||||
result->r1c3 = r1c3;
|
||||
|
||||
result->r2c1 = r2c1;
|
||||
result->r2c2 = r2c2;
|
||||
result->r2c3 = r2c3;
|
||||
|
||||
result->r3c1 = r3c1;
|
||||
result->r3c2 = r3c2;
|
||||
result->r3c3 = r3c3;
|
||||
}
|
144
src/matrixes.h
Normal file
144
src/matrixes.h
Normal 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_
|
|
@ -32,9 +32,27 @@ static inline void dp_quaternion_reset(DPQuaternion * quaternion)
|
|||
quaternion->x3 = 0.0;
|
||||
}
|
||||
|
||||
// ================== Set Unit ================== //
|
||||
|
||||
static inline void sp_quaternion_set_identity(SPQuaternion * quaternion)
|
||||
{
|
||||
quaternion->s0 = 1.0f;
|
||||
quaternion->x1 = 0.0f;
|
||||
quaternion->x2 = 0.0f;
|
||||
quaternion->x3 = 0.0f;
|
||||
}
|
||||
|
||||
static inline void dp_quaternion_set_identity(DPQuaternion * quaternion)
|
||||
{
|
||||
quaternion->s0 = 1.0;
|
||||
quaternion->x1 = 0.0;
|
||||
quaternion->x2 = 0.0;
|
||||
quaternion->x3 = 0.0;
|
||||
}
|
||||
|
||||
// ==================== Set ===================== //
|
||||
|
||||
static inline void sp_quaternion_set(const float s0, const float x1, const float x2, const float x3, SPQuaternion * quaternion)
|
||||
static inline void sp_quaternion_set_values(const float s0, const float x1, const float x2, const float x3, SPQuaternion * quaternion)
|
||||
{
|
||||
quaternion->s0 = s0;
|
||||
quaternion->x1 = x1;
|
||||
|
@ -42,7 +60,7 @@ static inline void sp_quaternion_set(const float s0, const float x1, const float
|
|||
quaternion->x3 = x3;
|
||||
}
|
||||
|
||||
static inline void dp_quaternion_set(const double s0, const double x1, const double x2, const double x3, DPQuaternion * quaternion)
|
||||
static inline void dp_quaternion_set_values(const double s0, const double x1, const double x2, const double x3, DPQuaternion * quaternion)
|
||||
{
|
||||
quaternion->s0 = s0;
|
||||
quaternion->x1 = x1;
|
||||
|
@ -70,15 +88,7 @@ static inline void dp_quaternion_copy(const DPQuaternion* from, DPQuaternion* to
|
|||
|
||||
// ============= Copy to twin type ============== //
|
||||
|
||||
static inline void sp_quaternion_copy_to_double(const SPQuaternion* versor, DPQuaternion* result)
|
||||
{
|
||||
result->s0 = (double)versor->s0;
|
||||
result->x1 = (double)versor->x1;
|
||||
result->x2 = (double)versor->x2;
|
||||
result->x3 = (double)versor->x3;
|
||||
}
|
||||
|
||||
static inline void dp_quaternion_copy_to_single(const DPQuaternion* versor, SPQuaternion* result)
|
||||
static inline void sp_quaternion_copy_from_double(const DPQuaternion* versor, SPQuaternion* result)
|
||||
{
|
||||
result->s0 = (float)versor->s0;
|
||||
result->x1 = (float)versor->x1;
|
||||
|
@ -86,6 +96,14 @@ static inline void dp_quaternion_copy_to_single(const DPQuaternion* versor, SPQu
|
|||
result->x3 = (float)versor->x3;
|
||||
}
|
||||
|
||||
static inline void dp_quaternion_copy_from_single(const SPQuaternion* versor, DPQuaternion* result)
|
||||
{
|
||||
result->s0 = versor->s0;
|
||||
result->x1 = versor->x1;
|
||||
result->x2 = versor->x2;
|
||||
result->x3 = versor->x3;
|
||||
}
|
||||
|
||||
// ================= Inversion ================== //
|
||||
|
||||
static inline void sp_quaternion_conjugate(SPQuaternion* versor)
|
||||
|
@ -102,9 +120,9 @@ static inline void dp_quaternion_conjugate(DPQuaternion* versor)
|
|||
versor->x3 = -versor->x3;
|
||||
}
|
||||
|
||||
// ================ Get Inverted ================ //
|
||||
// ================ Set Conjugate =============== //
|
||||
|
||||
static inline void sp_quaternion_get_conjugate(const SPQuaternion* versor, SPQuaternion* result)
|
||||
static inline void sp_quaternion_set_conjugate(const SPQuaternion* versor, SPQuaternion* result)
|
||||
{
|
||||
result->s0 = versor->s0;
|
||||
result->x1 = -versor->x1;
|
||||
|
@ -112,7 +130,25 @@ static inline void sp_quaternion_get_conjugate(const SPQuaternion* versor, SPQua
|
|||
result->x3 = -versor->x3;
|
||||
}
|
||||
|
||||
static inline void dp_quaternion_get_conjugate(const DPQuaternion* versor, DPQuaternion* result)
|
||||
static inline void dp_quaternion_set_conjugate(const DPQuaternion* versor, DPQuaternion* result)
|
||||
{
|
||||
result->s0 = versor->s0;
|
||||
result->x1 = -versor->x1;
|
||||
result->x2 = -versor->x2;
|
||||
result->x3 = -versor->x3;
|
||||
}
|
||||
|
||||
// ================ Get Inverted ================ //
|
||||
|
||||
static inline void sp_quaternion_conjugate_double(const DPQuaternion* versor, SPQuaternion* result)
|
||||
{
|
||||
result->s0 = (float)versor->s0;
|
||||
result->x1 = -(float)versor->x1;
|
||||
result->x2 = -(float)versor->x2;
|
||||
result->x3 = -(float)versor->x3;
|
||||
}
|
||||
|
||||
static inline void dp_quaternion_conjugate_single(const SPQuaternion* versor, DPQuaternion* result)
|
||||
{
|
||||
result->s0 = versor->s0;
|
||||
result->x1 = -versor->x1;
|
||||
|
|
|
@ -38,6 +38,20 @@ static inline void dp_vector2_reset(DPVector2* vector)
|
|||
vector->x2 = 0.0;
|
||||
}
|
||||
|
||||
// ==================== Set ===================== //
|
||||
|
||||
static inline void sp_vector2_set_values(const float x1, const float x2, SPVector2* to)
|
||||
{
|
||||
to->x1 = x1;
|
||||
to->x2 = x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_set_values(const double x1, const double x2, DPVector2* to)
|
||||
{
|
||||
to->x1 = x1;
|
||||
to->x2 = x2;
|
||||
}
|
||||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
static inline void sp_vector2_copy(const SPVector2* from, SPVector2* to)
|
||||
|
@ -52,18 +66,46 @@ static inline void dp_vector2_copy(const DPVector2* from, DPVector2* to)
|
|||
to->x2 = from->x2;
|
||||
}
|
||||
|
||||
// ==================== Set ===================== //
|
||||
// ============= Copy to twin type ============== //
|
||||
|
||||
static inline void sp_vector2_set(const float x1, const float x2, SPVector2* to)
|
||||
static inline void sp_vector2_copy_from_double(const DPVector2* from, SPVector2* to)
|
||||
{
|
||||
to->x1 = x1;
|
||||
to->x2 = x2;
|
||||
to->x1 = (float)from->x1;
|
||||
to->x2 = (float)from->x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_set(const double x1, const double x2, DPVector2* to)
|
||||
static inline void dp_vector2_copy_from_single(const SPVector2* from, DPVector2* to)
|
||||
{
|
||||
to->x1 = x1;
|
||||
to->x2 = x2;
|
||||
to->x1 = from->x1;
|
||||
to->x2 = from->x2;
|
||||
}
|
||||
|
||||
// =================== Reverse ================== //
|
||||
|
||||
static inline void sp_vector2_reverse(const SPVector2* from, SPVector2* to)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_reverse(const DPVector2* from, DPVector2* to)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
}
|
||||
|
||||
// ============= Reverse twin type ============== //
|
||||
|
||||
static inline void sp_vector2_reverse_double(const DPVector2* from, SPVector2* to)
|
||||
{
|
||||
to->x1 = -(float)from->x1;
|
||||
to->x2 = -(float)from->x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_reverse_single(const SPVector2* from, DPVector2* to)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
}
|
||||
|
||||
// =================== Module =================== //
|
||||
|
@ -114,48 +156,6 @@ static inline int dp_vector2_is_unit(const DPVector2* vector)
|
|||
return 1.0f - DP_TWO_EPSYLON <= square_module && square_module <= 1.0f + DP_TWO_EPSYLON;
|
||||
}
|
||||
|
||||
// ============= Copy to twin type ============== //
|
||||
|
||||
static inline void sp_vector2_copy_to_double(const SPVector2* from, DPVector2* to)
|
||||
{
|
||||
to->x1 = (double)from->x1;
|
||||
to->x2 = (double)from->x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_copy_to_single(const DPVector2* from, SPVector2* to)
|
||||
{
|
||||
to->x1 = (float)from->x1;
|
||||
to->x2 = (float)from->x2;
|
||||
}
|
||||
|
||||
// ================= Inversion ================== //
|
||||
|
||||
static inline void sp_vector2_invert(SPVector2* vector)
|
||||
{
|
||||
vector->x1 = -vector->x1;
|
||||
vector->x2 = -vector->x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_invert(DPVector2* vector)
|
||||
{
|
||||
vector->x1 = -vector->x1;
|
||||
vector->x2 = -vector->x2;
|
||||
}
|
||||
|
||||
// ================ Get Inverted ================ //
|
||||
|
||||
static inline void sp_vector2_get_inverted(const SPVector2* vector, SPVector2* result)
|
||||
{
|
||||
result->x1 = -vector->x1;
|
||||
result->x2 = -vector->x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_get_inverted(const DPVector2* vector, DPVector2* result)
|
||||
{
|
||||
result->x1 = -vector->x1;
|
||||
result->x2 = -vector->x2;
|
||||
}
|
||||
|
||||
// ==================== Add ===================== //
|
||||
|
||||
static inline void sp_vector2_add(const SPVector2* vector1, const SPVector2* vector2, SPVector2* result)
|
||||
|
|
114
src/vector3.h
114
src/vector3.h
|
@ -44,6 +44,22 @@ static inline void dp_vector3_reset(DPVector3* vector)
|
|||
vector->x3 = 0.0;
|
||||
}
|
||||
|
||||
// ==================== Set ===================== //
|
||||
|
||||
static inline void sp_vector3_set_values(const float x1, const float x2, const float x3, SPVector3* to)
|
||||
{
|
||||
to->x1 = x1;
|
||||
to->x2 = x2;
|
||||
to->x3 = x3;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_set_values(const double x1, const double x2, const double x3, DPVector3* to)
|
||||
{
|
||||
to->x1 = x1;
|
||||
to->x2 = x2;
|
||||
to->x3 = x3;
|
||||
}
|
||||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
static inline void sp_vector3_copy(const SPVector3* from, SPVector3* to)
|
||||
|
@ -60,20 +76,52 @@ static inline void dp_vector3_copy(const DPVector3* from, DPVector3* to)
|
|||
to->x3 = from->x3;
|
||||
}
|
||||
|
||||
// ==================== Set ===================== //
|
||||
// ============= Copy to twin type ============== //
|
||||
|
||||
static inline void sp_vector3_set(const float x1, const float x2, const float x3, SPVector3* to)
|
||||
static inline void sp_vector3_copy_from_double(const DPVector3* from, SPVector3* to)
|
||||
{
|
||||
to->x1 = x1;
|
||||
to->x2 = x2;
|
||||
to->x3 = x3;
|
||||
to->x1 = (float)from->x1;
|
||||
to->x2 = (float)from->x2;
|
||||
to->x3 = (float)from->x3;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_set(const double x1, const double x2, const double x3, DPVector3* to)
|
||||
static inline void dp_vector3_copy_from_single(const SPVector3* from, DPVector3* to)
|
||||
{
|
||||
to->x1 = x1;
|
||||
to->x2 = x2;
|
||||
to->x3 = x3;
|
||||
to->x1 = from->x1;
|
||||
to->x2 = from->x2;
|
||||
to->x3 = from->x3;
|
||||
}
|
||||
|
||||
// =================== Reverse ================== //
|
||||
|
||||
static inline void sp_vector3_reverse(const SPVector3* from, SPVector3* to)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
to->x3 = -from->x3;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_reverse(const DPVector3* from, DPVector3* to)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
to->x3 = -from->x3;
|
||||
}
|
||||
|
||||
// ============= Reverse twin type ============== //
|
||||
|
||||
static inline void sp_vector3_reverse_double(const DPVector3* from, SPVector3* to)
|
||||
{
|
||||
to->x1 = -(float)from->x1;
|
||||
to->x2 = -(float)from->x2;
|
||||
to->x3 = -(float)from->x3;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_reverse_single(const SPVector3* from, DPVector3* to)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
to->x3 = -from->x3;
|
||||
}
|
||||
|
||||
// =================== Module =================== //
|
||||
|
@ -124,54 +172,6 @@ static inline int dp_vector3_is_unit(const DPVector3* vector)
|
|||
return 1.0f - DP_TWO_EPSYLON <= square_module && square_module <= 1.0f + DP_TWO_EPSYLON;
|
||||
}
|
||||
|
||||
// ============= Copy to twin type ============== //
|
||||
|
||||
static inline void sp_vector3_copy_to_double(const SPVector3* from, DPVector3* to)
|
||||
{
|
||||
to->x1 = (double)from->x1;
|
||||
to->x2 = (double)from->x2;
|
||||
to->x3 = (double)from->x3;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_copy_to_single(const DPVector3* from, SPVector3* to)
|
||||
{
|
||||
to->x1 = (float)from->x1;
|
||||
to->x2 = (float)from->x2;
|
||||
to->x3 = (float)from->x3;
|
||||
}
|
||||
|
||||
// ================= Inversion ================== //
|
||||
|
||||
static inline void sp_vector3_invert(SPVector3* vector)
|
||||
{
|
||||
vector->x1 = -vector->x1;
|
||||
vector->x2 = -vector->x2;
|
||||
vector->x3 = -vector->x3;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_invert(DPVector3* vector)
|
||||
{
|
||||
vector->x1 = -vector->x1;
|
||||
vector->x2 = -vector->x2;
|
||||
vector->x3 = -vector->x3;
|
||||
}
|
||||
|
||||
// ================ Get Inverted ================ //
|
||||
|
||||
static inline void sp_vector3_get_inverted(const SPVector3* vector, SPVector3* result)
|
||||
{
|
||||
result->x1 = -vector->x1;
|
||||
result->x2 = -vector->x2;
|
||||
result->x3 = -vector->x3;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_get_inverted(const DPVector3* vector, DPVector3* result)
|
||||
{
|
||||
result->x1 = -vector->x1;
|
||||
result->x2 = -vector->x2;
|
||||
result->x3 = -vector->x3;
|
||||
}
|
||||
|
||||
// ==================== Add ===================== //
|
||||
|
||||
static inline void sp_vector3_add(const SPVector3* vector1, const SPVector3* vector2, SPVector3* result)
|
||||
|
|
24
src/versor.h
24
src/versor.h
|
@ -226,18 +226,7 @@ static inline int dp_versor_is_idle(const DPVersor* versor)
|
|||
|
||||
// ============= Copy to twin type ============== //
|
||||
|
||||
static inline void sp_versor_copy_to_double(const SPVersor* versor, DPVersor* result)
|
||||
{
|
||||
dp_versor_set(
|
||||
(double)versor->_s0,
|
||||
(double)versor->_x1,
|
||||
(double)versor->_x2,
|
||||
(double)versor->_x3,
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
static inline void dp_versor_copy_to_single(const DPVersor* versor, SPVersor* result)
|
||||
static inline void sp_versor_from_double(const DPVersor* versor, SPVersor* result)
|
||||
{
|
||||
sp_versor_set(
|
||||
(float)versor->_s0,
|
||||
|
@ -248,6 +237,17 @@ static inline void dp_versor_copy_to_single(const DPVersor* versor, SPVersor* re
|
|||
);
|
||||
}
|
||||
|
||||
static inline void dp_versor_from_single(const SPVersor* versor, DPVersor* result)
|
||||
{
|
||||
dp_versor_set(
|
||||
(double)versor->_s0,
|
||||
(double)versor->_x1,
|
||||
(double)versor->_x2,
|
||||
(double)versor->_x3,
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
// ================= Inversion ================== //
|
||||
|
||||
static inline void sp_versor_invert(SPVersor* versor)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue