Добавлены функции для матриц 2x3 и 3x2 / New functions for matrixes 2x3 and 3x2 have been added

This commit is contained in:
Andrey Pokidov 2024-11-15 23:07:28 +07:00
parent 67f66e2127
commit 07c1330858
11 changed files with 902 additions and 52 deletions

View file

@ -176,7 +176,7 @@ int main()
{ {
SPVector2 vector; SPVector2 vector;
sp_vector2_set(0, 0, &vector); sp_vector2_set_values(0, 0, &vector);
printf("SPVector2(%f, %f), module = %d\n", printf("SPVector2(%f, %f), module = %d\n",
vector.x1, vector.x1,

View file

@ -11,6 +11,7 @@
#include "matrixes.h" #include "matrixes.h"
#include "matrix2x2.h" #include "matrix2x2.h"
#include "matrix2x3.h" #include "matrix2x3.h"
#include "matrix3x2.h"
#include "matrix3x3.h" #include "matrix3x3.h"
#include "rotation3.h" #include "rotation3.h"

View file

@ -23,7 +23,10 @@
<ClInclude Include="basis.h" /> <ClInclude Include="basis.h" />
<ClInclude Include="geometry.h" /> <ClInclude Include="geometry.h" />
<ClInclude Include="matrix2x2.h" /> <ClInclude Include="matrix2x2.h" />
<ClInclude Include="matrix2x3.h" />
<ClInclude Include="matrix3x2.h" />
<ClInclude Include="matrix3x3.h" /> <ClInclude Include="matrix3x3.h" />
<ClInclude Include="matrixes.h" />
<ClInclude Include="quaternion.h" /> <ClInclude Include="quaternion.h" />
<ClInclude Include="rotation3.h" /> <ClInclude Include="rotation3.h" />
<ClInclude Include="versor.h" /> <ClInclude Include="versor.h" />
@ -34,7 +37,10 @@
<ClCompile Include="angle.c" /> <ClCompile Include="angle.c" />
<ClCompile Include="basis.c" /> <ClCompile Include="basis.c" />
<ClCompile Include="matrix2x2.c" /> <ClCompile Include="matrix2x2.c" />
<ClCompile Include="matrix2x3.c" />
<ClCompile Include="matrix3x2.c" />
<ClCompile Include="matrix3x3.c" /> <ClCompile Include="matrix3x3.c" />
<ClCompile Include="matrixes.c" />
<ClCompile Include="quaternion.c" /> <ClCompile Include="quaternion.c" />
<ClCompile Include="rotation3.c" /> <ClCompile Include="rotation3.c" />
<ClCompile Include="versor.c" /> <ClCompile Include="versor.c" />

View file

@ -45,6 +45,15 @@
<ClInclude Include="quaternion.h"> <ClInclude Include="quaternion.h">
<Filter>Файлы заголовков</Filter> <Filter>Файлы заголовков</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="matrix2x3.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
<ClInclude Include="matrix3x2.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
<ClInclude Include="matrixes.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="angle.c"> <ClCompile Include="angle.c">
@ -74,5 +83,14 @@
<ClCompile Include="quaternion.c"> <ClCompile Include="quaternion.c">
<Filter>Исходные файлы</Filter> <Filter>Исходные файлы</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="matrixes.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="matrix2x3.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="matrix3x2.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

149
src/matrix2x3.c Normal file
View file

@ -0,0 +1,149 @@
#include "matrix2x3.h"
// ============= Weighed Sum of two ============= //
void sp_matrix2x3_get_weighted_sum2(
const float weight1, const SPMatrix2x3* matrix1,
const float weight2, const SPMatrix2x3* matrix2,
SPMatrix2x3* sum
)
{
sum->r1c1 = matrix1->r1c1 * weight1 + matrix2->r1c1 * weight2;
sum->r1c2 = matrix1->r1c2 * weight1 + matrix2->r1c2 * weight2;
sum->r2c1 = matrix1->r2c1 * weight1 + matrix2->r2c1 * weight2;
sum->r2c2 = matrix1->r2c2 * weight1 + matrix2->r2c2 * weight2;
sum->r3c1 = matrix1->r3c1 * weight1 + matrix2->r3c1 * weight2;
sum->r3c2 = matrix1->r3c2 * weight1 + matrix2->r3c2 * weight2;
}
void dp_matrix2x3_get_weighted_sum2(
const double weight1, const DPMatrix2x3* matrix1,
const double weight2, const DPMatrix2x3* matrix2,
DPMatrix2x3* sum
)
{
sum->r1c1 = matrix1->r1c1 * weight1 + matrix2->r1c1 * weight2;
sum->r1c2 = matrix1->r1c2 * weight1 + matrix2->r1c2 * weight2;
sum->r2c1 = matrix1->r2c1 * weight1 + matrix2->r2c1 * weight2;
sum->r2c2 = matrix1->r2c2 * weight1 + matrix2->r2c2 * weight2;
sum->r3c1 = matrix1->r3c1 * weight1 + matrix2->r3c1 * weight2;
sum->r3c2 = matrix1->r3c2 * weight1 + matrix2->r3c2 * weight2;
}
// ============ Weighed Sum of three ============ //
void sp_matrix2x3_get_weighted_sum3(
const float weight1, const SPMatrix2x3* matrix1,
const float weight2, const SPMatrix2x3* matrix2,
const float weight3, const SPMatrix2x3* matrix3,
SPMatrix2x3* sum
)
{
sum->r1c1 = matrix1->r1c1 * weight1 + matrix2->r1c1 * weight2 + matrix3->r1c1 * weight3;
sum->r1c2 = matrix1->r1c2 * weight1 + matrix2->r1c2 * weight2 + matrix3->r1c2 * weight3;
sum->r2c1 = matrix1->r2c1 * weight1 + matrix2->r2c1 * weight2 + matrix3->r2c1 * weight3;
sum->r2c2 = matrix1->r2c2 * weight1 + matrix2->r2c2 * weight2 + matrix3->r2c2 * weight3;
sum->r3c1 = matrix1->r3c1 * weight1 + matrix2->r3c1 * weight2 + matrix3->r3c1 * weight3;
sum->r3c2 = matrix1->r3c2 * weight1 + matrix2->r3c2 * weight2 + matrix3->r3c2 * weight3;
}
void dp_matrix2x3_get_weighted_sum3(
const double weight1, const DPMatrix2x3* matrix1,
const double weight2, const DPMatrix2x3* matrix2,
const double weight3, const DPMatrix2x3* matrix3,
DPMatrix2x3* sum
)
{
sum->r1c1 = matrix1->r1c1 * weight1 + matrix2->r1c1 * weight2 + matrix3->r1c1 * weight3;
sum->r1c2 = matrix1->r1c2 * weight1 + matrix2->r1c2 * weight2 + matrix3->r1c2 * weight3;
sum->r2c1 = matrix1->r2c1 * weight1 + matrix2->r2c1 * weight2 + matrix3->r2c1 * weight3;
sum->r2c2 = matrix1->r2c2 * weight1 + matrix2->r2c2 * weight2 + matrix3->r2c2 * weight3;
sum->r3c1 = matrix1->r3c1 * weight1 + matrix2->r3c1 * weight2 + matrix3->r3c1 * weight3;
sum->r3c2 = matrix1->r3c2 * weight1 + matrix2->r3c2 * weight2 + matrix3->r3c2 * weight3;
}
// ============ Weighed Sum of four ============= //
void sp_matrix2x3_get_weighted_sum4(
const float weight1, const SPMatrix2x3* matrix1,
const float weight2, const SPMatrix2x3* matrix2,
const float weight3, const SPMatrix2x3* matrix3,
const float weight4, const SPMatrix2x3* matrix4,
SPMatrix2x3* sum
)
{
sum->r1c1 = (matrix1->r1c1 * weight1 + matrix2->r1c1 * weight2) + (matrix3->r1c1 * weight3 + matrix4->r1c1 * weight4);
sum->r1c2 = (matrix1->r1c2 * weight1 + matrix2->r1c2 * weight2) + (matrix3->r1c2 * weight3 + matrix4->r1c2 * weight4);
sum->r2c1 = (matrix1->r2c1 * weight1 + matrix2->r2c1 * weight2) + (matrix3->r2c1 * weight3 + matrix4->r2c1 * weight4);
sum->r2c2 = (matrix1->r2c2 * weight1 + matrix2->r2c2 * weight2) + (matrix3->r2c2 * weight3 + matrix4->r2c2 * weight4);
sum->r3c1 = (matrix1->r3c1 * weight1 + matrix2->r3c1 * weight2) + (matrix3->r3c1 * weight3 + matrix4->r3c1 * weight4);
sum->r3c2 = (matrix1->r3c2 * weight1 + matrix2->r3c2 * weight2) + (matrix3->r3c2 * weight3 + matrix4->r3c2 * weight4);
}
void dp_matrix2x3_get_weighted_sum4(
const double weight1, const DPMatrix2x3* matrix1,
const double weight2, const DPMatrix2x3* matrix2,
const double weight3, const DPMatrix2x3* matrix3,
const double weight4, const DPMatrix2x3* matrix4,
DPMatrix2x3* sum
)
{
sum->r1c1 = (matrix1->r1c1 * weight1 + matrix2->r1c1 * weight2) + (matrix3->r1c1 * weight3 + matrix4->r1c1 * weight4);
sum->r1c2 = (matrix1->r1c2 * weight1 + matrix2->r1c2 * weight2) + (matrix3->r1c2 * weight3 + matrix4->r1c2 * weight4);
sum->r2c1 = (matrix1->r2c1 * weight1 + matrix2->r2c1 * weight2) + (matrix3->r2c1 * weight3 + matrix4->r2c1 * weight4);
sum->r2c2 = (matrix1->r2c2 * weight1 + matrix2->r2c2 * weight2) + (matrix3->r2c2 * weight3 + matrix4->r2c2 * weight4);
sum->r3c1 = (matrix1->r3c1 * weight1 + matrix2->r3c1 * weight2) + (matrix3->r3c1 * weight3 + matrix4->r3c1 * weight4);
sum->r3c2 = (matrix1->r3c2 * weight1 + matrix2->r3c2 * weight2) + (matrix3->r3c2 * weight3 + matrix4->r3c2 * weight4);
}
// ============ Weighed Sum of five ============= //
void sp_matrix2x3_get_weighted_sum5(
const float weight1, const SPMatrix2x3* matrix1,
const float weight2, const SPMatrix2x3* matrix2,
const float weight3, const SPMatrix2x3* matrix3,
const float weight4, const SPMatrix2x3* matrix4,
const float weight5, const SPMatrix2x3* matrix5,
SPMatrix2x3* sum
)
{
sum->r1c1 = (matrix1->r1c1 * weight1 + matrix2->r1c1 * weight2) + (matrix3->r1c1 * weight3 + matrix4->r1c1 * weight4) + matrix5->r1c1 * weight5;
sum->r1c2 = (matrix1->r1c2 * weight1 + matrix2->r1c2 * weight2) + (matrix3->r1c2 * weight3 + matrix4->r1c2 * weight4) + matrix5->r1c2 * weight5;
sum->r2c1 = (matrix1->r2c1 * weight1 + matrix2->r2c1 * weight2) + (matrix3->r2c1 * weight3 + matrix4->r2c1 * weight4) + matrix5->r2c1 * weight5;
sum->r2c2 = (matrix1->r2c2 * weight1 + matrix2->r2c2 * weight2) + (matrix3->r2c2 * weight3 + matrix4->r2c2 * weight4) + matrix5->r2c2 * weight5;
sum->r3c1 = (matrix1->r3c1 * weight1 + matrix2->r3c1 * weight2) + (matrix3->r3c1 * weight3 + matrix4->r3c1 * weight4) + matrix5->r3c1 * weight5;
sum->r3c2 = (matrix1->r3c2 * weight1 + matrix2->r3c2 * weight2) + (matrix3->r3c2 * weight3 + matrix4->r3c2 * weight4) + matrix5->r3c2 * weight5;
}
void dp_matrix2x3_get_weighted_sum5(
const double weight1, const DPMatrix2x3* matrix1,
const double weight2, const DPMatrix2x3* matrix2,
const double weight3, const DPMatrix2x3* matrix3,
const double weight4, const DPMatrix2x3* matrix4,
const double weight5, const DPMatrix2x3* matrix5,
DPMatrix2x3* sum
)
{
sum->r1c1 = (matrix1->r1c1 * weight1 + matrix2->r1c1 * weight2) + (matrix3->r1c1 * weight3 + matrix4->r1c1 * weight4) + matrix5->r1c1 * weight5;
sum->r1c2 = (matrix1->r1c2 * weight1 + matrix2->r1c2 * weight2) + (matrix3->r1c2 * weight3 + matrix4->r1c2 * weight4) + matrix5->r1c2 * weight5;
sum->r2c1 = (matrix1->r2c1 * weight1 + matrix2->r2c1 * weight2) + (matrix3->r2c1 * weight3 + matrix4->r2c1 * weight4) + matrix5->r2c1 * weight5;
sum->r2c2 = (matrix1->r2c2 * weight1 + matrix2->r2c2 * weight2) + (matrix3->r2c2 * weight3 + matrix4->r2c2 * weight4) + matrix5->r2c2 * weight5;
sum->r3c1 = (matrix1->r3c1 * weight1 + matrix2->r3c1 * weight2) + (matrix3->r3c1 * weight3 + matrix4->r3c1 * weight4) + matrix5->r3c1 * weight5;
sum->r3c2 = (matrix1->r3c2 * weight1 + matrix2->r3c2 * weight2) + (matrix3->r3c2 * weight3 + matrix4->r3c2 * weight4) + matrix5->r3c2 * weight5;
}

View file

@ -37,15 +37,12 @@ static inline void sp_matrix2x3_copy(const SPMatrix2x3* from, SPMatrix2x3* to)
{ {
to->r1c1 = from->r1c1; to->r1c1 = from->r1c1;
to->r1c2 = from->r1c2; to->r1c2 = from->r1c2;
to->r1c3 = from->r1c3;
to->r2c1 = from->r2c1; to->r2c1 = from->r2c1;
to->r2c2 = from->r2c2; to->r2c2 = from->r2c2;
to->r2c3 = from->r2c3;
to->r3c1 = from->r3c1; to->r3c1 = from->r3c1;
to->r3c2 = from->r3c2; to->r3c2 = from->r3c2;
to->r3c3 = from->r3c3;
} }
static inline void dp_matrix2x3_copy(const DPMatrix2x3* from, DPMatrix2x3* to) static inline void dp_matrix2x3_copy(const DPMatrix2x3* from, DPMatrix2x3* to)
@ -138,4 +135,280 @@ static inline void dp_matrix2x3_transpose_single(const SPMatrix3x2* from, DPMatr
to->r3c2 = from->r2c3; to->r3c2 = from->r2c3;
} }
// ================= Set Row 1 ================== //
static inline void sp_matrix2x3_set_row1(const float c1, const float c2, SPMatrix2x3* matrix)
{
matrix->r1c1 = c1;
matrix->r1c2 = c2;
}
static inline void dp_matrix2x3_set_row1(const double c1, const double c2, DPMatrix2x3* matrix)
{
matrix->r1c1 = c1;
matrix->r1c2 = c2;
}
// ================= Set Row 2 ================== //
static inline void sp_matrix2x3_set_row2(const float c1, const float c2, SPMatrix2x3* matrix)
{
matrix->r2c1 = c1;
matrix->r2c2 = c2;
}
static inline void dp_matrix2x3_set_row2(const double c1, const double c2, DPMatrix2x3* matrix)
{
matrix->r2c1 = c1;
matrix->r2c2 = c2;
}
// ================= Set Row 3 ================== //
static inline void sp_matrix2x3_set_row3(const float c1, const float c2, SPMatrix2x3* matrix)
{
matrix->r3c1 = c1;
matrix->r3c2 = c2;
}
static inline void dp_matrix2x3_set_row3(const double c1, const double c2, DPMatrix2x3* matrix)
{
matrix->r3c1 = c1;
matrix->r3c2 = c2;
}
// ================ Set Column 1 ================ //
static inline void sp_matrix2x3_set_column1(const float r1, const float r2, const float r3, SPMatrix2x3* matrix)
{
matrix->r1c1 = r1;
matrix->r2c1 = r2;
matrix->r3c1 = r3;
}
static inline void dp_matrix2x3_set_column1(const double r1, const double r2, const double r3, DPMatrix2x3* matrix)
{
matrix->r1c1 = r1;
matrix->r2c1 = r2;
matrix->r3c1 = r3;
}
// ================ Set Column 2 ================ //
static inline void sp_matrix2x3_set_column2(const float r1, const float r2, const float r3, SPMatrix2x3* matrix)
{
matrix->r1c2 = r1;
matrix->r2c2 = r2;
matrix->r3c2 = r3;
}
static inline void dp_matrix2x3_set_column2(const double r1, const double r2, const double r3, DPMatrix2x3* matrix)
{
matrix->r1c2 = r1;
matrix->r2c2 = r2;
matrix->r3c2 = r3;
}
// ================== Addition ================== //
static inline void sp_matrix2x3_add(const SPMatrix2x3* matrix1, const SPMatrix2x3* matrix2, SPMatrix2x3* sum)
{
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
sum->r2c1 = matrix1->r2c1 + matrix2->r2c1;
sum->r2c2 = matrix1->r2c2 + matrix2->r2c2;
sum->r3c1 = matrix1->r3c1 + matrix2->r3c1;
sum->r3c2 = matrix1->r3c2 + matrix2->r3c2;
}
static inline void dp_matrix2x3_add(const DPMatrix2x3* matrix1, const DPMatrix2x3* matrix2, DPMatrix2x3* sum)
{
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
sum->r2c1 = matrix1->r2c1 + matrix2->r2c1;
sum->r2c2 = matrix1->r2c2 + matrix2->r2c2;
sum->r3c1 = matrix1->r3c1 + matrix2->r3c1;
sum->r3c2 = matrix1->r3c2 + matrix2->r3c2;
}
// ================ Subtraction ================= //
static inline void sp_matrix2x3_subtract(const SPMatrix2x3* minuend, const SPMatrix2x3* subtrahend, SPMatrix2x3* difference)
{
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
difference->r2c1 = minuend->r2c1 - subtrahend->r2c1;
difference->r2c2 = minuend->r2c2 - subtrahend->r2c2;
difference->r3c1 = minuend->r3c1 - subtrahend->r3c1;
difference->r3c2 = minuend->r3c2 - subtrahend->r3c2;
}
static inline void dp_matrix2x3_subtract(const DPMatrix2x3* minuend, const DPMatrix2x3* subtrahend, DPMatrix2x3* difference)
{
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
difference->r2c1 = minuend->r2c1 - subtrahend->r2c1;
difference->r2c2 = minuend->r2c2 - subtrahend->r2c2;
difference->r3c1 = minuend->r3c1 - subtrahend->r3c1;
difference->r3c2 = minuend->r3c2 - subtrahend->r3c2;
}
// =============== Multiplication =============== //
static inline void sp_matrix2x3_multiply(const SPMatrix2x3* multiplicand, const float multiplier, SPMatrix2x3* product)
{
product->r1c1 = multiplicand->r1c1 * multiplier;
product->r1c2 = multiplicand->r1c2 * multiplier;
product->r2c1 = multiplicand->r2c1 * multiplier;
product->r2c2 = multiplicand->r2c2 * multiplier;
product->r3c1 = multiplicand->r3c1 * multiplier;
product->r3c2 = multiplicand->r3c2 * multiplier;
}
static inline void dp_matrix2x3_multiply(const DPMatrix2x3* multiplicand, const double multiplier, DPMatrix2x3* product)
{
product->r1c1 = multiplicand->r1c1 * multiplier;
product->r1c2 = multiplicand->r1c2 * multiplier;
product->r2c1 = multiplicand->r2c1 * multiplier;
product->r2c2 = multiplicand->r2c2 * multiplier;
product->r3c1 = multiplicand->r3c1 * multiplier;
product->r3c2 = multiplicand->r3c2 * multiplier;
}
// ================== Division ================== //
static inline void sp_matrix2x3_divide(const SPMatrix2x3* dividend, const float divisor, SPMatrix2x3* quotient)
{
quotient->r1c1 = dividend->r1c1 / divisor;
quotient->r1c2 = dividend->r1c2 / divisor;
quotient->r2c1 = dividend->r2c1 / divisor;
quotient->r2c2 = dividend->r2c2 / divisor;
quotient->r3c1 = dividend->r3c1 / divisor;
quotient->r3c2 = dividend->r3c2 / divisor;
}
static inline void dp_matrix2x3_divide(const DPMatrix2x3* dividend, const double divisor, DPMatrix2x3* quotient)
{
quotient->r1c1 = dividend->r1c1 / divisor;
quotient->r1c2 = dividend->r1c2 / divisor;
quotient->r2c1 = dividend->r2c1 / divisor;
quotient->r2c2 = dividend->r2c2 / divisor;
quotient->r3c1 = dividend->r3c1 / divisor;
quotient->r3c2 = dividend->r3c2 / divisor;
}
// ============= Weighed Sum of two ============= //
void sp_matrix2x3_get_weighted_sum2(
const float weight1, const SPMatrix2x3* matrix1,
const float weight2, const SPMatrix2x3* matrix2,
SPMatrix2x3* sum
);
void dp_matrix2x3_get_weighted_sum2(
const double weight1, const DPMatrix2x3* matrix1,
const double weight2, const DPMatrix2x3* matrix2,
DPMatrix2x3* sum
);
// ============ Weighed Sum of three ============ //
void sp_matrix2x3_get_weighted_sum3(
const float weight1, const SPMatrix2x3* matrix1,
const float weight2, const SPMatrix2x3* matrix2,
const float weight3, const SPMatrix2x3* matrix3,
SPMatrix2x3* sum
);
void dp_matrix2x3_get_weighted_sum3(
const double weight1, const DPMatrix2x3* matrix1,
const double weight2, const DPMatrix2x3* matrix2,
const double weight3, const DPMatrix2x3* matrix3,
DPMatrix2x3* sum
);
// ============ Weighed Sum of four ============= //
void sp_matrix2x3_get_weighted_sum4(
const float weight1, const SPMatrix2x3* matrix1,
const float weight2, const SPMatrix2x3* matrix2,
const float weight3, const SPMatrix2x3* matrix3,
const float weight4, const SPMatrix2x3* matrix4,
SPMatrix2x3* sum
);
void dp_matrix2x3_get_weighted_sum4(
const double weight1, const DPMatrix2x3* matrix1,
const double weight2, const DPMatrix2x3* matrix2,
const double weight3, const DPMatrix2x3* matrix3,
const double weight4, const DPMatrix2x3* matrix4,
DPMatrix2x3* sum
);
// ============ Weighed Sum of five ============= //
void sp_matrix2x3_get_weighted_sum5(
const float weight1, const SPMatrix2x3* matrix1,
const float weight2, const SPMatrix2x3* matrix2,
const float weight3, const SPMatrix2x3* matrix3,
const float weight4, const SPMatrix2x3* matrix4,
const float weight5, const SPMatrix2x3* matrix5,
SPMatrix2x3* sum
);
void dp_matrix2x3_get_weighted_sum5(
const double weight1, const DPMatrix2x3* matrix1,
const double weight2, const DPMatrix2x3* matrix2,
const double weight3, const DPMatrix2x3* matrix3,
const double weight4, const DPMatrix2x3* matrix4,
const double weight5, const DPMatrix2x3* matrix5,
DPMatrix2x3* sum
);
// ============ Left Vector Product ============= //
static inline void sp_matrix2x3_left_product(const SPVector3* vector, const SPMatrix2x3* matrix, SPVector2* result)
{
result->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1;
result->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2;
}
static inline void dp_matrix2x3_left_product(const DPVector3* vector, const DPMatrix2x3* matrix, DPVector2* result)
{
result->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1;
result->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2;
}
// ============ Right Vector Product ============ //
static inline void sp_matrix2x3_right_product(const SPMatrix2x3* matrix, const SPVector2* vector, SPVector3* result)
{
result->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2;
result->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2;
result->x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2;
}
static inline void dp_matrix2x3_right_product(const DPMatrix2x3* matrix, const DPVector2* vector, DPVector3* result)
{
result->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2;
result->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2;
result->x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2;
}
#endif #endif

141
src/matrix3x2.c Normal file
View file

Internal server error - Personal Git Server: Beyond coding. We Forge.

500

Internal server error

Forgejo version: 11.0.1+gitea-1.22.0

@ -0,0 +1,141 @@
#include "matrix3x2.h"
// ============= Weighed Sum of two ============= //
void sp_matrix3x2_get_weighted_sum2(
const float weight1, const SPMatrix3x2* matrix1,
const float weight2, const SPMatrix3x2* matrix2,
SPMatrix3x2* sum
)
{
sum->r1c1 = matrix1->r1c1 * weight1 + matrix2->r1c1 * weight2;
sum->r1c2 = matrix1->r1c2 * weight1 + matrix2->r1c2 * weight2;
sum->r1c3 = matrix1->r1c3 * weight1 + matrix2->r1c3 * weight2;
sum->r2c1 = matrix1->r2c1 * weight1 + matrix2->r2c1 * weight2;
sum->r2c2 = matrix1->r2c2 * weight1 + matrix2->r2c2 * weight2;
sum->r2c3 = matrix1->r2c3 * weight1 + matrix2->r2c3 * weight2;
}
void dp_matrix3x2_get_weighted_sum2(
const double weight1, const DPMatrix3x2* matrix1,
const double weight2, const DPMatrix3x2* matrix2,
DPMatrix3x2* sum
)
{
sum->r1c1 = matrix1->r1c1 * weight1 + matrix2->r1c1 * weight2;
sum->r1c2 = matrix1->r1c2 * weight1 + matrix2->r1c2 * weight2;
sum->r1c3 = matrix1->r1c3 * weight1 + matrix2->r1c3 * weight2;
sum->r2c1 = matrix1->r2c1 * weight1 + matrix2->r2c1 * weight2;
sum->r2c2 = matrix1->r2c2 * weight1 + matrix2->r2c2 * weight2;
sum->r2c3 = matrix1->r2c3 * weight1 + matrix2->r2c3 * weight2;
}
// ============ Weighed Sum of three ============ //
void sp_matrix3x2_get_weighted_sum3(
const float weight1, const SPMatrix3x2* matrix1,
const float weight2, const SPMatrix3x2* matrix2,
const float weight3, const SPMatrix3x2* matrix3,
SPMatrix3x2* sum
)
{
sum->r1c1 = matrix1->r1c1 * weight1 + matrix2->r1c1 * weight2 + matrix3->r1c1 * weight3;
sum->r1c2 = matrix1->r1c2 * weight1 + matrix2->r1c2 * weight2 + matrix3->r1c2 * weight3;
sum->r1c3 = matrix1->r1c3 * weight1 + matrix2->r1c3 * weight2 + matrix3->r1c3 * weight3;
sum->r2c1 = matrix1->r2c1 * weight1 + matrix2->r2c1 * weight2 + matrix3->r2c1 * weight3;
sum->r2c2 = matrix1->r2c2 * weight1 + matrix2->r2c2 * weight2 + matrix3->r2c2 * weight3;
sum->r2c3 = matrix1->r2c3 * weight1 + matrix2->r2c3 * weight2 + matrix3->r2c3 * weight3;
}
void dp_matrix3x2_get_weighted_sum3(
const double weight1, const DPMatrix3x2* matrix1,
const double weight2, const DPMatrix3x2* matrix2,
const double weight3, const DPMatrix3x2* matrix3,
DPMatrix3x2* sum
)
{
sum->r1c1 = matrix1->r1c1 * weight1 + matrix2->r1c1 * weight2 + matrix3->r1c1 * weight3;
sum->r1c2 = matrix1->r1c2 * weight1 + matrix2->r1c2 * weight2 + matrix3->r1c2 * weight3;
sum->r1c3 = matrix1->r1c3 * weight1 + matrix2->r1c3 * weight2 + matrix3->r1c3 * weight3;
sum->r2c1 = matrix1->r2c1 * weight1 + matrix2->r2c1 * weight2 + matrix3->r2c1 * weight3;
sum->r2c2 = matrix1->r2c2 * weight1 + matrix2->r2c2 * weight2 + matrix3->r2c2 * weight3;
sum->r2c3 = matrix1->r2c3 * weight1 + matrix2->r2c3 * weight2 + matrix3->r2c3 * weight3;
}
// ============ Weighed Sum of four ============= //
void sp_matrix3x2_get_weighted_sum4(
const float weight1, const SPMatrix3x2* matrix1,
const float weight2, const SPMatrix3x2* matrix2,
const float weight3, const SPMatrix3x2* matrix3,
const float weight4, const SPMatrix3x2* matrix4,
SPMatrix3x2* sum
)
{
sum->r1c1 = (matrix1->r1c1 * weight1 + matrix2->r1c1 * weight2) + (matrix3->r1c1 * weight3 + matrix4->r1c1 * weight4);
sum->r1c2 = (matrix1->r1c2 * weight1 + matrix2->r1c2 * weight2) + (matrix3->r1c2 * weight3 + matrix4->r1c2 * weight4);
sum->r1c3 = (matrix1->r1c3 * weight1 + matrix2->r1c3 * weight2) + (matrix3->r1c3 * weight3 + matrix4->r1c3 * weight4);
sum->r2c1 = (matrix1->r2c1 * weight1 + matrix2->r2c1 * weight2) + (matrix3->r2c1 * weight3 + matrix4->r2c1 * weight4);
sum->r2c2 = (matrix1->r2c2 * weight1 + matrix2->r2c2 * weight2) + (matrix3->r2c2 * weight3 + matrix4->r2c2 * weight4);
sum->r2c3 = (matrix1->r2c3 * weight1 + matrix2->r2c3 * weight2) + (matrix3->r2c3 * weight3 + matrix4->r2c3 * weight4);
}
void dp_matrix3x2_get_weighted_sum4(
const double weight1, const DPMatrix3x2* matrix1,
const double weight2, const DPMatrix3x2* matrix2,
const double weight3, const DPMatrix3x2* matrix3,
const double weight4, const DPMatrix3x2* matrix4,
DPMatrix3x2* sum
)
{
sum->r1c1 = (matrix1->r1c1 * weight1 + matrix2->r1c1 * weight2) + (matrix3->r1c1 * weight3 + matrix4->r1c1 * weight4);
sum->r1c2 = (matrix1->r1c2 * weight1 + matrix2->r1c2 * weight2) + (matrix3->r1c2 * weight3 + matrix4->r1c2 * weight4);
sum->r1c3 = (matrix1->r1c3 * weight1 + matrix2->r1c3 * weight2) + (matrix3->r1c3 * weight3 + matrix4->r1c3 * weight4);
sum->r2c1 = (matrix1->r2c1 * weight1 + matrix2->r2c1 * weight2) + (matrix3->r2c1 * weight3 + matrix4->r2c1 * weight4);