From bba8a65c1a8a47f8649092065fae11a456cc64db Mon Sep 17 00:00:00 2001 From: Andrey Pokidov Date: Mon, 23 Feb 2026 22:30:22 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B9?= =?UTF-8?q?=20=D1=81=D1=80=D0=B5=D0=B4=D0=BD=D0=B5=D0=B3=D0=BE=20=D0=BE?= =?UTF-8?q?=D1=82=202=20=D0=B8=20=D0=BE=D1=82=203=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=BC=D0=B0=D1=82=D1=80=D0=B8=D1=86,=20=D0=B4=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=84=D1=83=D0=BD?= =?UTF-8?q?=D0=BA=D1=86=D0=B8=D0=B9=20=D0=B0=D0=BB=D1=8C=D1=82=D0=B5=D1=80?= =?UTF-8?q?=D0=BD=D0=B0=D1=82=D0=B8=D0=B2=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=B4?= =?UTF-8?q?=D0=B2=D0=BE=D0=B9=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=B2=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B8=D0=B7=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=BE=D1=80=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- basic-geometry/matrix2x2.c | 6 ++++ basic-geometry/matrix2x2.h | 40 ++++++++++++++++++++++++ basic-geometry/matrix2x3.c | 6 ++++ basic-geometry/matrix2x3.h | 52 +++++++++++++++++++++++++++++++ basic-geometry/matrix3x2.c | 6 ++++ basic-geometry/matrix3x2.h | 50 ++++++++++++++++++++++++++++- basic-geometry/matrix3x3.c | 6 ++++ basic-geometry/matrix3x3.h | 64 ++++++++++++++++++++++++++++++++++++++ basic-geometry/vector3.c | 3 ++ basic-geometry/vector3.h | 26 ++++++++++++++++ 10 files changed, 258 insertions(+), 1 deletion(-) diff --git a/basic-geometry/matrix2x2.c b/basic-geometry/matrix2x2.c index d41d49a..91be710 100644 --- a/basic-geometry/matrix2x2.c +++ b/basic-geometry/matrix2x2.c @@ -84,5 +84,11 @@ extern inline void bgc_fp64_matrix2x2_multiply_by_matrix3x2(BGC_FP64_Matrix3x2* extern inline int bgc_fp32_matrix2x2_divide_by_real(BGC_FP32_Matrix2x2* quotient, const BGC_FP32_Matrix2x2* dividend, const float divisor); extern inline int bgc_fp64_matrix2x2_divide_by_real(BGC_FP64_Matrix2x2* quotient, const BGC_FP64_Matrix2x2* dividend, const double divisor); +extern inline void bgc_fp32_matrix2x2_get_mean2(BGC_FP32_Matrix2x2* mean, const BGC_FP32_Matrix2x2* term1, const BGC_FP32_Matrix2x2* term2); +extern inline void bgc_fp64_matrix2x2_get_mean2(BGC_FP64_Matrix2x2* mean, const BGC_FP64_Matrix2x2* term1, const BGC_FP64_Matrix2x2* term2); + +extern inline void bgc_fp32_matrix2x2_get_mean3(BGC_FP32_Matrix2x2* mean, const BGC_FP32_Matrix2x2* term1, const BGC_FP32_Matrix2x2* term2, const BGC_FP32_Matrix2x2* term3); +extern inline void bgc_fp64_matrix2x2_get_mean3(BGC_FP64_Matrix2x2* mean, const BGC_FP64_Matrix2x2* term1, const BGC_FP64_Matrix2x2* term2, const BGC_FP64_Matrix2x2* term3); + extern inline void bgc_fp32_matrix2x2_interpolate(BGC_FP32_Matrix2x2* interpolation, const BGC_FP32_Matrix2x2* first, const BGC_FP32_Matrix2x2* second, const float phase); extern inline void bgc_fp64_matrix2x2_interpolate(BGC_FP64_Matrix2x2* interpolation, const BGC_FP64_Matrix2x2* first, const BGC_FP64_Matrix2x2* second, const double phase); diff --git a/basic-geometry/matrix2x2.h b/basic-geometry/matrix2x2.h index cd9202d..c036fec 100644 --- a/basic-geometry/matrix2x2.h +++ b/basic-geometry/matrix2x2.h @@ -691,6 +691,46 @@ inline int bgc_fp64_matrix2x2_divide_by_real(BGC_FP64_Matrix2x2* quotient, const return BGC_SUCCESS; } +// ================== Average2 ================== // + +inline void bgc_fp32_matrix2x2_get_mean2(BGC_FP32_Matrix2x2* mean, const BGC_FP32_Matrix2x2* term1, const BGC_FP32_Matrix2x2* term2) +{ + mean->r1c1 = (term1->r1c1 + term2->r1c1) * 0.5f; + mean->r1c2 = (term1->r1c2 + term2->r1c2) * 0.5f; + + mean->r2c1 = (term1->r2c1 + term2->r2c1) * 0.5f; + mean->r2c2 = (term1->r2c2 + term2->r2c2) * 0.5f; +} + +inline void bgc_fp64_matrix2x2_get_mean2(BGC_FP64_Matrix2x2* mean, const BGC_FP64_Matrix2x2* term1, const BGC_FP64_Matrix2x2* term2) +{ + mean->r1c1 = (term1->r1c1 + term2->r1c1) * 0.5; + mean->r1c2 = (term1->r1c2 + term2->r1c2) * 0.5; + + mean->r2c1 = (term1->r2c1 + term2->r2c1) * 0.5; + mean->r2c2 = (term1->r2c2 + term2->r2c2) * 0.5; +} + +// ================== Average3 ================== // + +inline void bgc_fp32_matrix2x2_get_mean3(BGC_FP32_Matrix2x2* mean, const BGC_FP32_Matrix2x2* term1, const BGC_FP32_Matrix2x2* term2, const BGC_FP32_Matrix2x2* term3) +{ + mean->r1c1 = (term1->r1c1 + term2->r1c1 + term3->r1c1) * BGC_FP32_ONE_THIRD; + mean->r1c2 = (term1->r1c2 + term2->r1c2 + term3->r1c2) * BGC_FP32_ONE_THIRD; + + mean->r2c1 = (term1->r2c1 + term2->r2c1 + term3->r2c1) * BGC_FP32_ONE_THIRD; + mean->r2c2 = (term1->r2c2 + term2->r2c2 + term3->r2c2) * BGC_FP32_ONE_THIRD; +} + +inline void bgc_fp64_matrix2x2_get_mean3(BGC_FP64_Matrix2x2* mean, const BGC_FP64_Matrix2x2* term1, const BGC_FP64_Matrix2x2* term2, const BGC_FP64_Matrix2x2* term3) +{ + mean->r1c1 = (term1->r1c1 + term2->r1c1 + term3->r1c1) * BGC_FP64_ONE_THIRD; + mean->r1c2 = (term1->r1c2 + term2->r1c2 + term3->r1c2) * BGC_FP64_ONE_THIRD; + + mean->r2c1 = (term1->r2c1 + term2->r2c1 + term3->r2c1) * BGC_FP64_ONE_THIRD; + mean->r2c2 = (term1->r2c2 + term2->r2c2 + term3->r2c2) * BGC_FP64_ONE_THIRD; +} + // ================ Interpolate ================= // inline void bgc_fp32_matrix2x2_interpolate(BGC_FP32_Matrix2x2* interpolation, const BGC_FP32_Matrix2x2* first, const BGC_FP32_Matrix2x2* second, const float phase) diff --git a/basic-geometry/matrix2x3.c b/basic-geometry/matrix2x3.c index 5158fd0..3ef523f 100644 --- a/basic-geometry/matrix2x3.c +++ b/basic-geometry/matrix2x3.c @@ -54,5 +54,11 @@ extern inline void bgc_fp64_matrix2x3_multiply_by_matrix3x2(BGC_FP64_Matrix3x3* extern inline int bgc_fp32_matrix2x3_divide_by_real(BGC_FP32_Matrix2x3* quotient, const BGC_FP32_Matrix2x3* dividend, const float divisor); extern inline int bgc_fp64_matrix2x3_divide_by_real(BGC_FP64_Matrix2x3* quotient, const BGC_FP64_Matrix2x3* dividend, const double divisor); +extern inline void bgc_fp32_matrix2x3_get_mean2(BGC_FP32_Matrix2x3* mean, const BGC_FP32_Matrix2x3* term1, const BGC_FP32_Matrix2x3* term2); +extern inline void bgc_fp64_matrix2x3_get_mean2(BGC_FP64_Matrix2x3* mean, const BGC_FP64_Matrix2x3* term1, const BGC_FP64_Matrix2x3* term2); + +extern inline void bgc_fp32_matrix2x3_get_mean3(BGC_FP32_Matrix2x3* mean, const BGC_FP32_Matrix2x3* term1, const BGC_FP32_Matrix2x3* term2, const BGC_FP32_Matrix2x3* term3); +extern inline void bgc_fp64_matrix2x3_get_mean3(BGC_FP64_Matrix2x3* mean, const BGC_FP64_Matrix2x3* term1, const BGC_FP64_Matrix2x3* term2, const BGC_FP64_Matrix2x3* term3); + extern inline void bgc_fp32_matrix2x3_interpolate(BGC_FP32_Matrix2x3* interpolation, const BGC_FP32_Matrix2x3* first, const BGC_FP32_Matrix2x3* second, const float phase); extern inline void bgc_fp64_matrix2x3_interpolate(BGC_FP64_Matrix2x3* interpolation, const BGC_FP64_Matrix2x3* first, const BGC_FP64_Matrix2x3* second, const double phase); diff --git a/basic-geometry/matrix2x3.h b/basic-geometry/matrix2x3.h index 78eb97a..624585c 100644 --- a/basic-geometry/matrix2x3.h +++ b/basic-geometry/matrix2x3.h @@ -577,6 +577,58 @@ inline int bgc_fp64_matrix2x3_divide_by_real(BGC_FP64_Matrix2x3* quotient, const return BGC_SUCCESS; } +// ================== Average2 ================== // + +inline void bgc_fp32_matrix2x3_get_mean2(BGC_FP32_Matrix2x3* mean, const BGC_FP32_Matrix2x3* term1, const BGC_FP32_Matrix2x3* term2) +{ + mean->r1c1 = (term1->r1c1 + term2->r1c1) * 0.5f; + mean->r1c2 = (term1->r1c2 + term2->r1c2) * 0.5f; + + mean->r2c1 = (term1->r2c1 + term2->r2c1) * 0.5f; + mean->r2c2 = (term1->r2c2 + term2->r2c2) * 0.5f; + + mean->r3c1 = (term1->r3c1 + term2->r3c1) * 0.5f; + mean->r3c2 = (term1->r3c2 + term2->r3c2) * 0.5f; +} + +inline void bgc_fp64_matrix2x3_get_mean2(BGC_FP64_Matrix2x3* mean, const BGC_FP64_Matrix2x3* term1, const BGC_FP64_Matrix2x3* term2) +{ + mean->r1c1 = (term1->r1c1 + term2->r1c1) * 0.5; + mean->r1c2 = (term1->r1c2 + term2->r1c2) * 0.5; + + mean->r2c1 = (term1->r2c1 + term2->r2c1) * 0.5; + mean->r2c2 = (term1->r2c2 + term2->r2c2) * 0.5; + + mean->r3c1 = (term1->r3c1 + term2->r3c1) * 0.5; + mean->r3c2 = (term1->r3c2 + term2->r3c2) * 0.5; +} + +// ================== Average3 ================== // + +inline void bgc_fp32_matrix2x3_get_mean3(BGC_FP32_Matrix2x3* mean, const BGC_FP32_Matrix2x3* term1, const BGC_FP32_Matrix2x3* term2, const BGC_FP32_Matrix2x3* term3) +{ + mean->r1c1 = (term1->r1c1 + term2->r1c1 + term3->r1c1) * BGC_FP32_ONE_THIRD; + mean->r1c2 = (term1->r1c2 + term2->r1c2 + term3->r1c2) * BGC_FP32_ONE_THIRD; + + mean->r2c1 = (term1->r2c1 + term2->r2c1 + term3->r2c1) * BGC_FP32_ONE_THIRD; + mean->r2c2 = (term1->r2c2 + term2->r2c2 + term3->r2c2) * BGC_FP32_ONE_THIRD; + + mean->r3c1 = (term1->r3c1 + term2->r3c1 + term3->r3c1) * BGC_FP32_ONE_THIRD; + mean->r3c2 = (term1->r3c2 + term2->r3c2 + term3->r3c2) * BGC_FP32_ONE_THIRD; +} + +inline void bgc_fp64_matrix2x3_get_mean3(BGC_FP64_Matrix2x3* mean, const BGC_FP64_Matrix2x3* term1, const BGC_FP64_Matrix2x3* term2, const BGC_FP64_Matrix2x3* term3) +{ + mean->r1c1 = (term1->r1c1 + term2->r1c1 + term3->r1c1) * BGC_FP64_ONE_THIRD; + mean->r1c2 = (term1->r1c2 + term2->r1c2 + term3->r1c2) * BGC_FP64_ONE_THIRD; + + mean->r2c1 = (term1->r2c1 + term2->r2c1 + term3->r2c1) * BGC_FP64_ONE_THIRD; + mean->r2c2 = (term1->r2c2 + term2->r2c2 + term3->r2c2) * BGC_FP64_ONE_THIRD; + + mean->r3c1 = (term1->r3c1 + term2->r3c1 + term3->r3c1) * BGC_FP64_ONE_THIRD; + mean->r3c2 = (term1->r3c2 + term2->r3c2 + term3->r3c2) * BGC_FP64_ONE_THIRD; +} + // ================ Interpolate ================= // inline void bgc_fp32_matrix2x3_interpolate(BGC_FP32_Matrix2x3* interpolation, const BGC_FP32_Matrix2x3* first, const BGC_FP32_Matrix2x3* second, const float phase) diff --git a/basic-geometry/matrix3x2.c b/basic-geometry/matrix3x2.c index c631e27..775c92d 100644 --- a/basic-geometry/matrix3x2.c +++ b/basic-geometry/matrix3x2.c @@ -54,5 +54,11 @@ extern inline void bgc_fp64_matrix3x2_multiply_by_matrix3x3(BGC_FP64_Matrix3x2* extern inline int bgc_fp32_matrix3x2_divide_by_real(BGC_FP32_Matrix3x2* quotient, const BGC_FP32_Matrix3x2* dividend, const float divisor); extern inline int bgc_fp64_matrix3x2_divide_by_real(BGC_FP64_Matrix3x2* quotient, const BGC_FP64_Matrix3x2* dividend, const double divisor); +extern inline void bgc_fp32_matrix3x2_get_mean2(BGC_FP32_Matrix3x2* mean, const BGC_FP32_Matrix3x2* term1, const BGC_FP32_Matrix3x2* term2); +extern inline void bgc_fp64_matrix3x2_get_mean2(BGC_FP64_Matrix3x2* mean, const BGC_FP64_Matrix3x2* term1, const BGC_FP64_Matrix3x2* term2); + +extern inline void bgc_fp32_matrix3x2_get_mean3(BGC_FP32_Matrix3x2* mean, const BGC_FP32_Matrix3x2* term1, const BGC_FP32_Matrix3x2* term2, const BGC_FP32_Matrix3x2* term3); +extern inline void bgc_fp64_matrix3x2_get_mean3(BGC_FP64_Matrix3x2* mean, const BGC_FP64_Matrix3x2* term1, const BGC_FP64_Matrix3x2* term2, const BGC_FP64_Matrix3x2* term3); + extern inline void bgc_fp32_matrix3x2_interpolate(BGC_FP32_Matrix3x2* interpolation, const BGC_FP32_Matrix3x2* first, const BGC_FP32_Matrix3x2* second, const float phase); extern inline void bgc_fp64_matrix3x2_interpolate(BGC_FP64_Matrix3x2* interpolation, const BGC_FP64_Matrix3x2* first, const BGC_FP64_Matrix3x2* second, const double phase); diff --git a/basic-geometry/matrix3x2.h b/basic-geometry/matrix3x2.h index ca7178e..d696b1d 100644 --- a/basic-geometry/matrix3x2.h +++ b/basic-geometry/matrix3x2.h @@ -502,7 +502,7 @@ inline void bgc_fp64_matrix3x2_multiply_by_matrix2x3(BGC_FP64_Matrix2x2* product product->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2; } -// ========== Matrix Product 3x2 at 3x3 ========= // +// ========== Matrix Product 3x2 at 3x2 ========= // inline void bgc_fp32_matrix3x2_multiply_by_matrix3x3(BGC_FP32_Matrix3x2* product, const BGC_FP32_Matrix3x2* matrix1, const BGC_FP32_Matrix3x3* matrix2) { @@ -564,6 +564,54 @@ inline int bgc_fp64_matrix3x2_divide_by_real(BGC_FP64_Matrix3x2* quotient, const return BGC_SUCCESS; } +// ================== Average2 ================== // + +inline void bgc_fp32_matrix3x2_get_mean2(BGC_FP32_Matrix3x2* mean, const BGC_FP32_Matrix3x2* term1, const BGC_FP32_Matrix3x2* term2) +{ + mean->r1c1 = (term1->r1c1 + term2->r1c1) * 0.5f; + mean->r1c2 = (term1->r1c2 + term2->r1c2) * 0.5f; + mean->r1c3 = (term1->r1c3 + term2->r1c3) * 0.5f; + + mean->r2c1 = (term1->r2c1 + term2->r2c1) * 0.5f; + mean->r2c2 = (term1->r2c2 + term2->r2c2) * 0.5f; + mean->r2c3 = (term1->r2c3 + term2->r2c3) * 0.5f; +} + +inline void bgc_fp64_matrix3x2_get_mean2(BGC_FP64_Matrix3x2* mean, const BGC_FP64_Matrix3x2* term1, const BGC_FP64_Matrix3x2* term2) +{ + mean->r1c1 = (term1->r1c1 + term2->r1c1) * 0.5; + mean->r1c2 = (term1->r1c2 + term2->r1c2) * 0.5; + mean->r1c3 = (term1->r1c3 + term2->r1c3) * 0.5; + + mean->r2c1 = (term1->r2c1 + term2->r2c1) * 0.5; + mean->r2c2 = (term1->r2c2 + term2->r2c2) * 0.5; + mean->r2c3 = (term1->r2c3 + term2->r2c3) * 0.5; +} + +// ================== Average3 ================== // + +inline void bgc_fp32_matrix3x2_get_mean3(BGC_FP32_Matrix3x2* mean, const BGC_FP32_Matrix3x2* term1, const BGC_FP32_Matrix3x2* term2, const BGC_FP32_Matrix3x2* term3) +{ + mean->r1c1 = (term1->r1c1 + term2->r1c1 + term3->r1c1) * BGC_FP32_ONE_THIRD; + mean->r1c2 = (term1->r1c2 + term2->r1c2 + term3->r1c2) * BGC_FP32_ONE_THIRD; + mean->r1c3 = (term1->r1c3 + term2->r1c3 + term3->r1c3) * BGC_FP32_ONE_THIRD; + + mean->r2c1 = (term1->r2c1 + term2->r2c1 + term3->r2c1) * BGC_FP32_ONE_THIRD; + mean->r2c2 = (term1->r2c2 + term2->r2c2 + term3->r2c2) * BGC_FP32_ONE_THIRD; + mean->r2c3 = (term1->r2c3 + term2->r2c3 + term3->r2c3) * BGC_FP32_ONE_THIRD; +} + +inline void bgc_fp64_matrix3x2_get_mean3(BGC_FP64_Matrix3x2* mean, const BGC_FP64_Matrix3x2* term1, const BGC_FP64_Matrix3x2* term2, const BGC_FP64_Matrix3x2* term3) +{ + mean->r1c1 = (term1->r1c1 + term2->r1c1 + term3->r1c1) * BGC_FP64_ONE_THIRD; + mean->r1c2 = (term1->r1c2 + term2->r1c2 + term3->r1c2) * BGC_FP64_ONE_THIRD; + mean->r1c3 = (term1->r1c3 + term2->r1c3 + term3->r1c3) * BGC_FP64_ONE_THIRD; + + mean->r2c1 = (term1->r2c1 + term2->r2c1 + term3->r2c1) * BGC_FP64_ONE_THIRD; + mean->r2c2 = (term1->r2c2 + term2->r2c2 + term3->r2c2) * BGC_FP64_ONE_THIRD; + mean->r2c3 = (term1->r2c3 + term2->r2c3 + term3->r2c3) * BGC_FP64_ONE_THIRD; +} + // ================ Interpolate ================= // inline void bgc_fp32_matrix3x2_interpolate(BGC_FP32_Matrix3x2* interpolation, const BGC_FP32_Matrix3x2* first, const BGC_FP32_Matrix3x2* second, const float phase) diff --git a/basic-geometry/matrix3x3.c b/basic-geometry/matrix3x3.c index 56bf691..568c29c 100644 --- a/basic-geometry/matrix3x3.c +++ b/basic-geometry/matrix3x3.c @@ -78,6 +78,12 @@ extern inline void bgc_fp64_matrix3x3_multiply_by_matrix3x3(BGC_FP64_Matrix3x3* extern inline int bgc_fp32_matrix3x3_divide_by_real(BGC_FP32_Matrix3x3* quotient, const BGC_FP32_Matrix3x3* dividend, const float divisor); extern inline int bgc_fp64_matrix3x3_divide_by_real(BGC_FP64_Matrix3x3* quotient, const BGC_FP64_Matrix3x3* dividend, const double divisor); +extern inline void bgc_fp32_matrix3x3_get_mean2(BGC_FP32_Matrix3x3* mean, const BGC_FP32_Matrix3x3* term1, const BGC_FP32_Matrix3x3* term2); +extern inline void bgc_fp64_matrix3x3_get_mean2(BGC_FP64_Matrix3x3* mean, const BGC_FP64_Matrix3x3* term1, const BGC_FP64_Matrix3x3* term2); + +extern inline void bgc_fp32_matrix3x3_get_mean3(BGC_FP32_Matrix3x3* mean, const BGC_FP32_Matrix3x3* term1, const BGC_FP32_Matrix3x3* term2, const BGC_FP32_Matrix3x3* term3); +extern inline void bgc_fp64_matrix3x3_get_mean3(BGC_FP64_Matrix3x3* mean, const BGC_FP64_Matrix3x3* term1, const BGC_FP64_Matrix3x3* term2, const BGC_FP64_Matrix3x3* term3); + extern inline void bgc_fp32_matrix3x3_interpolate(BGC_FP32_Matrix3x3* interpolation, const BGC_FP32_Matrix3x3* first, const BGC_FP32_Matrix3x3* second, const float phase); extern inline void bgc_fp64_matrix3x3_interpolate(BGC_FP64_Matrix3x3* interpolation, const BGC_FP64_Matrix3x3* first, const BGC_FP64_Matrix3x3* second, const double phase); diff --git a/basic-geometry/matrix3x3.h b/basic-geometry/matrix3x3.h index a30106e..b587055 100644 --- a/basic-geometry/matrix3x3.h +++ b/basic-geometry/matrix3x3.h @@ -963,6 +963,70 @@ inline int bgc_fp64_matrix3x3_divide_by_real(BGC_FP64_Matrix3x3* quotient, const return BGC_SUCCESS; } +// ================== Average2 ================== // + +inline void bgc_fp32_matrix3x3_get_mean2(BGC_FP32_Matrix3x3* mean, const BGC_FP32_Matrix3x3* term1, const BGC_FP32_Matrix3x3* term2) +{ + mean->r1c1 = (term1->r1c1 + term2->r1c1) * 0.5f; + mean->r1c2 = (term1->r1c2 + term2->r1c2) * 0.5f; + mean->r1c3 = (term1->r1c3 + term2->r1c3) * 0.5f; + + mean->r2c1 = (term1->r2c1 + term2->r2c1) * 0.5f; + mean->r2c2 = (term1->r2c2 + term2->r2c2) * 0.5f; + mean->r2c3 = (term1->r2c3 + term2->r2c3) * 0.5f; + + mean->r3c1 = (term1->r3c1 + term2->r3c1) * 0.5f; + mean->r3c2 = (term1->r3c2 + term2->r3c2) * 0.5f; + mean->r3c3 = (term1->r3c3 + term2->r3c3) * 0.5f; +} + +inline void bgc_fp64_matrix3x3_get_mean2(BGC_FP64_Matrix3x3* mean, const BGC_FP64_Matrix3x3* term1, const BGC_FP64_Matrix3x3* term2) +{ + mean->r1c1 = (term1->r1c1 + term2->r1c1) * 0.5; + mean->r1c2 = (term1->r1c2 + term2->r1c2) * 0.5; + mean->r1c3 = (term1->r1c3 + term2->r1c3) * 0.5; + + mean->r2c1 = (term1->r2c1 + term2->r2c1) * 0.5; + mean->r2c2 = (term1->r2c2 + term2->r2c2) * 0.5; + mean->r2c3 = (term1->r2c3 + term2->r2c3) * 0.5; + + mean->r3c1 = (term1->r3c1 + term2->r3c1) * 0.5; + mean->r3c2 = (term1->r3c2 + term2->r3c2) * 0.5; + mean->r3c3 = (term1->r3c3 + term2->r3c3) * 0.5; +} + +// ================== Average3 ================== // + +inline void bgc_fp32_matrix3x3_get_mean3(BGC_FP32_Matrix3x3* mean, const BGC_FP32_Matrix3x3* term1, const BGC_FP32_Matrix3x3* term2, const BGC_FP32_Matrix3x3* term3) +{ + mean->r1c1 = (term1->r1c1 + term2->r1c1 + term3->r1c1) * BGC_FP32_ONE_THIRD; + mean->r1c2 = (term1->r1c2 + term2->r1c2 + term3->r1c2) * BGC_FP32_ONE_THIRD; + mean->r1c3 = (term1->r1c3 + term2->r1c3 + term3->r1c3) * BGC_FP32_ONE_THIRD; + + mean->r2c1 = (term1->r2c1 + term2->r2c1 + term3->r2c1) * BGC_FP32_ONE_THIRD; + mean->r2c2 = (term1->r2c2 + term2->r2c2 + term3->r2c2) * BGC_FP32_ONE_THIRD; + mean->r2c3 = (term1->r2c3 + term2->r2c3 + term3->r2c3) * BGC_FP32_ONE_THIRD; + + mean->r3c1 = (term1->r3c1 + term2->r3c1 + term3->r3c1) * BGC_FP32_ONE_THIRD; + mean->r3c2 = (term1->r3c2 + term2->r3c2 + term3->r3c2) * BGC_FP32_ONE_THIRD; + mean->r3c3 = (term1->r3c3 + term2->r3c3 + term3->r3c3) * BGC_FP32_ONE_THIRD; +} + +inline void bgc_fp64_matrix3x3_get_mean3(BGC_FP64_Matrix3x3* mean, const BGC_FP64_Matrix3x3* term1, const BGC_FP64_Matrix3x3* term2, const BGC_FP64_Matrix3x3* term3) +{ + mean->r1c1 = (term1->r1c1 + term2->r1c1 + term3->r1c1) * BGC_FP64_ONE_THIRD; + mean->r1c2 = (term1->r1c2 + term2->r1c2 + term3->r1c2) * BGC_FP64_ONE_THIRD; + mean->r1c3 = (term1->r1c3 + term2->r1c3 + term3->r1c3) * BGC_FP64_ONE_THIRD; + + mean->r2c1 = (term1->r2c1 + term2->r2c1 + term3->r2c1) * BGC_FP64_ONE_THIRD; + mean->r2c2 = (term1->r2c2 + term2->r2c2 + term3->r2c2) * BGC_FP64_ONE_THIRD; + mean->r2c3 = (term1->r2c3 + term2->r2c3 + term3->r2c3) * BGC_FP64_ONE_THIRD; + + mean->r3c1 = (term1->r3c1 + term2->r3c1 + term3->r3c1) * BGC_FP64_ONE_THIRD; + mean->r3c2 = (term1->r3c2 + term2->r3c2 + term3->r3c2) * BGC_FP64_ONE_THIRD; + mean->r3c3 = (term1->r3c3 + term2->r3c3 + term3->r3c3) * BGC_FP64_ONE_THIRD; +} + // ================ Interpolate ================= // inline void bgc_fp32_matrix3x3_interpolate(BGC_FP32_Matrix3x3* interpolation, const BGC_FP32_Matrix3x3* first, const BGC_FP32_Matrix3x3* second, const float phase) diff --git a/basic-geometry/vector3.c b/basic-geometry/vector3.c index 3a8430c..693eb04 100644 --- a/basic-geometry/vector3.c +++ b/basic-geometry/vector3.c @@ -84,6 +84,9 @@ extern inline void bgc_fp64_vector3_get_cross_product(BGC_FP64_Vector3* product, extern inline void bgc_fp32_vector3_get_double_cross(BGC_FP32_Vector3* product, const BGC_FP32_Vector3* vector1, const BGC_FP32_Vector3* vector2, const BGC_FP32_Vector3* vector3); extern inline void bgc_fp64_vector3_get_double_cross(BGC_FP64_Vector3* product, const BGC_FP64_Vector3* vector1, const BGC_FP64_Vector3* vector2, const BGC_FP64_Vector3* vector3); +extern inline void bgc_fp32_vector3_get_alternative_double_cross(BGC_FP32_Vector3* product, const BGC_FP32_Vector3* vector1, const BGC_FP32_Vector3* vector2, const BGC_FP32_Vector3* vector3); +extern inline void bgc_fp64_vector3_get_alternative_double_cross(BGC_FP64_Vector3* product, const BGC_FP64_Vector3* vector1, const BGC_FP64_Vector3* vector2, const BGC_FP64_Vector3* vector3); + extern inline float bgc_fp32_vector3_get_square_distance(const BGC_FP32_Vector3* vector1, const BGC_FP32_Vector3* vector2); extern inline double bgc_fp64_vector3_get_square_distance(const BGC_FP64_Vector3* vector1, const BGC_FP64_Vector3* vector2); diff --git a/basic-geometry/vector3.h b/basic-geometry/vector3.h index 8980730..91b745d 100644 --- a/basic-geometry/vector3.h +++ b/basic-geometry/vector3.h @@ -505,6 +505,7 @@ inline void bgc_fp64_vector3_get_cross_product(BGC_FP64_Vector3* product, const // ============ Double Cross Product ============ // +// [a x [b x c]] = b * (a, c) - c * (a, b) inline void bgc_fp32_vector3_get_double_cross(BGC_FP32_Vector3* product, const BGC_FP32_Vector3* vector1, const BGC_FP32_Vector3* vector2, const BGC_FP32_Vector3* vector3) { const float ac = bgc_fp32_vector3_get_dot_product(vector1, vector3); @@ -515,6 +516,7 @@ inline void bgc_fp32_vector3_get_double_cross(BGC_FP32_Vector3* product, const B product->x3 = vector2->x3 * ac - vector3->x3 * ab; } +// [a x [b x c]] = b * (a, c) - c * (a, b) inline void bgc_fp64_vector3_get_double_cross(BGC_FP64_Vector3* product, const BGC_FP64_Vector3* vector1, const BGC_FP64_Vector3* vector2, const BGC_FP64_Vector3* vector3) { const double ac = bgc_fp64_vector3_get_dot_product(vector1, vector3); @@ -525,6 +527,30 @@ inline void bgc_fp64_vector3_get_double_cross(BGC_FP64_Vector3* product, const B product->x3 = vector2->x3 * ac - vector3->x3 * ab; } +// ====== Alternative Double Cross Product ====== // + +// [[a x b] x c] = - [c x [a x b]] = -(a * (c, b) - b * (c, a)) = b * (a, c) - a * (b, c) +inline void bgc_fp32_vector3_get_alternative_double_cross(BGC_FP32_Vector3* product, const BGC_FP32_Vector3* vector1, const BGC_FP32_Vector3* vector2, const BGC_FP32_Vector3* vector3) +{ + const float ac = bgc_fp32_vector3_get_dot_product(vector1, vector3); + const float bc = bgc_fp32_vector3_get_dot_product(vector2, vector3); + + product->x1 = vector2->x1 * ac - vector1->x1 * bc; + product->x2 = vector2->x2 * ac - vector1->x2 * bc; + product->x3 = vector2->x3 * ac - vector1->x3 * bc; +} + +// [[a x b] x c] = - [c x [a x b]] = -(a * (b, c) - b * (a, c)) = b * (a, c) - a * (b, c) +inline void bgc_fp64_vector3_get_alternative_double_cross(BGC_FP64_Vector3* product, const BGC_FP64_Vector3* vector1, const BGC_FP64_Vector3* vector2, const BGC_FP64_Vector3* vector3) +{ + const double ac = bgc_fp64_vector3_get_dot_product(vector1, vector3); + const double bc = bgc_fp64_vector3_get_dot_product(vector2, vector3); + + product->x1 = vector2->x1 * ac - vector1->x1 * bc; + product->x2 = vector2->x2 * ac - vector1->x2 * bc; + product->x3 = vector2->x3 * ac - vector1->x3 * bc; +} + // =================== Angle ==================== // float bgc_fp32_vector3_get_angle(const BGC_FP32_Vector3* vector1, const BGC_FP32_Vector3* vector2, const int angle_unit);