From b8d383da337f723438aad5ceb904476bbc4ce4ee Mon Sep 17 00:00:00 2001 From: Andrey Pokidov Date: Sun, 29 Mar 2026 22:06:01 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B8=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20s0=20->=20s,=20x1?= =?UTF-8?q?=20->=20x,=20x2=20->=20y,=20x3=20->=20z,=20=D1=87=D1=82=D0=BE?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=BB=D0=B6=D0=BD=D0=BE=20=D1=83=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B8=D1=82=D1=8C=20=D1=87=D0=B8=D1=82=D0=B0?= =?UTF-8?q?=D0=B5=D0=BC=D0=BE=D1=81=D1=82=D1=8C=20=D0=BA=D0=BE=D0=B4=D0=B0?= =?UTF-8?q?.=20=D0=A2=D0=B0=D0=BA=D0=B6=D0=B5=20=D0=BE=D0=B1=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=BE=D0=BA=D1=83?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- basic-geometry-dev/affine3.c | 14 +- basic-geometry-dev/main.c | 8 +- basic-geometry/dual-quaternion.h | 48 +- basic-geometry/dual-vector3.h | 72 +- basic-geometry/matrix2x2.c | 16 +- basic-geometry/matrix2x2.h | 228 +++---- basic-geometry/matrix2x3.c | 16 +- basic-geometry/matrix2x3.h | 292 ++++---- basic-geometry/matrix3x2.c | 16 +- basic-geometry/matrix3x2.h | 280 ++++---- basic-geometry/matrix3x3.c | 16 +- basic-geometry/matrix3x3.h | 500 +++++++------- basic-geometry/quaternion.c | 68 +- basic-geometry/quaternion.h | 1100 +++++++++++++++--------------- basic-geometry/rigid-pose3.h | 96 +-- basic-geometry/slerp3.c | 72 +- basic-geometry/slerp3.h | 32 +- basic-geometry/turn2.c | 4 +- basic-geometry/turn2.h | 44 +- basic-geometry/turn3.c | 156 ++--- basic-geometry/turn3.h | 68 +- basic-geometry/types.h | 12 +- basic-geometry/vector2.c | 4 +- basic-geometry/vector2.h | 200 +++--- basic-geometry/vector3.c | 4 +- basic-geometry/vector3.h | 420 ++++++------ docs/intro-eng.md | 41 +- docs/intro-rus.md | 55 +- docs/vector3-eng.md | 12 +- docs/vector3-rus.md | 24 +- docs/vector3/copy-eng.md | 39 +- docs/vector3/copy-rus.md | 38 +- docs/vector3/reset-eng.md | 25 +- docs/vector3/reset-rus.md | 25 +- docs/vector3/set-values-eng.md | 30 +- docs/vector3/set-values-rus.md | 33 +- docs/vector3/swap-eng.md | 36 +- docs/vector3/swap-rus.md | 30 +- 38 files changed, 2104 insertions(+), 2070 deletions(-) diff --git a/basic-geometry-dev/affine3.c b/basic-geometry-dev/affine3.c index b9d1e40..e59277f 100644 --- a/basic-geometry-dev/affine3.c +++ b/basic-geometry-dev/affine3.c @@ -48,9 +48,9 @@ BGC_FP32_Affine3* _create_bgc_affine3_random_list(int affine_amount) get_random_value_fp32() ); - position.shift.x1 = get_random_value_fp32(); - position.shift.x2 = get_random_value_fp32(); - position.shift.x3 = get_random_value_fp32(); + position.shift.x = get_random_value_fp32(); + position.shift.y = get_random_value_fp32(); + position.shift.z = get_random_value_fp32(); bgc_fp32_position3_get_affine(&affines[i], &position); } @@ -72,9 +72,9 @@ BGC_FP32_Vector3* _create_bgc_vector3_random_list(int amount) } for (int i = 0; i < amount; i++) { - vectors[i].x1 = get_random_value_fp32(); - vectors[i].x2 = get_random_value_fp32(); - vectors[i].x3 = get_random_value_fp32(); + vectors[i].x = get_random_value_fp32(); + vectors[i].y = get_random_value_fp32(); + vectors[i].z = get_random_value_fp32(); } return vectors; @@ -146,7 +146,7 @@ float test_bgc_affine3_performance(int affine_amount, int vector_per_affine) time = (float)(end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) * 0.000000001f; #endif // _WIN64 - printf("Result vector [0] = (%f, %f, %f)\n", result_vectors[0].x1, result_vectors[0].x2, result_vectors[0].x3); + printf("Result vector [0] = (%f, %f, %f)\n", result_vectors[0].x, result_vectors[0].y, result_vectors[0].z); free(result_vectors); free(source_vectors); diff --git a/basic-geometry-dev/main.c b/basic-geometry-dev/main.c index 2b540dc..fa3c21a 100644 --- a/basic-geometry-dev/main.c +++ b/basic-geometry-dev/main.c @@ -53,22 +53,22 @@ structure_fp32_t* make_structures(const unsigned int amount) void print_quaternion_fp32(const BGC_FP32_Quaternion* quaternion) { - printf("Quaternion FP32(s0 = %0.12f, x1 = %0.12f, x2 = %0.12f, x3 = %0.12f)\n", quaternion->s0, quaternion->x1, quaternion->x2, quaternion->x3); + printf("Quaternion FP32(s = %0.12f, x = %0.12f, y = %0.12f, z = %0.12f)\n", quaternion->s, quaternion->x, quaternion->y, quaternion->z); } void print_quaternion_fp64(const BGC_FP64_Quaternion* quaternion) { - printf("Quaternion FP64(s0 = %0.12f, x1 = %0.12f, x2 = %0.12f, x3 = %0.12f)\n", quaternion->s0, quaternion->x1, quaternion->x2, quaternion->x3); + printf("Quaternion FP64(s = %0.12f, x = %0.12f, y = %0.12f, z = %0.12f)\n", quaternion->s, quaternion->x, quaternion->y, quaternion->z); } void print_vector_fp32(const BGC_FP32_Vector3* vector) { - printf("(%f, %f, %f) / %f\n", vector->x1, vector->x2, vector->x3, bgc_fp32_vector3_get_length(vector)); + printf("(%f, %f, %f) / %f\n", vector->x, vector->y, vector->z, bgc_fp32_vector3_get_length(vector)); } void print_vector_fp64(const BGC_FP64_Vector3* vector) { - printf("(%lf, %lf, %lf) / %lf\n", vector->x1, vector->x2, vector->x3, bgc_fp64_vector3_get_length(vector)); + printf("(%lf, %lf, %lf) / %lf\n", vector->x, vector->y, vector->z, bgc_fp64_vector3_get_length(vector)); } void list_work(const uint_fast32_t amount, structure_fp32_t* list) diff --git a/basic-geometry/dual-quaternion.h b/basic-geometry/dual-quaternion.h index ce8966e..9337d33 100644 --- a/basic-geometry/dual-quaternion.h +++ b/basic-geometry/dual-quaternion.h @@ -214,48 +214,48 @@ inline void bgc_fp64_dual_quaternion_get_dual_conjugate(BGC_FP64_DualQuaternion* inline void bgc_fp32_dual_quaternion_fully_conjugate(BGC_FP32_DualQuaternion* const quaternion) { - quaternion->real_part.x1 = -quaternion->real_part.x1; - quaternion->real_part.x2 = -quaternion->real_part.x2; - quaternion->real_part.x3 = -quaternion->real_part.x3; + quaternion->real_part.x = -quaternion->real_part.x; + quaternion->real_part.y = -quaternion->real_part.y; + quaternion->real_part.z = -quaternion->real_part.z; - quaternion->dual_part.s0 = -quaternion->dual_part.s0; + quaternion->dual_part.s = -quaternion->dual_part.s; } inline void bgc_fp64_dual_quaternion_fully_conjugate(BGC_FP64_DualQuaternion* const quaternion) { - quaternion->real_part.x1 = -quaternion->real_part.x1; - quaternion->real_part.x2 = -quaternion->real_part.x2; - quaternion->real_part.x3 = -quaternion->real_part.x3; + quaternion->real_part.x = -quaternion->real_part.x; + quaternion->real_part.y = -quaternion->real_part.y; + quaternion->real_part.z = -quaternion->real_part.z; - quaternion->dual_part.s0 = -quaternion->dual_part.s0; + quaternion->dual_part.s = -quaternion->dual_part.s; } // ============ Get Fully Conjugate ============= // inline void bgc_fp32_dual_quaternion_get_fully_conjugate(BGC_FP32_DualQuaternion* const conjugate, const BGC_FP32_DualQuaternion* const quaternion) { - conjugate->real_part.s0 = quaternion->real_part.s0; - conjugate->real_part.x1 = -quaternion->real_part.x1; - conjugate->real_part.x2 = -quaternion->real_part.x2; - conjugate->real_part.x3 = -quaternion->real_part.x3; + conjugate->real_part.s = quaternion->real_part.s; + conjugate->real_part.x = -quaternion->real_part.x; + conjugate->real_part.y = -quaternion->real_part.y; + conjugate->real_part.z = -quaternion->real_part.z; - conjugate->dual_part.s0 = -quaternion->dual_part.s0; - conjugate->dual_part.x1 = quaternion->dual_part.x1; - conjugate->dual_part.x2 = quaternion->dual_part.x2; - conjugate->dual_part.x3 = quaternion->dual_part.x3; + conjugate->dual_part.s = -quaternion->dual_part.s; + conjugate->dual_part.x = quaternion->dual_part.x; + conjugate->dual_part.y = quaternion->dual_part.y; + conjugate->dual_part.z = quaternion->dual_part.z; } inline void bgc_fp64_dual_quaternion_get_fully_conjugate(BGC_FP64_DualQuaternion* const conjugate, const BGC_FP64_DualQuaternion* const quaternion) { - conjugate->real_part.s0 = quaternion->real_part.s0; - conjugate->real_part.x1 = -quaternion->real_part.x1; - conjugate->real_part.x2 = -quaternion->real_part.x2; - conjugate->real_part.x3 = -quaternion->real_part.x3; + conjugate->real_part.s = quaternion->real_part.s; + conjugate->real_part.x = -quaternion->real_part.x; + conjugate->real_part.y = -quaternion->real_part.y; + conjugate->real_part.z = -quaternion->real_part.z; - conjugate->dual_part.s0 = -quaternion->dual_part.s0; - conjugate->dual_part.x1 = quaternion->dual_part.x1; - conjugate->dual_part.x2 = quaternion->dual_part.x2; - conjugate->dual_part.x3 = quaternion->dual_part.x3; + conjugate->dual_part.s = -quaternion->dual_part.s; + conjugate->dual_part.x = quaternion->dual_part.x; + conjugate->dual_part.y = quaternion->dual_part.y; + conjugate->dual_part.z = quaternion->dual_part.z; } // ================= Normalize ================== // diff --git a/basic-geometry/dual-vector3.h b/basic-geometry/dual-vector3.h index 9717499..a52cc0c 100644 --- a/basic-geometry/dual-vector3.h +++ b/basic-geometry/dual-vector3.h @@ -210,64 +210,64 @@ inline void bgc_fp64_dual_vector3_multiply_by_conjugate_dual_number(BGC_FP64_Dua inline void bgc_fp32_dual_vector3_multiply_by_matrix3x3(BGC_FP32_DualVector3* const product, const BGC_FP32_DualVector3* const vector, const BGC_FP32_Matrix3x3* const matrix) { - const float real_x1 = vector->real_part.x1 * matrix->r1c1 + vector->real_part.x2 * matrix->r2c1 + vector->real_part.x3 * matrix->r3c1; - const float real_x2 = vector->real_part.x1 * matrix->r1c2 + vector->real_part.x2 * matrix->r2c2 + vector->real_part.x3 * matrix->r3c2; - const float real_x3 = vector->real_part.x1 * matrix->r1c3 + vector->real_part.x2 * matrix->r2c3 + vector->real_part.x3 * matrix->r3c3; + const float real_x = vector->real_part.x * matrix->r1c1 + vector->real_part.y * matrix->r2c1 + vector->real_part.z * matrix->r3c1; + const float real_y = vector->real_part.x * matrix->r1c2 + vector->real_part.y * matrix->r2c2 + vector->real_part.z * matrix->r3c2; + const float real_z = vector->real_part.x * matrix->r1c3 + vector->real_part.y * matrix->r2c3 + vector->real_part.z * matrix->r3c3; - const float dual_x1 = vector->real_part.x1 * matrix->r1c1 + vector->real_part.x2 * matrix->r2c1 + vector->real_part.x3 * matrix->r3c1; - const float dual_x2 = vector->real_part.x1 * matrix->r1c2 + vector->real_part.x2 * matrix->r2c2 + vector->real_part.x3 * matrix->r3c2; - const float dual_x3 = vector->real_part.x1 * matrix->r1c3 + vector->real_part.x2 * matrix->r2c3 + vector->real_part.x3 * matrix->r3c3; + const float dual_x = vector->real_part.x * matrix->r1c1 + vector->real_part.y * matrix->r2c1 + vector->real_part.z * matrix->r3c1; + const float dual_y = vector->real_part.x * matrix->r1c2 + vector->real_part.y * matrix->r2c2 + vector->real_part.z * matrix->r3c2; + const float dual_z = vector->real_part.x * matrix->r1c3 + vector->real_part.y * matrix->r2c3 + vector->real_part.z * matrix->r3c3; - product->real_part.x1 = real_x1; - product->real_part.x2 = real_x2; - product->real_part.x3 = real_x3; + product->real_part.x = real_x; + product->real_part.y = real_y; + product->real_part.z = real_z; - product->real_part.x1 = real_x1; - product->real_part.x2 = real_x2; - product->real_part.x3 = real_x3; + product->real_part.x = real_x; + product->real_part.y = real_y; + product->real_part.z = real_z; } inline void bgc_fp64_dual_vector3_multiply_by_matrix3x3(BGC_FP64_DualVector3* const product, const BGC_FP64_DualVector3* const vector, const BGC_FP64_Matrix3x3* const matrix) { - const double real_x1 = vector->real_part.x1 * matrix->r1c1 + vector->real_part.x2 * matrix->r2c1 + vector->real_part.x3 * matrix->r3c1; - const double real_x2 = vector->real_part.x1 * matrix->r1c2 + vector->real_part.x2 * matrix->r2c2 + vector->real_part.x3 * matrix->r3c2; - const double real_x3 = vector->real_part.x1 * matrix->r1c3 + vector->real_part.x2 * matrix->r2c3 + vector->real_part.x3 * matrix->r3c3; + const double real_x = vector->real_part.x * matrix->r1c1 + vector->real_part.y * matrix->r2c1 + vector->real_part.z * matrix->r3c1; + const double real_y = vector->real_part.x * matrix->r1c2 + vector->real_part.y * matrix->r2c2 + vector->real_part.z * matrix->r3c2; + const double real_z = vector->real_part.x * matrix->r1c3 + vector->real_part.y * matrix->r2c3 + vector->real_part.z * matrix->r3c3; - const double dual_x1 = vector->real_part.x1 * matrix->r1c1 + vector->real_part.x2 * matrix->r2c1 + vector->real_part.x3 * matrix->r3c1; - const double dual_x2 = vector->real_part.x1 * matrix->r1c2 + vector->real_part.x2 * matrix->r2c2 + vector->real_part.x3 * matrix->r3c2; - const double dual_x3 = vector->real_part.x1 * matrix->r1c3 + vector->real_part.x2 * matrix->r2c3 + vector->real_part.x3 * matrix->r3c3; + const double dual_x = vector->real_part.x * matrix->r1c1 + vector->real_part.y * matrix->r2c1 + vector->real_part.z * matrix->r3c1; + const double dual_y = vector->real_part.x * matrix->r1c2 + vector->real_part.y * matrix->r2c2 + vector->real_part.z * matrix->r3c2; + const double dual_z = vector->real_part.x * matrix->r1c3 + vector->real_part.y * matrix->r2c3 + vector->real_part.z * matrix->r3c3; - product->real_part.x1 = real_x1; - product->real_part.x2 = real_x2; - product->real_part.x3 = real_x3; + product->real_part.x = real_x; + product->real_part.y = real_y; + product->real_part.z = real_z; - product->real_part.x1 = real_x1; - product->real_part.x2 = real_x2; - product->real_part.x3 = real_x3; + product->real_part.x = real_x; + product->real_part.y = real_y; + product->real_part.z = real_z; } // ===== Restrict Left Dual Vector Product ====== // inline void _bgc_fp32_restrict_dual_vector3_multiply_by_matrix3x3(BGC_FP32_DualVector3* restrict const product, const BGC_FP32_DualVector3* const vector, const BGC_FP32_Matrix3x3* const matrix) { - product->real_part.x1 = vector->real_part.x1 * matrix->r1c1 + vector->real_part.x2 * matrix->r2c1 + vector->real_part.x3 * matrix->r3c1; - product->real_part.x2 = vector->real_part.x1 * matrix->r1c2 + vector->real_part.x2 * matrix->r2c2 + vector->real_part.x3 * matrix->r3c2; - product->real_part.x3 = vector->real_part.x1 * matrix->r1c3 + vector->real_part.x2 * matrix->r2c3 + vector->real_part.x3 * matrix->r3c3; + product->real_part.x = vector->real_part.x * matrix->r1c1 + vector->real_part.y * matrix->r2c1 + vector->real_part.z * matrix->r3c1; + product->real_part.y = vector->real_part.x * matrix->r1c2 + vector->real_part.y * matrix->r2c2 + vector->real_part.z * matrix->r3c2; + product->real_part.z = vector->real_part.x * matrix->r1c3 + vector->real_part.y * matrix->r2c3 + vector->real_part.z * matrix->r3c3; - product->real_part.x1 = vector->real_part.x1 * matrix->r1c1 + vector->real_part.x2 * matrix->r2c1 + vector->real_part.x3 * matrix->r3c1; - product->real_part.x2 = vector->real_part.x1 * matrix->r1c2 + vector->real_part.x2 * matrix->r2c2 + vector->real_part.x3 * matrix->r3c2; - product->real_part.x3 = vector->real_part.x1 * matrix->r1c3 + vector->real_part.x2 * matrix->r2c3 + vector->real_part.x3 * matrix->r3c3; + product->real_part.x = vector->real_part.x * matrix->r1c1 + vector->real_part.y * matrix->r2c1 + vector->real_part.z * matrix->r3c1; + product->real_part.y = vector->real_part.x * matrix->r1c2 + vector->real_part.y * matrix->r2c2 + vector->real_part.z * matrix->r3c2; + product->real_part.z = vector->real_part.x * matrix->r1c3 + vector->real_part.y * matrix->r2c3 + vector->real_part.z * matrix->r3c3; } inline void _bgc_fp64_restrict_dual_vector3_multiply_by_matrix3x3(BGC_FP64_DualVector3* restrict const product, const BGC_FP64_DualVector3* const vector, const BGC_FP64_Matrix3x3* const matrix) { - product->real_part.x1 = vector->real_part.x1 * matrix->r1c1 + vector->real_part.x2 * matrix->r2c1 + vector->real_part.x3 * matrix->r3c1; - product->real_part.x2 = vector->real_part.x1 * matrix->r1c2 + vector->real_part.x2 * matrix->r2c2 + vector->real_part.x3 * matrix->r3c2; - product->real_part.x3 = vector->real_part.x1 * matrix->r1c3 + vector->real_part.x2 * matrix->r2c3 + vector->real_part.x3 * matrix->r3c3; + product->real_part.x = vector->real_part.x * matrix->r1c1 + vector->real_part.y * matrix->r2c1 + vector->real_part.z * matrix->r3c1; + product->real_part.y = vector->real_part.x * matrix->r1c2 + vector->real_part.y * matrix->r2c2 + vector->real_part.z * matrix->r3c2; + product->real_part.z = vector->real_part.x * matrix->r1c3 + vector->real_part.y * matrix->r2c3 + vector->real_part.z * matrix->r3c3; - product->real_part.x1 = vector->real_part.x1 * matrix->r1c1 + vector->real_part.x2 * matrix->r2c1 + vector->real_part.x3 * matrix->r3c1; - product->real_part.x2 = vector->real_part.x1 * matrix->r1c2 + vector->real_part.x2 * matrix->r2c2 + vector->real_part.x3 * matrix->r3c2; - product->real_part.x3 = vector->real_part.x1 * matrix->r1c3 + vector->real_part.x2 * matrix->r2c3 + vector->real_part.x3 * matrix->r3c3; + product->real_part.x = vector->real_part.x * matrix->r1c1 + vector->real_part.y * matrix->r2c1 + vector->real_part.z * matrix->r3c1; + product->real_part.y = vector->real_part.x * matrix->r1c2 + vector->real_part.y * matrix->r2c2 + vector->real_part.z * matrix->r3c2; + product->real_part.z = vector->real_part.x * matrix->r1c3 + vector->real_part.y * matrix->r2c3 + vector->real_part.z * matrix->r3c3; } // =================== Divide =================== // diff --git a/basic-geometry/matrix2x2.c b/basic-geometry/matrix2x2.c index ee229ab..ffcb1e1 100644 --- a/basic-geometry/matrix2x2.c +++ b/basic-geometry/matrix2x2.c @@ -27,8 +27,8 @@ extern inline int bgc_fp64_matrix2x2_is_rotation(const BGC_FP64_Matrix2x2* const extern inline void bgc_fp32_matrix2x2_copy(BGC_FP32_Matrix2x2* const destination, const BGC_FP32_Matrix2x2* const source); extern inline void bgc_fp64_matrix2x2_copy(BGC_FP64_Matrix2x2* const destination, const BGC_FP64_Matrix2x2* const source); -extern inline void bgc_fp32_matrix2x2_swap(BGC_FP32_Matrix2x2* const matrix1, BGC_FP32_Matrix2x2* const matrix2); -extern inline void bgc_fp64_matrix2x2_swap(BGC_FP64_Matrix2x2* const matrix1, BGC_FP64_Matrix2x2* const matrix2); +extern inline void bgc_fp32_matrix2x2_swap(BGC_FP32_Matrix2x2* const matrix, BGC_FP32_Matrix2x2* const matriy); +extern inline void bgc_fp64_matrix2x2_swap(BGC_FP64_Matrix2x2* const matrix, BGC_FP64_Matrix2x2* const matriy); extern inline void bgc_fp64_matrix2x2_convert_to_fp32(BGC_FP32_Matrix2x2* const destination, const BGC_FP64_Matrix2x2* const source); extern inline void bgc_fp32_matrix2x2_convert_to_fp64(BGC_FP64_Matrix2x2* const destination, const BGC_FP32_Matrix2x2* const source); @@ -57,8 +57,8 @@ extern inline void bgc_fp64_matrix2x2_get_column(BGC_FP64_Vector2* const column, extern inline void bgc_fp32_matrix2x2_set_column(BGC_FP32_Matrix2x2* const matrix, const int column_number, const BGC_FP32_Vector2* const column); extern inline void bgc_fp64_matrix2x2_set_column(BGC_FP64_Matrix2x2* const matrix, const int column_number, const BGC_FP64_Vector2* const column); -extern inline void bgc_fp32_matrix2x2_add(BGC_FP32_Matrix2x2* const sum, const BGC_FP32_Matrix2x2* const matrix1, const BGC_FP32_Matrix2x2* const matrix2); -extern inline void bgc_fp64_matrix2x2_add(BGC_FP64_Matrix2x2* const sum, const BGC_FP64_Matrix2x2* const matrix1, const BGC_FP64_Matrix2x2* const matrix2); +extern inline void bgc_fp32_matrix2x2_add(BGC_FP32_Matrix2x2* const sum, const BGC_FP32_Matrix2x2* const matrix, const BGC_FP32_Matrix2x2* const matriy); +extern inline void bgc_fp64_matrix2x2_add(BGC_FP64_Matrix2x2* const sum, const BGC_FP64_Matrix2x2* const matrix, const BGC_FP64_Matrix2x2* const matriy); extern inline void bgc_fp32_matrix2x2_add_scaled(BGC_FP32_Matrix2x2* const sum, const BGC_FP32_Matrix2x2* const basic_matrix, const BGC_FP32_Matrix2x2* const scalable_matrix, const float scale); extern inline void bgc_fp64_matrix2x2_add_scaled(BGC_FP64_Matrix2x2* const sum, const BGC_FP64_Matrix2x2* const basic_matrix, const BGC_FP64_Matrix2x2* const scalable_matrix, const double scale); @@ -78,11 +78,11 @@ extern inline void bgc_fp64_matrix2x2_multiply_by_vector2(BGC_FP64_Vector2* cons extern inline void _bgc_fp32_restrict_matrix2x2_multiply_by_vector2(BGC_FP32_Vector2* restrict const product, const BGC_FP32_Matrix2x2* const matrix, const BGC_FP32_Vector2* const vector); extern inline void _bgc_fp64_restrict_matrix2x2_multiply_by_vector2(BGC_FP64_Vector2* restrict const product, const BGC_FP64_Matrix2x2* const matrix, const BGC_FP64_Vector2* const vector); -extern inline void bgc_fp32_matrix2x2_multiply_by_matrix2x2(BGC_FP32_Matrix2x2* const product, const BGC_FP32_Matrix2x2* const matrix1, const BGC_FP32_Matrix2x2* const matrix2); -extern inline void bgc_fp64_matrix2x2_multiply_by_matrix2x2(BGC_FP64_Matrix2x2* const product, const BGC_FP64_Matrix2x2* const matrix1, const BGC_FP64_Matrix2x2* const matrix2); +extern inline void bgc_fp32_matrix2x2_multiply_by_matrix2x2(BGC_FP32_Matrix2x2* const product, const BGC_FP32_Matrix2x2* const matrix, const BGC_FP32_Matrix2x2* const matriy); +extern inline void bgc_fp64_matrix2x2_multiply_by_matrix2x2(BGC_FP64_Matrix2x2* const product, const BGC_FP64_Matrix2x2* const matrix, const BGC_FP64_Matrix2x2* const matriy); -extern inline void bgc_fp32_matrix2x2_multiply_by_matrix3x2(BGC_FP32_Matrix3x2* const product, const BGC_FP32_Matrix2x2* const matrix1, const BGC_FP32_Matrix3x2* const matrix2); -extern inline void bgc_fp64_matrix2x2_multiply_by_matrix3x2(BGC_FP64_Matrix3x2* const product, const BGC_FP64_Matrix2x2* const matrix1, const BGC_FP64_Matrix3x2* const matrix2); +extern inline void bgc_fp32_matrix2x2_multiply_by_matrix3x2(BGC_FP32_Matrix3x2* const product, const BGC_FP32_Matrix2x2* const matrix, const BGC_FP32_Matrix3x2* const matriy); +extern inline void bgc_fp64_matrix2x2_multiply_by_matrix3x2(BGC_FP64_Matrix3x2* const product, const BGC_FP64_Matrix2x2* const matrix, const BGC_FP64_Matrix3x2* const matriy); extern inline int bgc_fp32_matrix2x2_divide_by_real_number(BGC_FP32_Matrix2x2* const quotient, const BGC_FP32_Matrix2x2* const dividend, const float divisor); extern inline int bgc_fp64_matrix2x2_divide_by_real_number(BGC_FP64_Matrix2x2* const quotient, const BGC_FP64_Matrix2x2* const dividend, const double divisor); diff --git a/basic-geometry/matrix2x2.h b/basic-geometry/matrix2x2.h index 9554690..8816b6c 100644 --- a/basic-geometry/matrix2x2.h +++ b/basic-geometry/matrix2x2.h @@ -175,46 +175,46 @@ inline void bgc_fp64_matrix2x2_copy(BGC_FP64_Matrix2x2* const destination, const // ==================== Swap ==================== // -inline void bgc_fp32_matrix2x2_swap(BGC_FP32_Matrix2x2* const matrix1, BGC_FP32_Matrix2x2* const matrix2) +inline void bgc_fp32_matrix2x2_swap(BGC_FP32_Matrix2x2* const matrix, BGC_FP32_Matrix2x2* const matriy) { - const float r1c1 = matrix2->r1c1; - const float r1c2 = matrix2->r1c2; + const float r1c1 = matriy->r1c1; + const float r1c2 = matriy->r1c2; - const float r2c1 = matrix2->r2c1; - const float r2c2 = matrix2->r2c2; + const float r2c1 = matriy->r2c1; + const float r2c2 = matriy->r2c2; - matrix2->r1c1 = matrix1->r1c1; - matrix2->r1c2 = matrix1->r1c2; + matriy->r1c1 = matrix->r1c1; + matriy->r1c2 = matrix->r1c2; - matrix2->r2c1 = matrix1->r2c1; - matrix2->r2c2 = matrix1->r2c2; + matriy->r2c1 = matrix->r2c1; + matriy->r2c2 = matrix->r2c2; - matrix1->r1c1 = r1c1; - matrix1->r1c2 = r1c2; + matrix->r1c1 = r1c1; + matrix->r1c2 = r1c2; - matrix1->r2c1 = r2c1; - matrix1->r2c2 = r2c2; + matrix->r2c1 = r2c1; + matrix->r2c2 = r2c2; } -inline void bgc_fp64_matrix2x2_swap(BGC_FP64_Matrix2x2* const matrix1, BGC_FP64_Matrix2x2* const matrix2) +inline void bgc_fp64_matrix2x2_swap(BGC_FP64_Matrix2x2* const matrix, BGC_FP64_Matrix2x2* const matriy) { - const double r1c1 = matrix2->r1c1; - const double r1c2 = matrix2->r1c2; + const double r1c1 = matriy->r1c1; + const double r1c2 = matriy->r1c2; - const double r2c1 = matrix2->r2c1; - const double r2c2 = matrix2->r2c2; + const double r2c1 = matriy->r2c1; + const double r2c2 = matriy->r2c2; - matrix2->r1c1 = matrix1->r1c1; - matrix2->r1c2 = matrix1->r1c2; + matriy->r1c1 = matrix->r1c1; + matriy->r1c2 = matrix->r1c2; - matrix2->r2c1 = matrix1->r2c1; - matrix2->r2c2 = matrix1->r2c2; + matriy->r2c1 = matrix->r2c1; + matriy->r2c2 = matrix->r2c2; - matrix1->r1c1 = r1c1; - matrix1->r1c2 = r1c2; + matrix->r1c1 = r1c1; + matrix->r1c2 = r1c2; - matrix1->r2c1 = r2c1; - matrix1->r2c2 = r2c2; + matrix->r2c1 = r2c1; + matrix->r2c2 = r2c2; } // ================== Convert =================== // @@ -346,37 +346,37 @@ inline void bgc_fp64_matrix2x2_get_transposed(BGC_FP64_Matrix2x2* const transpos inline void bgc_fp32_matrix2x2_get_row(BGC_FP32_Vector2* const row, const BGC_FP32_Matrix2x2* const matrix, const int row_number) { if (row_number == 1) { - row->x1 = matrix->r1c1; - row->x2 = matrix->r1c2; + row->x = matrix->r1c1; + row->y = matrix->r1c2; return; } if (row_number == 2) { - row->x1 = matrix->r2c1; - row->x2 = matrix->r2c2; + row->x = matrix->r2c1; + row->y = matrix->r2c2; return; } - row->x1 = 0.0f; - row->x2 = 0.0f; + row->x = 0.0f; + row->y = 0.0f; } inline void bgc_fp64_matrix2x2_get_row(BGC_FP64_Vector2* const row, const BGC_FP64_Matrix2x2* const matrix, const int row_number) { if (row_number == 1) { - row->x1 = matrix->r1c1; - row->x2 = matrix->r1c2; + row->x = matrix->r1c1; + row->y = matrix->r1c2; return; } if (row_number == 2) { - row->x1 = matrix->r2c1; - row->x2 = matrix->r2c2; + row->x = matrix->r2c1; + row->y = matrix->r2c2; return; } - row->x1 = 0.0; - row->x2 = 0.0; + row->x = 0.0; + row->y = 0.0; } // ================== Set Row =================== // @@ -384,28 +384,28 @@ inline void bgc_fp64_matrix2x2_get_row(BGC_FP64_Vector2* const row, const BGC_FP inline void bgc_fp32_matrix2x2_set_row(BGC_FP32_Matrix2x2* const matrix, const int row_number, const BGC_FP32_Vector2* const row) { if (row_number == 1) { - matrix->r1c1 = row->x1; - matrix->r1c2 = row->x2; + matrix->r1c1 = row->x; + matrix->r1c2 = row->y; return; } if (row_number == 2) { - matrix->r2c1 = row->x1; - matrix->r2c2 = row->x2; + matrix->r2c1 = row->x; + matrix->r2c2 = row->y; } } inline void bgc_fp64_matrix2x2_set_row(BGC_FP64_Matrix2x2* const matrix, const int row_number, const BGC_FP64_Vector2* const row) { if (row_number == 1) { - matrix->r1c1 = row->x1; - matrix->r1c2 = row->x2; + matrix->r1c1 = row->x; + matrix->r1c2 = row->y; return; } if (row_number == 2) { - matrix->r2c1 = row->x1; - matrix->r2c2 = row->x2; + matrix->r2c1 = row->x; + matrix->r2c2 = row->y; } } @@ -414,37 +414,37 @@ inline void bgc_fp64_matrix2x2_set_row(BGC_FP64_Matrix2x2* const matrix, const i inline void bgc_fp32_matrix2x2_get_column(BGC_FP32_Vector2* const column, const BGC_FP32_Matrix2x2* const matrix, const int column_number) { if (column_number == 1) { - column->x1 = matrix->r1c1; - column->x2 = matrix->r2c1; + column->x = matrix->r1c1; + column->y = matrix->r2c1; return; } if (column_number == 2) { - column->x1 = matrix->r1c2; - column->x2 = matrix->r2c2; + column->x = matrix->r1c2; + column->y = matrix->r2c2; return; } - column->x1 = 0.0f; - column->x2 = 0.0f; + column->x = 0.0f; + column->y = 0.0f; } inline void bgc_fp64_matrix2x2_get_column(BGC_FP64_Vector2* const column, const BGC_FP64_Matrix2x2* const matrix, const int column_number) { if (column_number == 1) { - column->x1 = matrix->r1c1; - column->x2 = matrix->r2c1; + column->x = matrix->r1c1; + column->y = matrix->r2c1; return; } if (column_number == 2) { - column->x1 = matrix->r1c2; - column->x2 = matrix->r2c2; + column->x = matrix->r1c2; + column->y = matrix->r2c2; return; } - column->x1 = 0.0; - column->x2 = 0.0; + column->x = 0.0; + column->y = 0.0; } // ================= Set Column ================= // @@ -452,49 +452,49 @@ inline void bgc_fp64_matrix2x2_get_column(BGC_FP64_Vector2* const column, const inline void bgc_fp32_matrix2x2_set_column(BGC_FP32_Matrix2x2* const matrix, const int column_number, const BGC_FP32_Vector2* const column) { if (column_number == 1) { - matrix->r1c1 = column->x1; - matrix->r2c1 = column->x2; + matrix->r1c1 = column->x; + matrix->r2c1 = column->y; return; } if (column_number == 2) { - matrix->r1c2 = column->x1; - matrix->r2c2 = column->x2; + matrix->r1c2 = column->x; + matrix->r2c2 = column->y; } } inline void bgc_fp64_matrix2x2_set_column(BGC_FP64_Matrix2x2* const matrix, const int column_number, const BGC_FP64_Vector2* const column) { if (column_number == 1) { - matrix->r1c1 = column->x1; - matrix->r2c1 = column->x2; + matrix->r1c1 = column->x; + matrix->r2c1 = column->y; return; } if (column_number == 2) { - matrix->r1c2 = column->x1; - matrix->r2c2 = column->x2; + matrix->r1c2 = column->x; + matrix->r2c2 = column->y; } } // ==================== Add ===================== // -inline void bgc_fp32_matrix2x2_add(BGC_FP32_Matrix2x2* const sum, const BGC_FP32_Matrix2x2* const matrix1, const BGC_FP32_Matrix2x2* const matrix2) +inline void bgc_fp32_matrix2x2_add(BGC_FP32_Matrix2x2* const sum, const BGC_FP32_Matrix2x2* const matrix, const BGC_FP32_Matrix2x2* const matriy) { - sum->r1c1 = matrix1->r1c1 + matrix2->r1c1; - sum->r1c2 = matrix1->r1c2 + matrix2->r1c2; + sum->r1c1 = matrix->r1c1 + matriy->r1c1; + sum->r1c2 = matrix->r1c2 + matriy->r1c2; - sum->r2c1 = matrix1->r2c1 + matrix2->r2c1; - sum->r2c2 = matrix1->r2c2 + matrix2->r2c2; + sum->r2c1 = matrix->r2c1 + matriy->r2c1; + sum->r2c2 = matrix->r2c2 + matriy->r2c2; } -inline void bgc_fp64_matrix2x2_add(BGC_FP64_Matrix2x2* const sum, const BGC_FP64_Matrix2x2* const matrix1, const BGC_FP64_Matrix2x2* const matrix2) +inline void bgc_fp64_matrix2x2_add(BGC_FP64_Matrix2x2* const sum, const BGC_FP64_Matrix2x2* const matrix, const BGC_FP64_Matrix2x2* const matriy) { - sum->r1c1 = matrix1->r1c1 + matrix2->r1c1; - sum->r1c2 = matrix1->r1c2 + matrix2->r1c2; + sum->r1c1 = matrix->r1c1 + matriy->r1c1; + sum->r1c2 = matrix->r1c2 + matriy->r1c2; - sum->r2c1 = matrix1->r2c1 + matrix2->r2c1; - sum->r2c2 = matrix1->r2c2 + matrix2->r2c2; + sum->r2c1 = matrix->r2c1 + matriy->r2c1; + sum->r2c2 = matrix->r2c2 + matriy->r2c2; } // ================= Add Scaled ================= // @@ -581,45 +581,45 @@ inline void bgc_fp64_matrix2x2_multiply_by_real_number(BGC_FP64_Matrix2x2* const inline void bgc_fp32_matrix2x2_multiply_by_vector2(BGC_FP32_Vector2* const product, const BGC_FP32_Matrix2x2* const matrix, const BGC_FP32_Vector2* const vector) { - const float x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2; - const float x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2; + const float x = matrix->r1c1 * vector->x + matrix->r1c2 * vector->y; + const float y = matrix->r2c1 * vector->x + matrix->r2c2 * vector->y; - product->x1 = x1; - product->x2 = x2; + product->x = x; + product->y = y; } inline void bgc_fp64_matrix2x2_multiply_by_vector2(BGC_FP64_Vector2* const product, const BGC_FP64_Matrix2x2* const matrix, const BGC_FP64_Vector2* const vector) { - const double x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2; - const double x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2; + const double x = matrix->r1c1 * vector->x + matrix->r1c2 * vector->y; + const double y = matrix->r2c1 * vector->x + matrix->r2c2 * vector->y; - product->x1 = x1; - product->x2 = x2; + product->x = x; + product->y = y; } // ======= Restrict Right Vector Product ======== // inline void _bgc_fp32_restrict_matrix2x2_multiply_by_vector2(BGC_FP32_Vector2* restrict const product, const BGC_FP32_Matrix2x2* const matrix, const BGC_FP32_Vector2* const vector) { - product->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2; - product->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2; + product->x = matrix->r1c1 * vector->x + matrix->r1c2 * vector->y; + product->y = matrix->r2c1 * vector->x + matrix->r2c2 * vector->y; } inline void _bgc_fp64_restrict_matrix2x2_multiply_by_vector2(BGC_FP64_Vector2* restrict const product, const BGC_FP64_Matrix2x2* const matrix, const BGC_FP64_Vector2* const vector) { - product->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2; - product->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2; + product->x = matrix->r1c1 * vector->x + matrix->r1c2 * vector->y; + product->y = matrix->r2c1 * vector->x + matrix->r2c2 * vector->y; } -// ========== Matrix Product 2x2 at 2x2 ========= // +// ========== Matrix Product 2y at 2y ========= // -inline void bgc_fp32_matrix2x2_multiply_by_matrix2x2(BGC_FP32_Matrix2x2* const product, const BGC_FP32_Matrix2x2* const matrix1, const BGC_FP32_Matrix2x2* const matrix2) +inline void bgc_fp32_matrix2x2_multiply_by_matrix2x2(BGC_FP32_Matrix2x2* const product, const BGC_FP32_Matrix2x2* const matrix, const BGC_FP32_Matrix2x2* const matriy) { - const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; - const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; + const float r1c1 = matrix->r1c1 * matriy->r1c1 + matrix->r1c2 * matriy->r2c1; + const float r1c2 = matrix->r1c1 * matriy->r1c2 + matrix->r1c2 * matriy->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 r2c1 = matrix->r2c1 * matriy->r1c1 + matrix->r2c2 * matriy->r2c1; + const float r2c2 = matrix->r2c1 * matriy->r1c2 + matrix->r2c2 * matriy->r2c2; product->r1c1 = r1c1; product->r1c2 = r1c2; @@ -628,13 +628,13 @@ inline void bgc_fp32_matrix2x2_multiply_by_matrix2x2(BGC_FP32_Matrix2x2* const p product->r2c2 = r2c2; } -inline void bgc_fp64_matrix2x2_multiply_by_matrix2x2(BGC_FP64_Matrix2x2* const product, const BGC_FP64_Matrix2x2* const matrix1, const BGC_FP64_Matrix2x2* const matrix2) +inline void bgc_fp64_matrix2x2_multiply_by_matrix2x2(BGC_FP64_Matrix2x2* const product, const BGC_FP64_Matrix2x2* const matrix, const BGC_FP64_Matrix2x2* const matriy) { - const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; - const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; + const double r1c1 = matrix->r1c1 * matriy->r1c1 + matrix->r1c2 * matriy->r2c1; + const double r1c2 = matrix->r1c1 * matriy->r1c2 + matrix->r1c2 * matriy->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 r2c1 = matrix->r2c1 * matriy->r1c1 + matrix->r2c2 * matriy->r2c1; + const double r2c2 = matrix->r2c1 * matriy->r1c2 + matrix->r2c2 * matriy->r2c2; product->r1c1 = r1c1; product->r1c2 = r1c2; @@ -643,17 +643,17 @@ inline void bgc_fp64_matrix2x2_multiply_by_matrix2x2(BGC_FP64_Matrix2x2* const p product->r2c2 = r2c2; } -// ========== Matrix Product 2x2 at 3x2 ========= // +// ========== Matrix Product 2y at 3y ========= // -inline void bgc_fp32_matrix2x2_multiply_by_matrix3x2(BGC_FP32_Matrix3x2* const product, const BGC_FP32_Matrix2x2* const matrix1, const BGC_FP32_Matrix3x2* const matrix2) +inline void bgc_fp32_matrix2x2_multiply_by_matrix3x2(BGC_FP32_Matrix3x2* const product, const BGC_FP32_Matrix2x2* const matrix, const BGC_FP32_Matrix3x2* const matriy) { - 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 r1c1 = matrix->r1c1 * matriy->r1c1 + matrix->r1c2 * matriy->r2c1; + const float r1c2 = matrix->r1c1 * matriy->r1c2 + matrix->r1c2 * matriy->r2c2; + const float r1c3 = matrix->r1c1 * matriy->r1c3 + matrix->r1c2 * matriy->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; + const float r2c1 = matrix->r2c1 * matriy->r1c1 + matrix->r2c2 * matriy->r2c1; + const float r2c2 = matrix->r2c1 * matriy->r1c2 + matrix->r2c2 * matriy->r2c2; + const float r2c3 = matrix->r2c1 * matriy->r1c3 + matrix->r2c2 * matriy->r2c3; product->r1c1 = r1c1; product->r1c2 = r1c2; @@ -664,15 +664,15 @@ inline void bgc_fp32_matrix2x2_multiply_by_matrix3x2(BGC_FP32_Matrix3x2* const p product->r2c3 = r2c3; } -inline void bgc_fp64_matrix2x2_multiply_by_matrix3x2(BGC_FP64_Matrix3x2* const product, const BGC_FP64_Matrix2x2* const matrix1, const BGC_FP64_Matrix3x2* const matrix2) +inline void bgc_fp64_matrix2x2_multiply_by_matrix3x2(BGC_FP64_Matrix3x2* const product, const BGC_FP64_Matrix2x2* const matrix, const BGC_FP64_Matrix3x2* const matriy) { - 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 r1c1 = matrix->r1c1 * matriy->r1c1 + matrix->r1c2 * matriy->r2c1; + const double r1c2 = matrix->r1c1 * matriy->r1c2 + matrix->r1c2 * matriy->r2c2; + const double r1c3 = matrix->r1c1 * matriy->r1c3 + matrix->r1c2 * matriy->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; + const double r2c1 = matrix->r2c1 * matriy->r1c1 + matrix->r2c2 * matriy->r2c1; + const double r2c2 = matrix->r2c1 * matriy->r1c2 + matrix->r2c2 * matriy->r2c2; + const double r2c3 = matrix->r2c1 * matriy->r1c3 + matrix->r2c2 * matriy->r2c3; product->r1c1 = r1c1; product->r1c2 = r1c2; diff --git a/basic-geometry/matrix2x3.c b/basic-geometry/matrix2x3.c index 1874f12..9733d8b 100644 --- a/basic-geometry/matrix2x3.c +++ b/basic-geometry/matrix2x3.c @@ -6,8 +6,8 @@ extern inline void bgc_fp64_matrix2x3_reset(BGC_FP64_Matrix2x3* const matrix); extern inline void bgc_fp32_matrix2x3_copy(BGC_FP32_Matrix2x3* const destination, const BGC_FP32_Matrix2x3* const source); extern inline void bgc_fp64_matrix2x3_copy(BGC_FP64_Matrix2x3* const destination, const BGC_FP64_Matrix2x3* const source); -extern inline void bgc_fp32_matrix2x3_swap(BGC_FP32_Matrix2x3* const matrix1, BGC_FP32_Matrix2x3* const matrix2); -extern inline void bgc_fp64_matrix2x3_swap(BGC_FP64_Matrix2x3* const matrix1, BGC_FP64_Matrix2x3* const matrix2); +extern inline void bgc_fp32_matrix2x3_swap(BGC_FP32_Matrix2x3* const matrix, BGC_FP32_Matrix2x3* const matriy); +extern inline void bgc_fp64_matrix2x3_swap(BGC_FP64_Matrix2x3* const matrix, BGC_FP64_Matrix2x3* const matriy); extern inline void bgc_fp32_matrix2x3_convert_to_fp64(BGC_FP64_Matrix2x3* const destination, const BGC_FP32_Matrix2x3* const source); extern inline void bgc_fp64_matrix2x3_convert_to_fp32(BGC_FP32_Matrix2x3* const destination, const BGC_FP64_Matrix2x3* const source); @@ -27,8 +27,8 @@ extern inline void bgc_fp64_matrix2x3_get_column(BGC_FP64_Vector3* const column, extern inline void bgc_fp32_matrix2x3_set_column(BGC_FP32_Matrix2x3* const matrix, const int number, const BGC_FP32_Vector3* const column); extern inline void bgc_fp64_matrix2x3_set_column(BGC_FP64_Matrix2x3* const matrix, const int number, const BGC_FP64_Vector3* const column); -extern inline void bgc_fp32_matrix2x3_add(BGC_FP32_Matrix2x3* const sum, const BGC_FP32_Matrix2x3* const matrix1, const BGC_FP32_Matrix2x3* const matrix2); -extern inline void bgc_fp64_matrix2x3_add(BGC_FP64_Matrix2x3* const sum, const BGC_FP64_Matrix2x3* const matrix1, const BGC_FP64_Matrix2x3* const matrix2); +extern inline void bgc_fp32_matrix2x3_add(BGC_FP32_Matrix2x3* const sum, const BGC_FP32_Matrix2x3* const matrix, const BGC_FP32_Matrix2x3* const matriy); +extern inline void bgc_fp64_matrix2x3_add(BGC_FP64_Matrix2x3* const sum, const BGC_FP64_Matrix2x3* const matrix, const BGC_FP64_Matrix2x3* const matriy); extern inline void bgc_fp32_matrix2x3_add_scaled(BGC_FP32_Matrix2x3* const sum, const BGC_FP32_Matrix2x3* const basic_matrix, const BGC_FP32_Matrix2x3* const scalable_matrix, const float scale); extern inline void bgc_fp64_matrix2x3_add_scaled(BGC_FP64_Matrix2x3* const sum, const BGC_FP64_Matrix2x3* const basic_matrix, const BGC_FP64_Matrix2x3* const scalable_matrix, const double scale); @@ -45,11 +45,11 @@ extern inline void bgc_fp64_matrix2x3_multiply_by_real_number(BGC_FP64_Matrix2x3 extern inline void bgc_fp32_matrix2x3_multiply_by_vector2(BGC_FP32_Vector3* const product, const BGC_FP32_Matrix2x3* const matrix, const BGC_FP32_Vector2* const vector); extern inline void bgc_fp64_matrix2x3_multiply_by_vector2(BGC_FP64_Vector3* const product, const BGC_FP64_Matrix2x3* const matrix, const BGC_FP64_Vector2* const vector); -extern inline void bgc_fp32_matrix2x3_multiply_by_matrix2x2(BGC_FP32_Matrix2x3* const product, const BGC_FP32_Matrix2x3* const matrix1, const BGC_FP32_Matrix2x2* const matrix2); -extern inline void bgc_fp64_matrix2x3_multiply_by_matrix2x2(BGC_FP64_Matrix2x3* const product, const BGC_FP64_Matrix2x3* const matrix1, const BGC_FP64_Matrix2x2* const matrix2); +extern inline void bgc_fp32_matrix2x3_multiply_by_matrix2x2(BGC_FP32_Matrix2x3* const product, const BGC_FP32_Matrix2x3* const matrix, const BGC_FP32_Matrix2x2* const matriy); +extern inline void bgc_fp64_matrix2x3_multiply_by_matrix2x2(BGC_FP64_Matrix2x3* const product, const BGC_FP64_Matrix2x3* const matrix, const BGC_FP64_Matrix2x2* const matriy); -extern inline void bgc_fp32_matrix2x3_multiply_by_matrix3x2(BGC_FP32_Matrix3x3* const product, const BGC_FP32_Matrix2x3* const matrix1, const BGC_FP32_Matrix3x2* const matrix2); -extern inline void bgc_fp64_matrix2x3_multiply_by_matrix3x2(BGC_FP64_Matrix3x3* const product, const BGC_FP64_Matrix2x3* const matrix1, const BGC_FP64_Matrix3x2* const matrix2); +extern inline void bgc_fp32_matrix2x3_multiply_by_matrix3x2(BGC_FP32_Matrix3x3* const product, const BGC_FP32_Matrix2x3* const matrix, const BGC_FP32_Matrix3x2* const matriy); +extern inline void bgc_fp64_matrix2x3_multiply_by_matrix3x2(BGC_FP64_Matrix3x3* const product, const BGC_FP64_Matrix2x3* const matrix, const BGC_FP64_Matrix3x2* const matriy); extern inline int bgc_fp32_matrix2x3_divide_by_real_number(BGC_FP32_Matrix2x3* const quotient, const BGC_FP32_Matrix2x3* const dividend, const float divisor); extern inline int bgc_fp64_matrix2x3_divide_by_real_number(BGC_FP64_Matrix2x3* const quotient, const BGC_FP64_Matrix2x3* const dividend, const double divisor); diff --git a/basic-geometry/matrix2x3.h b/basic-geometry/matrix2x3.h index a32b374..e74aa46 100644 --- a/basic-geometry/matrix2x3.h +++ b/basic-geometry/matrix2x3.h @@ -60,64 +60,64 @@ inline void bgc_fp64_matrix2x3_copy(BGC_FP64_Matrix2x3* const destination, const // ==================== Swap ==================== // -inline void bgc_fp32_matrix2x3_swap(BGC_FP32_Matrix2x3* const matrix1, BGC_FP32_Matrix2x3* const matrix2) +inline void bgc_fp32_matrix2x3_swap(BGC_FP32_Matrix2x3* const matrix, BGC_FP32_Matrix2x3* const matriy) { - const float r1c1 = matrix2->r1c1; - const float r1c2 = matrix2->r1c2; + const float r1c1 = matriy->r1c1; + const float r1c2 = matriy->r1c2; - const float r2c1 = matrix2->r2c1; - const float r2c2 = matrix2->r2c2; + const float r2c1 = matriy->r2c1; + const float r2c2 = matriy->r2c2; - const float r3c1 = matrix2->r3c1; - const float r3c2 = matrix2->r3c2; + const float r3c1 = matriy->r3c1; + const float r3c2 = matriy->r3c2; - matrix2->r1c1 = matrix1->r1c1; - matrix2->r1c2 = matrix1->r1c2; + matriy->r1c1 = matrix->r1c1; + matriy->r1c2 = matrix->r1c2; - matrix2->r2c1 = matrix1->r2c1; - matrix2->r2c2 = matrix1->r2c2; + matriy->r2c1 = matrix->r2c1; + matriy->r2c2 = matrix->r2c2; - matrix2->r3c1 = matrix1->r3c1; - matrix2->r3c2 = matrix1->r3c2; + matriy->r3c1 = matrix->r3c1; + matriy->r3c2 = matrix->r3c2; - matrix1->r1c1 = r1c1; - matrix1->r1c2 = r1c2; + matrix->r1c1 = r1c1; + matrix->r1c2 = r1c2; - matrix1->r2c1 = r2c1; - matrix1->r2c2 = r2c2; + matrix->r2c1 = r2c1; + matrix->r2c2 = r2c2; - matrix1->r3c1 = r3c1; - matrix1->r3c2 = r3c2; + matrix->r3c1 = r3c1; + matrix->r3c2 = r3c2; } -inline void bgc_fp64_matrix2x3_swap(BGC_FP64_Matrix2x3* const matrix1, BGC_FP64_Matrix2x3* const matrix2) +inline void bgc_fp64_matrix2x3_swap(BGC_FP64_Matrix2x3* const matrix, BGC_FP64_Matrix2x3* const matriy) { - const double r1c1 = matrix2->r1c1; - const double r1c2 = matrix2->r1c2; + const double r1c1 = matriy->r1c1; + const double r1c2 = matriy->r1c2; - const double r2c1 = matrix2->r2c1; - const double r2c2 = matrix2->r2c2; + const double r2c1 = matriy->r2c1; + const double r2c2 = matriy->r2c2; - const double r3c1 = matrix2->r3c1; - const double r3c2 = matrix2->r3c2; + const double r3c1 = matriy->r3c1; + const double r3c2 = matriy->r3c2; - matrix2->r1c1 = matrix1->r1c1; - matrix2->r1c2 = matrix1->r1c2; + matriy->r1c1 = matrix->r1c1; + matriy->r1c2 = matrix->r1c2; - matrix2->r2c1 = matrix1->r2c1; - matrix2->r2c2 = matrix1->r2c2; + matriy->r2c1 = matrix->r2c1; + matriy->r2c2 = matrix->r2c2; - matrix2->r3c1 = matrix1->r3c1; - matrix2->r3c2 = matrix1->r3c2; + matriy->r3c1 = matrix->r3c1; + matriy->r3c2 = matrix->r3c2; - matrix1->r1c1 = r1c1; - matrix1->r1c2 = r1c2; + matrix->r1c1 = r1c1; + matrix->r1c2 = r1c2; - matrix1->r2c1 = r2c1; - matrix1->r2c2 = r2c2; + matrix->r2c1 = r2c1; + matrix->r2c2 = r2c2; - matrix1->r3c1 = r3c1; - matrix1->r3c2 = r3c2; + matrix->r3c1 = r3c1; + matrix->r3c2 = r3c2; } // ================== Convert =================== // @@ -177,49 +177,49 @@ inline void bgc_fp64_matrix2x3_get_transposed(BGC_FP64_Matrix2x3* const transpos inline void bgc_fp32_matrix2x3_get_row(BGC_FP32_Vector2* const row, const BGC_FP32_Matrix2x3* const matrix, const int row_number) { if (row_number == 1) { - row->x1 = matrix->r1c1; - row->x2 = matrix->r1c2; + row->x = matrix->r1c1; + row->y = matrix->r1c2; return; } if (row_number == 2) { - row->x1 = matrix->r2c1; - row->x2 = matrix->r2c2; + row->x = matrix->r2c1; + row->y = matrix->r2c2; return; } if (row_number == 3) { - row->x1 = matrix->r3c1; - row->x2 = matrix->r3c2; + row->x = matrix->r3c1; + row->y = matrix->r3c2; return; } - row->x1 = 0.0f; - row->x2 = 0.0f; + row->x = 0.0f; + row->y = 0.0f; } inline void bgc_fp64_matrix2x3_get_row(BGC_FP64_Vector2* const row, const BGC_FP64_Matrix2x3* const matrix, const int row_number) { if (row_number == 1) { - row->x1 = matrix->r1c1; - row->x2 = matrix->r1c2; + row->x = matrix->r1c1; + row->y = matrix->r1c2; return; } if (row_number == 2) { - row->x1 = matrix->r2c1; - row->x2 = matrix->r2c2; + row->x = matrix->r2c1; + row->y = matrix->r2c2; return; } if (row_number == 3) { - row->x1 = matrix->r3c1; - row->x2 = matrix->r3c2; + row->x = matrix->r3c1; + row->y = matrix->r3c2; return; } - row->x1 = 0.0f; - row->x2 = 0.0f; + row->x = 0.0f; + row->y = 0.0f; } // ================== Set Row =================== // @@ -227,40 +227,40 @@ inline void bgc_fp64_matrix2x3_get_row(BGC_FP64_Vector2* const row, const BGC_FP inline void bgc_fp32_matrix2x3_set_row(BGC_FP32_Matrix2x3* const matrix, const int row_number, const BGC_FP32_Vector2* const row) { if (row_number == 1) { - matrix->r1c1 = row->x1; - matrix->r1c2 = row->x2; + matrix->r1c1 = row->x; + matrix->r1c2 = row->y; return; } if (row_number == 2) { - matrix->r2c1 = row->x1; - matrix->r2c2 = row->x2; + matrix->r2c1 = row->x; + matrix->r2c2 = row->y; return; } if (row_number == 3) { - matrix->r3c1 = row->x1; - matrix->r3c2 = row->x2; + matrix->r3c1 = row->x; + matrix->r3c2 = row->y; } } inline void bgc_fp64_matrix2x3_set_row(BGC_FP64_Matrix2x3* const matrix, const int row_number, const BGC_FP64_Vector2* const row) { if (row_number == 1) { - matrix->r1c1 = row->x1; - matrix->r1c2 = row->x2; + matrix->r1c1 = row->x; + matrix->r1c2 = row->y; return; } if (row_number == 2) { - matrix->r2c1 = row->x1; - matrix->r2c2 = row->x2; + matrix->r2c1 = row->x; + matrix->r2c2 = row->y; return; } if (row_number == 3) { - matrix->r3c1 = row->x1; - matrix->r3c2 = row->x2; + matrix->r3c1 = row->x; + matrix->r3c2 = row->y; } } @@ -269,32 +269,32 @@ inline void bgc_fp64_matrix2x3_set_row(BGC_FP64_Matrix2x3* const matrix, const i inline void bgc_fp32_matrix2x3_get_column(BGC_FP32_Vector3* const column, const BGC_FP32_Matrix2x3* const matrix, const int column_number) { if (column_number == 1) { - column->x1 = matrix->r1c1; - column->x2 = matrix->r2c1; - column->x3 = matrix->r3c1; + column->x = matrix->r1c1; + column->y = matrix->r2c1; + column->z = matrix->r3c1; return; } if (column_number == 2) { - column->x1 = matrix->r1c2; - column->x2 = matrix->r2c2; - column->x3 = matrix->r3c2; + column->x = matrix->r1c2; + column->y = matrix->r2c2; + column->z = matrix->r3c2; } } inline void bgc_fp64_matrix2x3_get_column(BGC_FP64_Vector3* const column, const BGC_FP64_Matrix2x3* const matrix, const int column_number) { if (column_number == 1) { - column->x1 = matrix->r1c1; - column->x2 = matrix->r2c1; - column->x3 = matrix->r3c1; + column->x = matrix->r1c1; + column->y = matrix->r2c1; + column->z = matrix->r3c1; return; } if (column_number == 2) { - column->x1 = matrix->r1c2; - column->x2 = matrix->r2c2; - column->x3 = matrix->r3c2; + column->x = matrix->r1c2; + column->y = matrix->r2c2; + column->z = matrix->r3c2; } } @@ -303,59 +303,59 @@ inline void bgc_fp64_matrix2x3_get_column(BGC_FP64_Vector3* const column, const inline void bgc_fp32_matrix2x3_set_column(BGC_FP32_Matrix2x3* const matrix, const int column_number, const BGC_FP32_Vector3* const column) { if (column_number == 1) { - matrix->r1c1 = column->x1; - matrix->r2c1 = column->x2; - matrix->r3c1 = column->x3; + matrix->r1c1 = column->x; + matrix->r2c1 = column->y; + matrix->r3c1 = column->z; return; } if (column_number == 2) { - matrix->r1c2 = column->x1; - matrix->r2c2 = column->x2; - matrix->r3c2 = column->x3; + matrix->r1c2 = column->x; + matrix->r2c2 = column->y; + matrix->r3c2 = column->z; } } inline void bgc_fp64_matrix2x3_set_column(BGC_FP64_Matrix2x3* const matrix, const int column_number, const BGC_FP64_Vector3* const column) { if (column_number == 1) { - matrix->r1c1 = column->x1; - matrix->r2c1 = column->x2; - matrix->r3c1 = column->x3; + matrix->r1c1 = column->x; + matrix->r2c1 = column->y; + matrix->r3c1 = column->z; return; } if (column_number == 2) { - matrix->r1c2 = column->x1; - matrix->r2c2 = column->x2; - matrix->r3c2 = column->x3; + matrix->r1c2 = column->x; + matrix->r2c2 = column->y; + matrix->r3c2 = column->z; } } // ==================== Add ===================== // -inline void bgc_fp32_matrix2x3_add(BGC_FP32_Matrix2x3* const sum, const BGC_FP32_Matrix2x3* const matrix1, const BGC_FP32_Matrix2x3* const matrix2) +inline void bgc_fp32_matrix2x3_add(BGC_FP32_Matrix2x3* const sum, const BGC_FP32_Matrix2x3* const matrix, const BGC_FP32_Matrix2x3* const matriy) { - sum->r1c1 = matrix1->r1c1 + matrix2->r1c1; - sum->r1c2 = matrix1->r1c2 + matrix2->r1c2; + sum->r1c1 = matrix->r1c1 + matriy->r1c1; + sum->r1c2 = matrix->r1c2 + matriy->r1c2; - sum->r2c1 = matrix1->r2c1 + matrix2->r2c1; - sum->r2c2 = matrix1->r2c2 + matrix2->r2c2; + sum->r2c1 = matrix->r2c1 + matriy->r2c1; + sum->r2c2 = matrix->r2c2 + matriy->r2c2; - sum->r3c1 = matrix1->r3c1 + matrix2->r3c1; - sum->r3c2 = matrix1->r3c2 + matrix2->r3c2; + sum->r3c1 = matrix->r3c1 + matriy->r3c1; + sum->r3c2 = matrix->r3c2 + matriy->r3c2; } -inline void bgc_fp64_matrix2x3_add(BGC_FP64_Matrix2x3* const sum, const BGC_FP64_Matrix2x3* const matrix1, const BGC_FP64_Matrix2x3* const matrix2) +inline void bgc_fp64_matrix2x3_add(BGC_FP64_Matrix2x3* const sum, const BGC_FP64_Matrix2x3* const matrix, const BGC_FP64_Matrix2x3* const matriy) { - sum->r1c1 = matrix1->r1c1 + matrix2->r1c1; - sum->r1c2 = matrix1->r1c2 + matrix2->r1c2; + sum->r1c1 = matrix->r1c1 + matriy->r1c1; + sum->r1c2 = matrix->r1c2 + matriy->r1c2; - sum->r2c1 = matrix1->r2c1 + matrix2->r2c1; - sum->r2c2 = matrix1->r2c2 + matrix2->r2c2; + sum->r2c1 = matrix->r2c1 + matriy->r2c1; + sum->r2c2 = matrix->r2c2 + matriy->r2c2; - sum->r3c1 = matrix1->r3c1 + matrix2->r3c1; - sum->r3c2 = matrix1->r3c2 + matrix2->r3c2; + sum->r3c1 = matrix->r3c1 + matriy->r3c1; + sum->r3c2 = matrix->r3c2 + matriy->r3c2; } // ================= Add Scaled ================= // @@ -466,31 +466,31 @@ inline void bgc_fp64_matrix2x3_multiply_by_real_number(BGC_FP64_Matrix2x3* const inline void bgc_fp32_matrix2x3_multiply_by_vector2(BGC_FP32_Vector3* const product, const BGC_FP32_Matrix2x3* const matrix, const BGC_FP32_Vector2* vector) { - product->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2; - product->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2; - product->x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2; + product->x = matrix->r1c1 * vector->x + matrix->r1c2 * vector->y; + product->y = matrix->r2c1 * vector->x + matrix->r2c2 * vector->y; + product->z = matrix->r3c1 * vector->x + matrix->r3c2 * vector->y; } inline void bgc_fp64_matrix2x3_multiply_by_vector2(BGC_FP64_Vector3* const product, const BGC_FP64_Matrix2x3* const matrix, const BGC_FP64_Vector2* vector) { - product->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2; - product->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2; - product->x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2; + product->x = matrix->r1c1 * vector->x + matrix->r1c2 * vector->y; + product->y = matrix->r2c1 * vector->x + matrix->r2c2 * vector->y; + product->z = matrix->r3c1 * vector->x + matrix->r3c2 * vector->y; } -// ========== Matrix Product 2x3 at 2x2 ========= // +// ========== Matrix Product 2z at 2y ========= // -inline void bgc_fp32_matrix2x3_multiply_by_matrix2x2(BGC_FP32_Matrix2x3* const product, const BGC_FP32_Matrix2x3* const matrix1, const BGC_FP32_Matrix2x2* const matrix2) +inline void bgc_fp32_matrix2x3_multiply_by_matrix2x2(BGC_FP32_Matrix2x3* const product, const BGC_FP32_Matrix2x3* const matrix, const BGC_FP32_Matrix2x2* const matriy) { - const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; - const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; + const float r1c1 = matrix->r1c1 * matriy->r1c1 + matrix->r1c2 * matriy->r2c1; + const float r1c2 = matrix->r1c1 * matriy->r1c2 + matrix->r1c2 * matriy->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 r2c1 = matrix->r2c1 * matriy->r1c1 + matrix->r2c2 * matriy->r2c1; + const float r2c2 = matrix->r2c1 * matriy->r1c2 + matrix->r2c2 * matriy->r2c2; - const float r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1; - const float r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2; + const float r3c1 = matrix->r3c1 * matriy->r1c1 + matrix->r3c2 * matriy->r2c1; + const float r3c2 = matrix->r3c1 * matriy->r1c2 + matrix->r3c2 * matriy->r2c2; product->r1c1 = r1c1; product->r1c2 = r1c2; @@ -502,16 +502,16 @@ inline void bgc_fp32_matrix2x3_multiply_by_matrix2x2(BGC_FP32_Matrix2x3* const p product->r3c2 = r3c2; } -inline void bgc_fp64_matrix2x3_multiply_by_matrix2x2(BGC_FP64_Matrix2x3* const product, const BGC_FP64_Matrix2x3* const matrix1, const BGC_FP64_Matrix2x2* const matrix2) +inline void bgc_fp64_matrix2x3_multiply_by_matrix2x2(BGC_FP64_Matrix2x3* const product, const BGC_FP64_Matrix2x3* const matrix, const BGC_FP64_Matrix2x2* const matriy) { - const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; - const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; + const double r1c1 = matrix->r1c1 * matriy->r1c1 + matrix->r1c2 * matriy->r2c1; + const double r1c2 = matrix->r1c1 * matriy->r1c2 + matrix->r1c2 * matriy->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 r2c1 = matrix->r2c1 * matriy->r1c1 + matrix->r2c2 * matriy->r2c1; + const double r2c2 = matrix->r2c1 * matriy->r1c2 + matrix->r2c2 * matriy->r2c2; - const double r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1; - const double r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2; + const double r3c1 = matrix->r3c1 * matriy->r1c1 + matrix->r3c2 * matriy->r2c1; + const double r3c2 = matrix->r3c1 * matriy->r1c2 + matrix->r3c2 * matriy->r2c2; product->r1c1 = r1c1; product->r1c2 = r1c2; @@ -523,36 +523,36 @@ inline void bgc_fp64_matrix2x3_multiply_by_matrix2x2(BGC_FP64_Matrix2x3* const p product->r3c2 = r3c2; } -// ========== Matrix Product 2x3 at 3x2 ========= // +// ========== Matrix Product 2z at 3y ========= // -inline void bgc_fp32_matrix2x3_multiply_by_matrix3x2(BGC_FP32_Matrix3x3* const product, const BGC_FP32_Matrix2x3* const matrix1, const BGC_FP32_Matrix3x2* const matrix2) +inline void bgc_fp32_matrix2x3_multiply_by_matrix3x2(BGC_FP32_Matrix3x3* const product, const BGC_FP32_Matrix2x3* const matrix, const BGC_FP32_Matrix3x2* const matriy) { - product->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; - product->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; - product->r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3; + product->r1c1 = matrix->r1c1 * matriy->r1c1 + matrix->r1c2 * matriy->r2c1; + product->r1c2 = matrix->r1c1 * matriy->r1c2 + matrix->r1c2 * matriy->r2c2; + product->r1c3 = matrix->r1c1 * matriy->r1c3 + matrix->r1c2 * matriy->r2c3; - product->r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1; - product->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2; - product->r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3; + product->r2c1 = matrix->r2c1 * matriy->r1c1 + matrix->r2c2 * matriy->r2c1; + product->r2c2 = matrix->r2c1 * matriy->r1c2 + matrix->r2c2 * matriy->r2c2; + product->r2c3 = matrix->r2c1 * matriy->r1c3 + matrix->r2c2 * matriy->r2c3; - product->r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1; - product->r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2; - product->r3c3 = matrix1->r3c1 * matrix2->r1c3 + matrix1->r3c2 * matrix2->r2c3; + product->r3c1 = matrix->r3c1 * matriy->r1c1 + matrix->r3c2 * matriy->r2c1; + product->r3c2 = matrix->r3c1 * matriy->r1c2 + matrix->r3c2 * matriy->r2c2; + product->r3c3 = matrix->r3c1 * matriy->r1c3 + matrix->r3c2 * matriy->r2c3; } -inline void bgc_fp64_matrix2x3_multiply_by_matrix3x2(BGC_FP64_Matrix3x3* const product, const BGC_FP64_Matrix2x3* const matrix1, const BGC_FP64_Matrix3x2* const matrix2) +inline void bgc_fp64_matrix2x3_multiply_by_matrix3x2(BGC_FP64_Matrix3x3* const product, const BGC_FP64_Matrix2x3* const matrix, const BGC_FP64_Matrix3x2* const matriy) { - product->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; - product->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; - product->r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3; + product->r1c1 = matrix->r1c1 * matriy->r1c1 + matrix->r1c2 * matriy->r2c1; + product->r1c2 = matrix->r1c1 * matriy->r1c2 + matrix->r1c2 * matriy->r2c2; + product->r1c3 = matrix->r1c1 * matriy->r1c3 + matrix->r1c2 * matriy->r2c3; - product->r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1; - product->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2; - product->r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3; + product->r2c1 = matrix->r2c1 * matriy->r1c1 + matrix->r2c2 * matriy->r2c1; + product->r2c2 = matrix->r2c1 * matriy->r1c2 + matrix->r2c2 * matriy->r2c2; + product->r2c3 = matrix->r2c1 * matriy->r1c3 + matrix->r2c2 * matriy->r2c3; - product->r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1; - product->r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2; - product->r3c3 = matrix1->r3c1 * matrix2->r1c3 + matrix1->r3c2 * matrix2->r2c3; + product->r3c1 = matrix->r3c1 * matriy->r1c1 + matrix->r3c2 * matriy->r2c1; + product->r3c2 = matrix->r3c1 * matriy->r1c2 + matrix->r3c2 * matriy->r2c2; + product->r3c3 = matrix->r3c1 * matriy->r1c3 + matrix->r3c2 * matriy->r2c3; } // =================== Divide =================== // diff --git a/basic-geometry/matrix3x2.c b/basic-geometry/matrix3x2.c index ef0593b..b0544d6 100644 --- a/basic-geometry/matrix3x2.c +++ b/basic-geometry/matrix3x2.c @@ -6,8 +6,8 @@ extern inline void bgc_fp64_matrix3x2_reset(BGC_FP64_Matrix3x2* const matrix); extern inline void bgc_fp32_matrix3x2_copy(BGC_FP32_Matrix3x2* const destination, const BGC_FP32_Matrix3x2* const source); extern inline void bgc_fp64_matrix3x2_copy(BGC_FP64_Matrix3x2* const destination, const BGC_FP64_Matrix3x2* const source); -extern inline void bgc_fp32_matrix3x2_swap(BGC_FP32_Matrix3x2* const matrix1, BGC_FP32_Matrix3x2* const matrix2); -extern inline void bgc_fp64_matrix3x2_swap(BGC_FP64_Matrix3x2* const matrix1, BGC_FP64_Matrix3x2* const matrix2); +extern inline void bgc_fp32_matrix3x2_swap(BGC_FP32_Matrix3x2* const matrix, BGC_FP32_Matrix3x2* const matriy); +extern inline void bgc_fp64_matrix3x2_swap(BGC_FP64_Matrix3x2* const matrix, BGC_FP64_Matrix3x2* const matriy); extern inline void bgc_fp32_matrix3x2_convert_to_fp64(BGC_FP64_Matrix3x2* const destination, const BGC_FP32_Matrix3x2* const source); extern inline void bgc_fp64_matrix3x2_convert_to_fp32(BGC_FP32_Matrix3x2* const destination, const BGC_FP64_Matrix3x2* const source); @@ -27,8 +27,8 @@ extern inline void bgc_fp64_matrix3x2_get_column(BGC_FP64_Vector2* const column, extern inline void bgc_fp32_matrix3x2_set_column(BGC_FP32_Matrix3x2* const matrix, const int column_number, const BGC_FP32_Vector2* const column); extern inline void bgc_fp64_matrix3x2_set_column(BGC_FP64_Matrix3x2* const matrix, const int column_number, const BGC_FP64_Vector2* const column); -extern inline void bgc_fp32_matrix3x2_add(BGC_FP32_Matrix3x2* const sum, const BGC_FP32_Matrix3x2* const matrix1, const BGC_FP32_Matrix3x2* const matrix2); -extern inline void bgc_fp64_matrix3x2_add(BGC_FP64_Matrix3x2* const sum, const BGC_FP64_Matrix3x2* const matrix1, const BGC_FP64_Matrix3x2* const matrix2); +extern inline void bgc_fp32_matrix3x2_add(BGC_FP32_Matrix3x2* const sum, const BGC_FP32_Matrix3x2* const matrix, const BGC_FP32_Matrix3x2* const matriy); +extern inline void bgc_fp64_matrix3x2_add(BGC_FP64_Matrix3x2* const sum, const BGC_FP64_Matrix3x2* const matrix, const BGC_FP64_Matrix3x2* const matriy); extern inline void bgc_fp32_matrix3x2_add_scaled(BGC_FP32_Matrix3x2* const sum, const BGC_FP32_Matrix3x2* const basic_matrix, const BGC_FP32_Matrix3x2* const scalable_matrix, const float scale); extern inline void bgc_fp64_matrix3x2_add_scaled(BGC_FP64_Matrix3x2* const sum, const BGC_FP64_Matrix3x2* const basic_matrix, const BGC_FP64_Matrix3x2* const scalable_matrix, const double scale); @@ -45,11 +45,11 @@ extern inline void bgc_fp64_matrix3x2_multiply_by_real_number(BGC_FP64_Matrix3x2 extern inline void bgc_fp32_matrix3x2_multiply_by_vector3(BGC_FP32_Vector2* const product, const BGC_FP32_Matrix3x2* const matrix, const BGC_FP32_Vector3* const vector); extern inline void bgc_fp64_matrix3x2_multiply_by_vector3(BGC_FP64_Vector2* const product, const BGC_FP64_Matrix3x2* const matrix, const BGC_FP64_Vector3* const vector); -extern inline void bgc_fp32_matrix3x2_multiply_by_matrix2x3(BGC_FP32_Matrix2x2* const product, const BGC_FP32_Matrix3x2* const matrix1, const BGC_FP32_Matrix2x3* const matrix2); -extern inline void bgc_fp64_matrix3x2_multiply_by_matrix2x3(BGC_FP64_Matrix2x2* const product, const BGC_FP64_Matrix3x2* const matrix1, const BGC_FP64_Matrix2x3* const matrix2); +extern inline void bgc_fp32_matrix3x2_multiply_by_matrix2x3(BGC_FP32_Matrix2x2* const product, const BGC_FP32_Matrix3x2* const matrix, const BGC_FP32_Matrix2x3* const matriy); +extern inline void bgc_fp64_matrix3x2_multiply_by_matrix2x3(BGC_FP64_Matrix2x2* const product, const BGC_FP64_Matrix3x2* const matrix, const BGC_FP64_Matrix2x3* const matriy); -extern inline void bgc_fp32_matrix3x2_multiply_by_matrix3x3(BGC_FP32_Matrix3x2* const product, const BGC_FP32_Matrix3x2* const matrix1, const BGC_FP32_Matrix3x3* const matrix2); -extern inline void bgc_fp64_matrix3x2_multiply_by_matrix3x3(BGC_FP64_Matrix3x2* const product, const BGC_FP64_Matrix3x2* const matrix1, const BGC_FP64_Matrix3x3* const matrix2); +extern inline void bgc_fp32_matrix3x2_multiply_by_matrix3x3(BGC_FP32_Matrix3x2* const product, const BGC_FP32_Matrix3x2* const matrix, const BGC_FP32_Matrix3x3* const matriy); +extern inline void bgc_fp64_matrix3x2_multiply_by_matrix3x3(BGC_FP64_Matrix3x2* const product, const BGC_FP64_Matrix3x2* const matrix, const BGC_FP64_Matrix3x3* const matriy); extern inline int bgc_fp32_matrix3x2_divide_by_real_number(BGC_FP32_Matrix3x2* const quotient, const BGC_FP32_Matrix3x2* const dividend, const float divisor); extern inline int bgc_fp64_matrix3x2_divide_by_real_number(BGC_FP64_Matrix3x2* const quotient, const BGC_FP64_Matrix3x2* const dividend, const double divisor); diff --git a/basic-geometry/matrix3x2.h b/basic-geometry/matrix3x2.h index 0ef034c..36e9ce5 100644 --- a/basic-geometry/matrix3x2.h +++ b/basic-geometry/matrix3x2.h @@ -56,58 +56,58 @@ inline void bgc_fp64_matrix3x2_copy(BGC_FP64_Matrix3x2* const destination, const // ==================== Swap ==================== // -inline void bgc_fp32_matrix3x2_swap(BGC_FP32_Matrix3x2* const matrix1, BGC_FP32_Matrix3x2* const matrix2) +inline void bgc_fp32_matrix3x2_swap(BGC_FP32_Matrix3x2* const matrix, BGC_FP32_Matrix3x2* const matriy) { - const float r1c1 = matrix2->r1c1; - const float r1c2 = matrix2->r1c2; - const float r1c3 = matrix2->r1c3; + const float r1c1 = matriy->r1c1; + const float r1c2 = matriy->r1c2; + const float r1c3 = matriy->r1c3; - const float r2c1 = matrix2->r2c1; - const float r2c2 = matrix2->r2c2; - const float r2c3 = matrix2->r2c3; + const float r2c1 = matriy->r2c1; + const float r2c2 = matriy->r2c2; + const float r2c3 = matriy->r2c3; - matrix2->r1c1 = matrix1->r1c1; - matrix2->r1c2 = matrix1->r1c2; - matrix2->r1c3 = matrix1->r1c3; + matriy->r1c1 = matrix->r1c1; + matriy->r1c2 = matrix->r1c2; + matriy->r1c3 = matrix->r1c3; - matrix2->r2c1 = matrix1->r2c1; - matrix2->r2c2 = matrix1->r2c2; - matrix2->r2c3 = matrix1->r2c3; + matriy->r2c1 = matrix->r2c1; + matriy->r2c2 = matrix->r2c2; + matriy->r2c3 = matrix->r2c3; - matrix1->r1c1 = r1c1; - matrix1->r1c2 = r1c2; - matrix1->r1c3 = r1c3; + matrix->r1c1 = r1c1; + matrix->r1c2 = r1c2; + matrix->r1c3 = r1c3; - matrix1->r2c1 = r2c1; - matrix1->r2c2 = r2c2; - matrix1->r2c3 = r2c3; + matrix->r2c1 = r2c1; + matrix->r2c2 = r2c2; + matrix->r2c3 = r2c3; } -inline void bgc_fp64_matrix3x2_swap(BGC_FP64_Matrix3x2* const matrix1, BGC_FP64_Matrix3x2* const matrix2) +inline void bgc_fp64_matrix3x2_swap(BGC_FP64_Matrix3x2* const matrix, BGC_FP64_Matrix3x2* const matriy) { - const double r1c1 = matrix2->r1c1; - const double r1c2 = matrix2->r1c2; - const double r1c3 = matrix2->r1c3; + const double r1c1 = matriy->r1c1; + const double r1c2 = matriy->r1c2; + const double r1c3 = matriy->r1c3; - const double r2c1 = matrix2->r2c1; - const double r2c2 = matrix2->r2c2; - const double r2c3 = matrix2->r2c3; + const double r2c1 = matriy->r2c1; + const double r2c2 = matriy->r2c2; + const double r2c3 = matriy->r2c3; - matrix2->r1c1 = matrix1->r1c1; - matrix2->r1c2 = matrix1->r1c2; - matrix2->r1c3 = matrix1->r1c3; + matriy->r1c1 = matrix->r1c1; + matriy->r1c2 = matrix->r1c2; + matriy->r1c3 = matrix->r1c3; - matrix2->r2c1 = matrix1->r2c1; - matrix2->r2c2 = matrix1->r2c2; - matrix2->r2c3 = matrix1->r2c3; + matriy->r2c1 = matrix->r2c1; + matriy->r2c2 = matrix->r2c2; + matriy->r2c3 = matrix->r2c3; - matrix1->r1c1 = r1c1; - matrix1->r1c2 = r1c2; - matrix1->r1c3 = r1c3; + matrix->r1c1 = r1c1; + matrix->r1c2 = r1c2; + matrix->r1c3 = r1c3; - matrix1->r2c1 = r2c1; - matrix1->r2c2 = r2c2; - matrix1->r2c3 = r2c3; + matrix->r2c1 = r2c1; + matrix->r2c2 = r2c2; + matrix->r2c3 = r2c3; } // ================== Convert =================== // @@ -164,46 +164,46 @@ inline void bgc_fp32_matrix3x2_get_row(BGC_FP32_Vector3* const row, const BGC_FP { if (row_number == 1) { - row->x1 = matrix->r1c1; - row->x2 = matrix->r1c2; - row->x3 = matrix->r1c3; + row->x = matrix->r1c1; + row->y = matrix->r1c2; + row->z = matrix->r1c3; return; } if (row_number == 2) { - row->x1 = matrix->r2c1; - row->x2 = matrix->r2c2; - row->x3 = matrix->r2c3; + row->x = matrix->r2c1; + row->y = matrix->r2c2; + row->z = matrix->r2c3; return; } - row->x1 = 0.0f; - row->x2 = 0.0f; - row->x3 = 0.0f; + row->x = 0.0f; + row->y = 0.0f; + row->z = 0.0f; } inline void bgc_fp64_matrix3x2_get_row(BGC_FP64_Vector3* const row, const BGC_FP64_Matrix3x2* const matrix, const int row_number) { if (row_number == 1) { - row->x1 = matrix->r1c1; - row->x2 = matrix->r1c2; - row->x3 = matrix->r1c3; + row->x = matrix->r1c1; + row->y = matrix->r1c2; + row->z = matrix->r1c3; return; } if (row_number == 2) { - row->x1 = matrix->r2c1; - row->x2 = matrix->r2c2; - row->x3 = matrix->r2c3; + row->x = matrix->r2c1; + row->y = matrix->r2c2; + row->z = matrix->r2c3; return; } - row->x1 = 0.0f; - row->x2 = 0.0f; - row->x3 = 0.0f; + row->x = 0.0f; + row->y = 0.0f; + row->z = 0.0f; } // ================== Set Row =================== // @@ -212,17 +212,17 @@ inline void bgc_fp32_matrix3x2_set_row(BGC_FP32_Matrix3x2* const matrix, const i { if (row_number == 1) { - matrix->r1c1 = row->x1; - matrix->r1c2 = row->x2; - matrix->r1c3 = row->x3; + matrix->r1c1 = row->x; + matrix->r1c2 = row->y; + matrix->r1c3 = row->z; return; } if (row_number == 2) { - matrix->r2c1 = row->x1; - matrix->r2c2 = row->x2; - matrix->r2c3 = row->x3; + matrix->r2c1 = row->x; + matrix->r2c2 = row->y; + matrix->r2c3 = row->z; } } @@ -230,17 +230,17 @@ inline void bgc_fp64_matrix3x2_set_row(BGC_FP64_Matrix3x2* const matrix, const i { if (row_number == 1) { - matrix->r1c1 = row->x1; - matrix->r1c2 = row->x2; - matrix->r1c3 = row->x3; + matrix->r1c1 = row->x; + matrix->r1c2 = row->y; + matrix->r1c3 = row->z; return; } if (row_number == 2) { - matrix->r2c1 = row->x1; - matrix->r2c2 = row->x2; - matrix->r2c3 = row->x3; + matrix->r2c1 = row->x; + matrix->r2c2 = row->y; + matrix->r2c3 = row->z; } } @@ -250,54 +250,54 @@ inline void bgc_fp32_matrix3x2_get_column(BGC_FP32_Vector2* const column, const { if (column_number == 1) { - column->x1 = matrix->r1c1; - column->x2 = matrix->r2c1; + column->x = matrix->r1c1; + column->y = matrix->r2c1; return; } if (column_number == 2) { - column->x1 = matrix->r1c2; - column->x2 = matrix->r2c2; + column->x = matrix->r1c2; + column->y = matrix->r2c2; return; } if (column_number == 3) { - column->x1 = matrix->r1c3; - column->x2 = matrix->r2c3; + column->x = matrix->r1c3; + column->y = matrix->r2c3; return; } - column->x1 = 0.0f; - column->x2 = 0.0f; + column->x = 0.0f; + column->y = 0.0f; } inline void bgc_fp64_matrix3x2_get_column(BGC_FP64_Vector2* const column, const BGC_FP64_Matrix3x2* const matrix, const int column_number) { if (column_number == 1) { - column->x1 = matrix->r1c1; - column->x2 = matrix->r2c1; + column->x = matrix->r1c1; + column->y = matrix->r2c1; return; } if (column_number == 2) { - column->x1 = matrix->r1c2; - column->x2 = matrix->r2c2; + column->x = matrix->r1c2; + column->y = matrix->r2c2; return; } if (column_number == 3) { - column->x1 = matrix->r1c3; - column->x2 = matrix->r2c3; + column->x = matrix->r1c3; + column->y = matrix->r2c3; return; } - column->x1 = 0.0; - column->x2 = 0.0; + column->x = 0.0; + column->y = 0.0; } // ================= Set Column ================= // @@ -306,22 +306,22 @@ inline void bgc_fp32_matrix3x2_set_column(BGC_FP32_Matrix3x2* const matrix, cons { if (column_number == 1) { - matrix->r1c1 = column->x1; - matrix->r2c1 = column->x2; + matrix->r1c1 = column->x; + matrix->r2c1 = column->y; return; } if (column_number == 2) { - matrix->r1c2 = column->x1; - matrix->r2c2 = column->x2; + matrix->r1c2 = column->x; + matrix->r2c2 = column->y; return; } if (column_number == 3) { - matrix->r1c3 = column->x1; - matrix->r2c3 = column->x2; + matrix->r1c3 = column->x; + matrix->r2c3 = column->y; } } @@ -329,47 +329,47 @@ inline void bgc_fp64_matrix3x2_set_column(BGC_FP64_Matrix3x2* const matrix, cons { if (column_number == 1) { - matrix->r1c1 = column->x1; - matrix->r2c1 = column->x2; + matrix->r1c1 = column->x; + matrix->r2c1 = column->y; return; } if (column_number == 2) { - matrix->r1c2 = column->x1; - matrix->r2c2 = column->x2; + matrix->r1c2 = column->x; + matrix->r2c2 = column->y; return; } if (column_number == 3) { - matrix->r1c3 = column->x1; - matrix->r2c3 = column->x2; + matrix->r1c3 = column->x; + matrix->r2c3 = column->y; } } // ==================== Add ===================== // -inline void bgc_fp32_matrix3x2_add(BGC_FP32_Matrix3x2* const sum, const BGC_FP32_Matrix3x2* const matrix1, const BGC_FP32_Matrix3x2* const matrix2) +inline void bgc_fp32_matrix3x2_add(BGC_FP32_Matrix3x2* const sum, const BGC_FP32_Matrix3x2* const matrix, const BGC_FP32_Matrix3x2* const matriy) { - sum->r1c1 = matrix1->r1c1 + matrix2->r1c1; - sum->r1c2 = matrix1->r1c2 + matrix2->r1c2; - sum->r1c3 = matrix1->r1c3 + matrix2->r1c3; + sum->r1c1 = matrix->r1c1 + matriy->r1c1; + sum->r1c2 = matrix->r1c2 + matriy->r1c2; + sum->r1c3 = matrix->r1c3 + matriy->r1c3; - sum->r2c1 = matrix1->r2c1 + matrix2->r2c1; - sum->r2c2 = matrix1->r2c2 + matrix2->r2c2; - sum->r2c3 = matrix1->r2c3 + matrix2->r2c3; + sum->r2c1 = matrix->r2c1 + matriy->r2c1; + sum->r2c2 = matrix->r2c2 + matriy->r2c2; + sum->r2c3 = matrix->r2c3 + matriy->r2c3; } -inline void bgc_fp64_matrix3x2_add(BGC_FP64_Matrix3x2* const sum, const BGC_FP64_Matrix3x2* const matrix1, const BGC_FP64_Matrix3x2* const matrix2) +inline void bgc_fp64_matrix3x2_add(BGC_FP64_Matrix3x2* const sum, const BGC_FP64_Matrix3x2* const matrix, const BGC_FP64_Matrix3x2* const matriy) { - sum->r1c1 = matrix1->r1c1 + matrix2->r1c1; - sum->r1c2 = matrix1->r1c2 + matrix2->r1c2; - sum->r1c3 = matrix1->r1c3 + matrix2->r1c3; + sum->r1c1 = matrix->r1c1 + matriy->r1c1; + sum->r1c2 = matrix->r1c2 + matriy->r1c2; + sum->r1c3 = matrix->r1c3 + matriy->r1c3; - sum->r2c1 = matrix1->r2c1 + matrix2->r2c1; - sum->r2c2 = matrix1->r2c2 + matrix2->r2c2; - sum->r2c3 = matrix1->r2c3 + matrix2->r2c3; + sum->r2c1 = matrix->r2c1 + matriy->r2c1; + sum->r2c2 = matrix->r2c2 + matriy->r2c2; + sum->r2c3 = matrix->r2c3 + matriy->r2c3; } // ================= Add Scaled ================= // @@ -472,47 +472,47 @@ inline void bgc_fp64_matrix3x2_multiply_by_real_number(BGC_FP64_Matrix3x2* const inline void bgc_fp32_matrix3x2_multiply_by_vector3(BGC_FP32_Vector2* const product, const BGC_FP32_Matrix3x2* const matrix, const BGC_FP32_Vector3* const vector) { - product->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3; - product->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3; + product->x = matrix->r1c1 * vector->x + matrix->r1c2 * vector->y + matrix->r1c3 * vector->z; + product->y = matrix->r2c1 * vector->x + matrix->r2c2 * vector->y + matrix->r2c3 * vector->z; } inline void bgc_fp64_matrix3x2_multiply_by_vector3(BGC_FP64_Vector2* const product, const BGC_FP64_Matrix3x2* const matrix, const BGC_FP64_Vector3* const vector) { - product->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3; - product->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3; + product->x = matrix->r1c1 * vector->x + matrix->r1c2 * vector->y + matrix->r1c3 * vector->z; + product->y = matrix->r2c1 * vector->x + matrix->r2c2 * vector->y + matrix->r2c3 * vector->z; } -// ========== Matrix Product 3x2 at 2x3 ========= // +// ========== Matrix Product 3y at 2z ========= // -inline void bgc_fp32_matrix3x2_multiply_by_matrix2x3(BGC_FP32_Matrix2x2* const product, const BGC_FP32_Matrix3x2* const matrix1, const BGC_FP32_Matrix2x3* const matrix2) +inline void bgc_fp32_matrix3x2_multiply_by_matrix2x3(BGC_FP32_Matrix2x2* const product, const BGC_FP32_Matrix3x2* const matrix, const BGC_FP32_Matrix2x3* const matriy) { - product->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1; - product->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2; + product->r1c1 = matrix->r1c1 * matriy->r1c1 + matrix->r1c2 * matriy->r2c1 + matrix->r1c3 * matriy->r3c1; + product->r1c2 = matrix->r1c1 * matriy->r1c2 + matrix->r1c2 * matriy->r2c2 + matrix->r1c3 * matriy->r3c2; - product->r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1; - product->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2; + product->r2c1 = matrix->r2c1 * matriy->r1c1 + matrix->r2c2 * matriy->r2c1 + matrix->r2c3 * matriy->r3c1; + product->r2c2 = matrix->r2c1 * matriy->r1c2 + matrix->r2c2 * matriy->r2c2 + matrix->r2c3 * matriy->r3c2; } -inline void bgc_fp64_matrix3x2_multiply_by_matrix2x3(BGC_FP64_Matrix2x2* const product, const BGC_FP64_Matrix3x2* const matrix1, const BGC_FP64_Matrix2x3* const matrix2) +inline void bgc_fp64_matrix3x2_multiply_by_matrix2x3(BGC_FP64_Matrix2x2* const product, const BGC_FP64_Matrix3x2* const matrix, const BGC_FP64_Matrix2x3* const matriy) { - product->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1; - product->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2; + product->r1c1 = matrix->r1c1 * matriy->r1c1 + matrix->r1c2 * matriy->r2c1 + matrix->r1c3 * matriy->r3c1; + product->r1c2 = matrix->r1c1 * matriy->r1c2 + matrix->r1c2 * matriy->r2c2 + matrix->r1c3 * matriy->r3c2; - product->r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1; - product->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2; + product->r2c1 = matrix->r2c1 * matriy->r1c1 + matrix->r2c2 * matriy->r2c1 + matrix->r2c3 * matriy->r3c1; + product->r2c2 = matrix->r2c1 * matriy->r1c2 + matrix->r2c2 * matriy->r2c2 + matrix->r2c3 * matriy->r3c2; } -// ========== Matrix Product 3x2 at 3x2 ========= // +// ========== Matrix Product 3y at 3y ========= // -inline void bgc_fp32_matrix3x2_multiply_by_matrix3x3(BGC_FP32_Matrix3x2* const product, const BGC_FP32_Matrix3x2* const matrix1, const BGC_FP32_Matrix3x3* const matrix2) +inline void bgc_fp32_matrix3x2_multiply_by_matrix3x3(BGC_FP32_Matrix3x2* const product, const BGC_FP32_Matrix3x2* const matrix, const BGC_FP32_Matrix3x3* const matriy) { - 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 r1c1 = matrix->r1c1 * matriy->r1c1 + matrix->r1c2 * matriy->r2c1 + matrix->r1c3 * matriy->r3c1; + const float r1c2 = matrix->r1c1 * matriy->r1c2 + matrix->r1c2 * matriy->r2c2 + matrix->r1c3 * matriy->r3c2; + const float r1c3 = matrix->r1c1 * matriy->r1c3 + matrix->r1c2 * matriy->r2c3 + matrix->r1c3 * matriy->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 r2c1 = matrix->r2c1 * matriy->r1c1 + matrix->r2c2 * matriy->r2c1 + matrix->r2c3 * matriy->r3c1; + const float r2c2 = matrix->r2c1 * matriy->r1c2 + matrix->r2c2 * matriy->r2c2 + matrix->r2c3 * matriy->r3c2; + const float r2c3 = matrix->r2c1 * matriy->r1c3 + matrix->r2c2 * matriy->r2c3 + matrix->r2c3 * matriy->r3c3; product->r1c1 = r1c1; product->r1c2 = r1c2; @@ -523,15 +523,15 @@ inline void bgc_fp32_matrix3x2_multiply_by_matrix3x3(BGC_FP32_Matrix3x2* const p product->r2c3 = r2c3; } -inline void bgc_fp64_matrix3x2_multiply_by_matrix3x3(BGC_FP64_Matrix3x2* const product, const BGC_FP64_Matrix3x2* const matrix1, const BGC_FP64_Matrix3x3* const matrix2) +inline void bgc_fp64_matrix3x2_multiply_by_matrix3x3(BGC_FP64_Matrix3x2* const product, const BGC_FP64_Matrix3x2* const matrix, const BGC_FP64_Matrix3x3* const matriy) { - 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 r1c1 = matrix->r1c1 * matriy->r1c1 + matrix->r1c2 * matriy->r2c1 + matrix->r1c3 * matriy->r3c1; + const double r1c2 = matrix->r1c1 * matriy->r1c2 + matrix->r1c2 * matriy->r2c2 + matrix->r1c3 * matriy->r3c2; + const double r1c3 = matrix->r1c1 * matriy->r1c3 + matrix->r1c2 * matriy->r2c3 + matrix->r1c3 * matriy->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 r2c1 = matrix->r2c1 * matriy->r1c1 + matrix->r2c2 * matriy->r2c1 + matrix->r2c3 * matriy->r3c1; + const double r2c2 = matrix->r2c1 * matriy->r1c2 + matrix->r2c2 * matriy->r2c2 + matrix->r2c3 * matriy->r3c2; + const double r2c3 = matrix->r2c1 * matriy->r1c3 + matrix->r2c2 * matriy->r2c3 + matrix->r2c3 * matriy->r3c3; product->r1c1 = r1c1; product->r1c2 = r1c2; diff --git a/basic-geometry/matrix3x3.c b/basic-geometry/matrix3x3.c index 6d81e17..eb7146e 100644 --- a/basic-geometry/matrix3x3.c +++ b/basic-geometry/matrix3x3.c @@ -12,8 +12,8 @@ extern inline void bgc_fp64_matrix3x3_make_diagonal(BGC_FP64_Matrix3x3* const ma extern inline void bgc_fp32_matrix3x3_copy(BGC_FP32_Matrix3x3* const destination, const BGC_FP32_Matrix3x3* const source); extern inline void bgc_fp64_matrix3x3_copy(BGC_FP64_Matrix3x3* const destination, const BGC_FP64_Matrix3x3* const source); -extern inline void bgc_fp32_matrix3x3_swap(BGC_FP32_Matrix3x3* const matrix1, BGC_FP32_Matrix3x3* const matrix2); -extern inline void bgc_fp64_matrix3x3_swap(BGC_FP64_Matrix3x3* const matrix1, BGC_FP64_Matrix3x3* const matrix2); +extern inline void bgc_fp32_matrix3x3_swap(BGC_FP32_Matrix3x3* const matrix, BGC_FP32_Matrix3x3* const matriy); +extern inline void bgc_fp64_matrix3x3_swap(BGC_FP64_Matrix3x3* const matrix, BGC_FP64_Matrix3x3* const matriy); extern inline void bgc_fp64_matrix3x3_convert_to_fp32(BGC_FP32_Matrix3x3* const destination, const BGC_FP64_Matrix3x3* const source); extern inline void bgc_fp32_matrix3x3_convert_to_fp64(BGC_FP64_Matrix3x3* const destination, const BGC_FP32_Matrix3x3* const source); @@ -51,8 +51,8 @@ extern inline void bgc_fp64_matrix3x3_get_column(BGC_FP64_Vector3* const column, extern inline void bgc_fp32_matrix3x3_set_column(BGC_FP32_Matrix3x3* const matrix, const int column_number, const BGC_FP32_Vector3* const column); extern inline void bgc_fp64_matrix3x3_set_column(BGC_FP64_Matrix3x3* const matrix, const int column_number, const BGC_FP64_Vector3* const column); -extern inline void bgc_fp32_matrix3x3_add(BGC_FP32_Matrix3x3* const sum, const BGC_FP32_Matrix3x3* const matrix1, const BGC_FP32_Matrix3x3* const matrix2); -extern inline void bgc_fp64_matrix3x3_add(BGC_FP64_Matrix3x3* const sum, const BGC_FP64_Matrix3x3* const matrix1, const BGC_FP64_Matrix3x3* const matrix2); +extern inline void bgc_fp32_matrix3x3_add(BGC_FP32_Matrix3x3* const sum, const BGC_FP32_Matrix3x3* const matrix, const BGC_FP32_Matrix3x3* const matriy); +extern inline void bgc_fp64_matrix3x3_add(BGC_FP64_Matrix3x3* const sum, const BGC_FP64_Matrix3x3* const matrix, const BGC_FP64_Matrix3x3* const matriy); extern inline void bgc_fp32_matrix3x3_add_scaled(BGC_FP32_Matrix3x3* const sum, const BGC_FP32_Matrix3x3* const basic_matrix, const BGC_FP32_Matrix3x3* const scalable_matrix, const float scale); extern inline void bgc_fp64_matrix3x3_add_scaled(BGC_FP64_Matrix3x3* const sum, const BGC_FP64_Matrix3x3* const basic_matrix, const BGC_FP64_Matrix3x3* const scalable_matrix, const double scale); @@ -78,11 +78,11 @@ extern inline void _bgc_fp64_restrict_matrix3x3_multiply_by_vector3(BGC_FP64_Vec extern inline void _bgc_fp32_restrict_matrix3x3_multiply_by_dual_vector3(BGC_FP32_DualVector3* restrict const product, const BGC_FP32_Matrix3x3* const matrix, const BGC_FP32_DualVector3* const vector); extern inline void _bgc_fp64_restrict_matrix3x3_multiply_by_dual_vector3(BGC_FP64_DualVector3* restrict const product, const BGC_FP64_Matrix3x3* const matrix, const BGC_FP64_DualVector3* const vector); -extern inline void bgc_fp32_matrix3x3_multiply_by_matrix2x3(BGC_FP32_Matrix2x3* const product, const BGC_FP32_Matrix3x3* const matrix1, const BGC_FP32_Matrix2x3* const matrix2); -extern inline void bgc_fp64_matrix3x3_multiply_by_matrix2x3(BGC_FP64_Matrix2x3* const product, const BGC_FP64_Matrix3x3* const matrix1, const BGC_FP64_Matrix2x3* const matrix2); +extern inline void bgc_fp32_matrix3x3_multiply_by_matrix2x3(BGC_FP32_Matrix2x3* const product, const BGC_FP32_Matrix3x3* const matrix, const BGC_FP32_Matrix2x3* const matriy); +extern inline void bgc_fp64_matrix3x3_multiply_by_matrix2x3(BGC_FP64_Matrix2x3* const product, const BGC_FP64_Matrix3x3* const matrix, const BGC_FP64_Matrix2x3* const matriy); -extern inline void bgc_fp32_matrix3x3_multiply_by_matrix3x3(BGC_FP32_Matrix3x3* const product, const BGC_FP32_Matrix3x3* const matrix1, const BGC_FP32_Matrix3x3* const matrix2); -extern inline void bgc_fp64_matrix3x3_multiply_by_matrix3x3(BGC_FP64_Matrix3x3* const product, const BGC_FP64_Matrix3x3* const matrix1, const BGC_FP64_Matrix3x3* const matrix2); +extern inline void bgc_fp32_matrix3x3_multiply_by_matrix3x3(BGC_FP32_Matrix3x3* const product, const BGC_FP32_Matrix3x3* const matrix, const BGC_FP32_Matrix3x3* const matriy); +extern inline void bgc_fp64_matrix3x3_multiply_by_matrix3x3(BGC_FP64_Matrix3x3* const product, const BGC_FP64_Matrix3x3* const matrix, const BGC_FP64_Matrix3x3* const matriy); extern inline int bgc_fp32_matrix3x3_divide_by_real_number(BGC_FP32_Matrix3x3* const quotient, const BGC_FP32_Matrix3x3* const dividend, const float divisor); extern inline int bgc_fp64_matrix3x3_divide_by_real_number(BGC_FP64_Matrix3x3* const quotient, const BGC_FP64_Matrix3x3* const dividend, const double divisor); diff --git a/basic-geometry/matrix3x3.h b/basic-geometry/matrix3x3.h index d4d481b..f157e9c 100644 --- a/basic-geometry/matrix3x3.h +++ b/basic-geometry/matrix3x3.h @@ -136,82 +136,82 @@ inline void bgc_fp64_matrix3x3_copy(BGC_FP64_Matrix3x3* const destination, const // ==================== Swap ==================== // -inline void bgc_fp32_matrix3x3_swap(BGC_FP32_Matrix3x3* const matrix1, BGC_FP32_Matrix3x3* const matrix2) +inline void bgc_fp32_matrix3x3_swap(BGC_FP32_Matrix3x3* const matrix, BGC_FP32_Matrix3x3* const matriy) { - const float r1c1 = matrix2->r1c1; - const float r1c2 = matrix2->r1c2; - const float r1c3 = matrix2->r1c3; + const float r1c1 = matriy->r1c1; + const float r1c2 = matriy->r1c2; + const float r1c3 = matriy->r1c3; - const float r2c1 = matrix2->r2c1; - const float r2c2 = matrix2->r2c2; - const float r2c3 = matrix2->r2c3; + const float r2c1 = matriy->r2c1; + const float r2c2 = matriy->r2c2; + const float r2c3 = matriy->r2c3; - const float r3c1 = matrix2->r3c1; - const float r3c2 = matrix2->r3c2; - const float r3c3 = matrix2->r3c3; + const float r3c1 = matriy->r3c1; + const float r3c2 = matriy->r3c2; + const float r3c3 = matriy->r3c3; - matrix2->r1c1 = matrix1->r1c1; - matrix2->r1c2 = matrix1->r1c2; - matrix2->r1c3 = matrix1->r1c3; + matriy->r1c1 = matrix->r1c1; + matriy->r1c2 = matrix->r1c2; + matriy->r1c3 = matrix->r1c3; - matrix2->r2c1 = matrix1->r2c1; - matrix2->r2c2 = matrix1->r2c2; - matrix2->r2c3 = matrix1->r2c3; + matriy->r2c1 = matrix->r2c1; + matriy->r2c2 = matrix->r2c2; + matriy->r2c3 = matrix->r2c3; - matrix2->r3c1 = matrix1->r3c1; - matrix2->r3c2 = matrix1->r3c2; - matrix2->r3c3 = matrix1->r3c3; + matriy->r3c1 = matrix->r3c1; + matriy->r3c2 = matrix->r3c2; + matriy->r3c3 = matrix->r3c3; - matrix1->r1c1 = r1c1; - matrix1->r1c2 = r1c2; - matrix1->r1c3 = r1c3; + matrix->r1c1 = r1c1; + matrix->r1c2 = r1c2; + matrix->r1c3 = r1c3; - matrix1->r2c1 = r2c1; - matrix1->r2c2 = r2c2; - matrix1->r2c3 = r2c3; + matrix->r2c1 = r2c1; + matrix->r2c2 = r2c2; + matrix->r2c3 = r2c3; - matrix1->r3c1 = r3c1; - matrix1->r3c2 = r3c2; - matrix1->r3c3 = r3c3; + matrix->r3c1 = r3c1; + matrix->r3c2 = r3c2; + matrix->r3c3 = r3c3; } -inline void bgc_fp64_matrix3x3_swap(BGC_FP64_Matrix3x3* const matrix1, BGC_FP64_Matrix3x3* const matrix2) +inline void bgc_fp64_matrix3x3_swap(BGC_FP64_Matrix3x3* const matrix, BGC_FP64_Matrix3x3* const matriy) { - const double r1c1 = matrix2->r1c1; - const double r1c2 = matrix2->r1c2; - const double r1c3 = matrix2->r1c3; + const double r1c1 = matriy->r1c1; + const double r1c2 = matriy->r1c2; + const double r1c3 = matriy->r1c3; - const double r2c1 = matrix2->r2c1; - const double r2c2 = matrix2->r2c2; - const double r2c3 = matrix2->r2c3; + const double r2c1 = matriy->r2c1; + const double r2c2 = matriy->r2c2; + const double r2c3 = matriy->r2c3; - const double r3c1 = matrix2->r3c1; - const double r3c2 = matrix2->r3c2; - const double r3c3 = matrix2->r3c3; + const double r3c1 = matriy->r3c1; + const double r3c2 = matriy->r3c2; + const double r3c3 = matriy->r3c3; - matrix2->r1c1 = matrix1->r1c1; - matrix2->r1c2 = matrix1->r1c2; - matrix2->r1c3 = matrix1->r1c3; + matriy->r1c1 = matrix->r1c1; + matriy->r1c2 = matrix->r1c2; + matriy->r1c3 = matrix->r1c3; - matrix2->r2c1 = matrix1->r2c1; - matrix2->r2c2 = matrix1->r2c2; - matrix2->r2c3 = matrix1->r2c3; + matriy->r2c1 = matrix->r2c1; + matriy->r2c2 = matrix->r2c2; + matriy->r2c3 = matrix->r2c3; - matrix2->r3c1 = matrix1->r3c1; - matrix2->r3c2 = matrix1->r3c2; - matrix2->r3c3 = matrix1->r3c3; + matriy->r3c1 = matrix->r3c1; + matriy->r3c2 = matrix->r3c2; + matriy->r3c3 = matrix->r3c3; - matrix1->r1c1 = r1c1; - matrix1->r1c2 = r1c2; - matrix1->r1c3 = r1c3; + matrix->r1c1 = r1c1; + matrix->r1c2 = r1c2; + matrix->r1c3 = r1c3; - matrix1->r2c1 = r2c1; - matrix1->r2c2 = r2c2; - matrix1->r2c3 = r2c3; + matrix->r2c1 = r2c1; + matrix->r2c2 = r2c2; + matrix->r2c3 = r2c3; - matrix1->r3c1 = r3c1; - matrix1->r3c2 = r3c2; - matrix1->r3c3 = r3c3; + matrix->r3c1 = r3c1; + matrix->r3c2 = r3c2; + matrix->r3c3 = r3c3; } // ================== Convert =================== // @@ -426,62 +426,62 @@ inline void bgc_fp32_matrix3x3_get_row(BGC_FP32_Vector3* const row, const BGC_FP { if (row_number == 1) { - row->x1 = matrix->r1c1; - row->x2 = matrix->r1c2; - row->x3 = matrix->r1c3; + row->x = matrix->r1c1; + row->y = matrix->r1c2; + row->z = matrix->r1c3; return; } if (row_number == 2) { - row->x1 = matrix->r2c1; - row->x2 = matrix->r2c2; - row->x3 = matrix->r2c3; + row->x = matrix->r2c1; + row->y = matrix->r2c2; + row->z = matrix->r2c3; return; } if (row_number == 3) { - row->x1 = matrix->r3c1; - row->x2 = matrix->r3c2; - row->x3 = matrix->r3c3; + row->x = matrix->r3c1; + row->y = matrix->r3c2; + row->z = matrix->r3c3; return; } - row->x1 = 0.0f; - row->x2 = 0.0f; - row->x3 = 0.0f; + row->x = 0.0f; + row->y = 0.0f; + row->z = 0.0f; } inline void bgc_fp64_matrix3x3_get_row(BGC_FP64_Vector3* const row, const BGC_FP64_Matrix3x3* const matrix, const int row_number) { if (row_number == 1) { - row->x1 = matrix->r1c1; - row->x2 = matrix->r1c2; - row->x3 = matrix->r1c3; + row->x = matrix->r1c1; + row->y = matrix->r1c2; + row->z = matrix->r1c3; return; } if (row_number == 2) { - row->x1 = matrix->r2c1; - row->x2 = matrix->r2c2; - row->x3 = matrix->r2c3; + row->x = matrix->r2c1; + row->y = matrix->r2c2; + row->z = matrix->r2c3; return; } if (row_number == 3) { - row->x1 = matrix->r3c1; - row->x2 = matrix->r3c2; - row->x3 = matrix->r3c3; + row->x = matrix->r3c1; + row->y = matrix->r3c2; + row->z = matrix->r3c3; return; } - row->x1 = 0.0; - row->x2 = 0.0; - row->x3 = 0.0; + row->x = 0.0; + row->y = 0.0; + row->z = 0.0; } // ================== Set Row =================== // @@ -490,25 +490,25 @@ inline void bgc_fp32_matrix3x3_set_row(BGC_FP32_Matrix3x3* const matrix, const i { if (row_number == 1) { - matrix->r1c1 = row->x1; - matrix->r1c2 = row->x2; - matrix->r1c3 = row->x3; + matrix->r1c1 = row->x; + matrix->r1c2 = row->y; + matrix->r1c3 = row->z; return; } if (row_number == 2) { - matrix->r2c1 = row->x1; - matrix->r2c2 = row->x2; - matrix->r2c3 = row->x3; + matrix->r2c1 = row->x; + matrix->r2c2 = row->y; + matrix->r2c3 = row->z; return; } if (row_number == 3) { - matrix->r3c1 = row->x1; - matrix->r3c2 = row->x2; - matrix->r3c3 = row->x3; + matrix->r3c1 = row->x; + matrix->r3c2 = row->y; + matrix->r3c3 = row->z; } } @@ -516,25 +516,25 @@ inline void bgc_fp64_matrix3x3_set_row(BGC_FP64_Matrix3x3* const matrix, const i { if (row_number == 1) { - matrix->r1c1 = row->x1; - matrix->r1c2 = row->x2; - matrix->r1c3 = row->x3; + matrix->r1c1 = row->x; + matrix->r1c2 = row->y; + matrix->r1c3 = row->z; return; } if (row_number == 2) { - matrix->r2c1 = row->x1; - matrix->r2c2 = row->x2; - matrix->r2c3 = row->x3; + matrix->r2c1 = row->x; + matrix->r2c2 = row->y; + matrix->r2c3 = row->z; return; } if (row_number == 3) { - matrix->r3c1 = row->x1; - matrix->r3c2 = row->x2; - matrix->r3c3 = row->x3; + matrix->r3c1 = row->x; + matrix->r3c2 = row->y; + matrix->r3c3 = row->z; } } @@ -544,62 +544,62 @@ inline void bgc_fp32_matrix3x3_get_column(BGC_FP32_Vector3* const column, const { if (column_number == 1) { - column->x1 = matrix->r1c1; - column->x2 = matrix->r2c1; - column->x3 = matrix->r3c1; + column->x = matrix->r1c1; + column->y = matrix->r2c1; + column->z = matrix->r3c1; return; } if (column_number == 2) { - column->x1 = matrix->r1c2; - column->x2 = matrix->r2c2; - column->x3 = matrix->r3c2; + column->x = matrix->r1c2; + column->y = matrix->r2c2; + column->z = matrix->r3c2; return; } if (column_number == 3) { - column->x1 = matrix->r1c3; - column->x2 = matrix->r2c3; - column->x3 = matrix->r3c3; + column->x = matrix->r1c3; + column->y = matrix->r2c3; + column->z = matrix->r3c3; return; } - column->x1 = 0.0f; - column->x2 = 0.0f; - column->x3 = 0.0f; + column->x = 0.0f; + column->y = 0.0f; + column->z = 0.0f; } inline void bgc_fp64_matrix3x3_get_column(BGC_FP64_Vector3* const column, const BGC_FP64_Matrix3x3* const matrix, const int column_number) { if (column_number == 1) { - column->x1 = matrix->r1c1; - column->x2 = matrix->r2c1; - column->x3 = matrix->r3c1; + column->x = matrix->r1c1; + column->y = matrix->r2c1; + column->z = matrix->r3c1; return; } if (column_number == 2) { - column->x1 = matrix->r1c2; - column->x2 = matrix->r2c2; - column->x3 = matrix->r3c2; + column->x = matrix->r1c2; + column->y = matrix->r2c2; + column->z = matrix->r3c2; return; } if (column_number == 3) { - column->x1 = matrix->r1c3; - column->x2 = matrix->r2c3; - column->x3 = matrix->r3c3; + column->x = matrix->r1c3; + column->y = matrix->r2c3; + column->z = matrix->r3c3; return; } - column->x1 = 0.0; - column->x2 = 0.0; - column->x3 = 0.0; + column->x = 0.0; + column->y = 0.0; + column->z = 0.0; } // ================= Set Column ================= // @@ -608,25 +608,25 @@ inline void bgc_fp32_matrix3x3_set_column(BGC_FP32_Matrix3x3* const matrix, cons { if (column_number == 1) { - matrix->r1c1 = column->x1; - matrix->r2c1 = column->x2; - matrix->r3c1 = column->x3; + matrix->r1c1 = column->x; + matrix->r2c1 = column->y; + matrix->r3c1 = column->z; return; } if (column_number == 2) { - matrix->r1c2 = column->x1; - matrix->r2c2 = column->x2; - matrix->r3c2 = column->x3; + matrix->r1c2 = column->x; + matrix->r2c2 = column->y; + matrix->r3c2 = column->z; return; } if (column_number == 3) { - matrix->r1c3 = column->x1; - matrix->r2c3 = column->x2; - matrix->r3c3 = column->x3; + matrix->r1c3 = column->x; + matrix->r2c3 = column->y; + matrix->r3c3 = column->z; } } @@ -634,58 +634,58 @@ inline void bgc_fp64_matrix3x3_set_column(BGC_FP64_Matrix3x3* const matrix, cons { if (column_number == 1) { - matrix->r1c1 = column->x1; - matrix->r2c1 = column->x2; - matrix->r3c1 = column->x3; + matrix->r1c1 = column->x; + matrix->r2c1 = column->y; + matrix->r3c1 = column->z; return; } if (column_number == 2) { - matrix->r1c2 = column->x1; - matrix->r2c2 = column->x2; - matrix->r3c2 = column->x3; + matrix->r1c2 = column->x; + matrix->r2c2 = column->y; + matrix->r3c2 = column->z; return; } if (column_number == 3) { - matrix->r1c3 = column->x1; - matrix->r2c3 = column->x2; - matrix->r3c3 = column->x3; + matrix->r1c3 = column->x; + matrix->r2c3 = column->y; + matrix->r3c3 = column->z; } } // ==================== Add ===================== // -inline void bgc_fp32_matrix3x3_add(BGC_FP32_Matrix3x3* const sum, const BGC_FP32_Matrix3x3* const matrix1, const BGC_FP32_Matrix3x3* const matrix2) +inline void bgc_fp32_matrix3x3_add(BGC_FP32_Matrix3x3* const sum, const BGC_FP32_Matrix3x3* const matrix, const BGC_FP32_Matrix3x3* const matriy) { - sum->r1c1 = matrix1->r1c1 + matrix2->r1c1; - sum->r1c2 = matrix1->r1c2 + matrix2->r1c2; - sum->r1c3 = matrix1->r1c3 + matrix2->r1c3; + sum->r1c1 = matrix->r1c1 + matriy->r1c1; + sum->r1c2 = matrix->r1c2 + matriy->r1c2; + sum->r1c3 = matrix->r1c3 + matriy->r1c3; - sum->r2c1 = matrix1->r2c1 + matrix2->r2c1; - sum->r2c2 = matrix1->r2c2 + matrix2->r2c2; - sum->r2c3 = matrix1->r2c3 + matrix2->r2c3; + sum->r2c1 = matrix->r2c1 + matriy->r2c1; + sum->r2c2 = matrix->r2c2 + matriy->r2c2; + sum->r2c3 = matrix->r2c3 + matriy->r2c3; - sum->r3c1 = matrix1->r3c1 + matrix2->r3c1; - sum->r3c2 = matrix1->r3c2 + matrix2->r3c2; - sum->r3c3 = matrix1->r3c3 + matrix2->r3c3; + sum->r3c1 = matrix->r3c1 + matriy->r3c1; + sum->r3c2 = matrix->r3c2 + matriy->r3c2; + sum->r3c3 = matrix->r3c3 + matriy->r3c3; } -inline void bgc_fp64_matrix3x3_add(BGC_FP64_Matrix3x3* const sum, const BGC_FP64_Matrix3x3* const matrix1, const BGC_FP64_Matrix3x3* const matrix2) +inline void bgc_fp64_matrix3x3_add(BGC_FP64_Matrix3x3* const sum, const BGC_FP64_Matrix3x3* const matrix, const BGC_FP64_Matrix3x3* const matriy) { - sum->r1c1 = matrix1->r1c1 + matrix2->r1c1; - sum->r1c2 = matrix1->r1c2 + matrix2->r1c2; - sum->r1c3 = matrix1->r1c3 + matrix2->r1c3; + sum->r1c1 = matrix->r1c1 + matriy->r1c1; + sum->r1c2 = matrix->r1c2 + matriy->r1c2; + sum->r1c3 = matrix->r1c3 + matriy->r1c3; - sum->r2c1 = matrix1->r2c1 + matrix2->r2c1; - sum->r2c2 = matrix1->r2c2 + matrix2->r2c2; - sum->r2c3 = matrix1->r2c3 + matrix2->r2c3; + sum->r2c1 = matrix->r2c1 + matriy->r2c1; + sum->r2c2 = matrix->r2c2 + matriy->r2c2; + sum->r2c3 = matrix->r2c3 + matriy->r2c3; - sum->r3c1 = matrix1->r3c1 + matrix2->r3c1; - sum->r3c2 = matrix1->r3c2 + matrix2->r3c2; - sum->r3c3 = matrix1->r3c3 + matrix2->r3c3; + sum->r3c1 = matrix->r3c1 + matriy->r3c1; + sum->r3c2 = matrix->r3c2 + matriy->r3c2; + sum->r3c3 = matrix->r3c3 + matriy->r3c3; } // ================= Add Scaled ================= // @@ -820,118 +820,118 @@ inline void bgc_fp64_matrix3x3_multiply_by_real_number(BGC_FP64_Matrix3x3* const inline void bgc_fp32_matrix3x3_multiply_by_vector3(BGC_FP32_Vector3* const product, const BGC_FP32_Matrix3x3* const matrix, const BGC_FP32_Vector3* const vector) { - const float x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3; - const float x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3; - const float x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2 + matrix->r3c3 * vector->x3; + const float x = matrix->r1c1 * vector->x + matrix->r1c2 * vector->y + matrix->r1c3 * vector->z; + const float y = matrix->r2c1 * vector->x + matrix->r2c2 * vector->y + matrix->r2c3 * vector->z; + const float z = matrix->r3c1 * vector->x + matrix->r3c2 * vector->y + matrix->r3c3 * vector->z; - product->x1 = x1; - product->x2 = x2; - product->x3 = x3; + product->x = x; + product->y = y; + product->z = z; } inline void bgc_fp64_matrix3x3_multiply_by_vector3(BGC_FP64_Vector3* const product, const BGC_FP64_Matrix3x3* const matrix, const BGC_FP64_Vector3* const vector) { - const double x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3; - const double x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3; - const double x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2 + matrix->r3c3 * vector->x3; + const double x = matrix->r1c1 * vector->x + matrix->r1c2 * vector->y + matrix->r1c3 * vector->z; + const double y = matrix->r2c1 * vector->x + matrix->r2c2 * vector->y + matrix->r2c3 * vector->z; + const double z = matrix->r3c1 * vector->x + matrix->r3c2 * vector->y + matrix->r3c3 * vector->z; - product->x1 = x1; - product->x2 = x2; - product->x3 = x3; + product->x = x; + product->y = y; + product->z = z; } // ========= Right Dual Vector Product ========== // inline void bgc_fp32_matrix3x3_multiply_by_dual_vector3(BGC_FP32_DualVector3* const product, const BGC_FP32_Matrix3x3* const matrix, const BGC_FP32_DualVector3* const vector) { - const float real_x1 = matrix->r1c1 * vector->real_part.x1 + matrix->r1c2 * vector->real_part.x2 + matrix->r1c3 * vector->real_part.x3; - const float real_x2 = matrix->r2c1 * vector->real_part.x1 + matrix->r2c2 * vector->real_part.x2 + matrix->r2c3 * vector->real_part.x3; - const float real_x3 = matrix->r3c1 * vector->real_part.x1 + matrix->r3c2 * vector->real_part.x2 + matrix->r3c3 * vector->real_part.x3; + const float real_x = matrix->r1c1 * vector->real_part.x + matrix->r1c2 * vector->real_part.y + matrix->r1c3 * vector->real_part.z; + const float real_y = matrix->r2c1 * vector->real_part.x + matrix->r2c2 * vector->real_part.y + matrix->r2c3 * vector->real_part.z; + const float real_z = matrix->r3c1 * vector->real_part.x + matrix->r3c2 * vector->real_part.y + matrix->r3c3 * vector->real_part.z; - const float dual_x1 = matrix->r1c1 * vector->dual_part.x1 + matrix->r1c2 * vector->dual_part.x2 + matrix->r1c3 * vector->dual_part.x3; - const float dual_x2 = matrix->r2c1 * vector->dual_part.x1 + matrix->r2c2 * vector->dual_part.x2 + matrix->r2c3 * vector->dual_part.x3; - const float dual_x3 = matrix->r3c1 * vector->dual_part.x1 + matrix->r3c2 * vector->dual_part.x2 + matrix->r3c3 * vector->dual_part.x3; + const float dual_x = matrix->r1c1 * vector->dual_part.x + matrix->r1c2 * vector->dual_part.y + matrix->r1c3 * vector->dual_part.z; + const float dual_y = matrix->r2c1 * vector->dual_part.x + matrix->r2c2 * vector->dual_part.y + matrix->r2c3 * vector->dual_part.z; + const float dual_z = matrix->r3c1 * vector->dual_part.x + matrix->r3c2 * vector->dual_part.y + matrix->r3c3 * vector->dual_part.z; - product->real_part.x1 = real_x1; - product->real_part.x2 = real_x2; - product->real_part.x3 = real_x3; + product->real_part.x = real_x; + product->real_part.y = real_y; + product->real_part.z = real_z; - product->real_part.x1 = real_x1; - product->real_part.x2 = real_x2; - product->real_part.x3 = real_x3; + product->real_part.x = real_x; + product->real_part.y = real_y; + product->real_part.z = real_z; } inline void bgc_fp64_matrix3x3_multiply_by_dual_vector3(BGC_FP64_DualVector3* const product, const BGC_FP64_Matrix3x3* const matrix, const BGC_FP64_DualVector3* const vector) { - const double real_x1 = matrix->r1c1 * vector->real_part.x1 + matrix->r1c2 * vector->real_part.x2 + matrix->r1c3 * vector->real_part.x3; - const double real_x2 = matrix->r2c1 * vector->real_part.x1 + matrix->r2c2 * vector->real_part.x2 + matrix->r2c3 * vector->real_part.x3; - const double real_x3 = matrix->r3c1 * vector->real_part.x1 + matrix->r3c2 * vector->real_part.x2 + matrix->r3c3 * vector->real_part.x3; + const double real_x = matrix->r1c1 * vector->real_part.x + matrix->r1c2 * vector->real_part.y + matrix->r1c3 * vector->real_part.z; + const double real_y = matrix->r2c1 * vector->real_part.x + matrix->r2c2 * vector->real_part.y + matrix->r2c3 * vector->real_part.z; + const double real_z = matrix->r3c1 * vector->real_part.x + matrix->r3c2 * vector->real_part.y + matrix->r3c3 * vector->real_part.z; - const double dual_x1 = matrix->r1c1 * vector->dual_part.x1 + matrix->r1c2 * vector->dual_part.x2 + matrix->r1c3 * vector->dual_part.x3; - const double dual_x2 = matrix->r2c1 * vector->dual_part.x1 + matrix->r2c2 * vector->dual_part.x2 + matrix->r2c3 * vector->dual_part.x3; - const double dual_x3 = matrix->r3c1 * vector->dual_part.x1 + matrix->r3c2 * vector->dual_part.x2 + matrix->r3c3 * vector->dual_part.x3; + const double dual_x = matrix->r1c1 * vector->dual_part.x + matrix->r1c2 * vector->dual_part.y + matrix->r1c3 * vector->dual_part.z; + const double dual_y = matrix->r2c1 * vector->dual_part.x + matrix->r2c2 * vector->dual_part.y + matrix->r2c3 * vector->dual_part.z; + const double dual_z = matrix->r3c1 * vector->dual_part.x + matrix->r3c2 * vector->dual_part.y + matrix->r3c3 * vector->dual_part.z; - product->real_part.x1 = real_x1; - product->real_part.x2 = real_x2; - product->real_part.x3 = real_x3; + product->real_part.x = real_x; + product->real_part.y = real_y; + product->real_part.z = real_z; - product->real_part.x1 = real_x1; - product->real_part.x2 = real_x2; - product->real_part.x3 = real_x3; + product->real_part.x = real_x; + product->real_part.y = real_y; + product->real_part.z = real_z; } // ======= Restrict Right Vector Product ======== // inline void _bgc_fp32_restrict_matrix3x3_multiply_by_vector3(BGC_FP32_Vector3* restrict const product, const BGC_FP32_Matrix3x3* const matrix, const BGC_FP32_Vector3* const vector) { - product->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3; - product->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3; - product->x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2 + matrix->r3c3 * vector->x3; + product->x = matrix->r1c1 * vector->x + matrix->r1c2 * vector->y + matrix->r1c3 * vector->z; + product->y = matrix->r2c1 * vector->x + matrix->r2c2 * vector->y + matrix->r2c3 * vector->z; + product->z = matrix->r3c1 * vector->x + matrix->r3c2 * vector->y + matrix->r3c3 * vector->z; } inline void _bgc_fp64_restrict_matrix3x3_multiply_by_vector3(BGC_FP64_Vector3* restrict const product, const BGC_FP64_Matrix3x3* const matrix, const BGC_FP64_Vector3* const vector) { - product->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3; - product->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3; - product->x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2 + matrix->r3c3 * vector->x3; + product->x = matrix->r1c1 * vector->x + matrix->r1c2 * vector->y + matrix->r1c3 * vector->z; + product->y = matrix->r2c1 * vector->x + matrix->r2c2 * vector->y + matrix->r2c3 * vector->z; + product->z = matrix->r3c1 * vector->x + matrix->r3c2 * vector->y + matrix->r3c3 * vector->z; } // ========= Right Dual Vector Product ========== // inline void _bgc_fp32_restrict_matrix3x3_multiply_by_dual_vector3(BGC_FP32_DualVector3* restrict const product, const BGC_FP32_Matrix3x3* const matrix, const BGC_FP32_DualVector3* const vector) { - product->real_part.x1 = matrix->r1c1 * vector->real_part.x1 + matrix->r1c2 * vector->real_part.x2 + matrix->r1c3 * vector->real_part.x3; - product->real_part.x2 = matrix->r2c1 * vector->real_part.x1 + matrix->r2c2 * vector->real_part.x2 + matrix->r2c3 * vector->real_part.x3; - product->real_part.x3 = matrix->r3c1 * vector->real_part.x1 + matrix->r3c2 * vector->real_part.x2 + matrix->r3c3 * vector->real_part.x3; + product->real_part.x = matrix->r1c1 * vector->real_part.x + matrix->r1c2 * vector->real_part.y + matrix->r1c3 * vector->real_part.z; + product->real_part.y = matrix->r2c1 * vector->real_part.x + matrix->r2c2 * vector->real_part.y + matrix->r2c3 * vector->real_part.z; + product->real_part.z = matrix->r3c1 * vector->real_part.x + matrix->r3c2 * vector->real_part.y + matrix->r3c3 * vector->real_part.z; - product->real_part.x1 = matrix->r1c1 * vector->dual_part.x1 + matrix->r1c2 * vector->dual_part.x2 + matrix->r1c3 * vector->dual_part.x3; - product->real_part.x2 = matrix->r2c1 * vector->dual_part.x1 + matrix->r2c2 * vector->dual_part.x2 + matrix->r2c3 * vector->dual_part.x3; - product->real_part.x3 = matrix->r3c1 * vector->dual_part.x1 + matrix->r3c2 * vector->dual_part.x2 + matrix->r3c3 * vector->dual_part.x3; + product->real_part.x = matrix->r1c1 * vector->dual_part.x + matrix->r1c2 * vector->dual_part.y + matrix->r1c3 * vector->dual_part.z; + product->real_part.y = matrix->r2c1 * vector->dual_part.x + matrix->r2c2 * vector->dual_part.y + matrix->r2c3 * vector->dual_part.z; + product->real_part.z = matrix->r3c1 * vector->dual_part.x + matrix->r3c2 * vector->dual_part.y + matrix->r3c3 * vector->dual_part.z; } inline void _bgc_fp64_restrict_matrix3x3_multiply_by_dual_vector3(BGC_FP64_DualVector3* restrict const product, const BGC_FP64_Matrix3x3* const matrix, const BGC_FP64_DualVector3* const vector) { - product->real_part.x1 = matrix->r1c1 * vector->real_part.x1 + matrix->r1c2 * vector->real_part.x2 + matrix->r1c3 * vector->real_part.x3; - product->real_part.x2 = matrix->r2c1 * vector->real_part.x1 + matrix->r2c2 * vector->real_part.x2 + matrix->r2c3 * vector->real_part.x3; - product->real_part.x3 = matrix->r3c1 * vector->real_part.x1 + matrix->r3c2 * vector->real_part.x2 + matrix->r3c3 * vector->real_part.x3; + product->real_part.x = matrix->r1c1 * vector->real_part.x + matrix->r1c2 * vector->real_part.y + matrix->r1c3 * vector->real_part.z; + product->real_part.y = matrix->r2c1 * vector->real_part.x + matrix->r2c2 * vector->real_part.y + matrix->r2c3 * vector->real_part.z; + product->real_part.z = matrix->r3c1 * vector->real_part.x + matrix->r3c2 * vector->real_part.y + matrix->r3c3 * vector->real_part.z; - product->real_part.x1 = matrix->r1c1 * vector->dual_part.x1 + matrix->r1c2 * vector->dual_part.x2 + matrix->r1c3 * vector->dual_part.x3; - product->real_part.x2 = matrix->r2c1 * vector->dual_part.x1 + matrix->r2c2 * vector->dual_part.x2 + matrix->r2c3 * vector->dual_part.x3; - product->real_part.x3 = matrix->r3c1 * vector->dual_part.x1 + matrix->r3c2 * vector->dual_part.x2 + matrix->r3c3 * vector->dual_part.x3; + product->real_part.x = matrix->r1c1 * vector->dual_part.x + matrix->r1c2 * vector->dual_part.y + matrix->r1c3 * vector->dual_part.z; + product->real_part.y = matrix->r2c1 * vector->dual_part.x + matrix->r2c2 * vector->dual_part.y + matrix->r2c3 * vector->dual_part.z; + product->real_part.z = matrix->r3c1 * vector->dual_part.x + matrix->r3c2 * vector->dual_part.y + matrix->r3c3 * vector->dual_part.z; } -// ========== Matrix Product 3x3 at 2x3 ========= // +// ========== Matrix Product 3z at 2z ========= // -inline void bgc_fp32_matrix3x3_multiply_by_matrix2x3(BGC_FP32_Matrix2x3* const product, const BGC_FP32_Matrix3x3* const matrix1, const BGC_FP32_Matrix2x3* const matrix2) +inline void bgc_fp32_matrix3x3_multiply_by_matrix2x3(BGC_FP32_Matrix2x3* const product, const BGC_FP32_Matrix3x3* const matrix, const BGC_FP32_Matrix2x3* const matriy) { - 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 r1c1 = matrix->r1c1 * matriy->r1c1 + matrix->r1c2 * matriy->r2c1 + matrix->r1c3 * matriy->r3c1; + const float r1c2 = matrix->r1c1 * matriy->r1c2 + matrix->r1c2 * matriy->r2c2 + matrix->r1c3 * matriy->r3c2; - 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 r2c1 = matrix->r2c1 * matriy->r1c1 + matrix->r2c2 * matriy->r2c1 + matrix->r2c3 * matriy->r3c1; + const float r2c2 = matrix->r2c1 * matriy->r1c2 + matrix->r2c2 * matriy->r2c2 + matrix->r2c3 * matriy->r3c2; - 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 r3c1 = matrix->r3c1 * matriy->r1c1 + matrix->r3c2 * matriy->r2c1 + matrix->r3c3 * matriy->r3c1; + const float r3c2 = matrix->r3c1 * matriy->r1c2 + matrix->r3c2 * matriy->r2c2 + matrix->r3c3 * matriy->r3c2; product->r1c1 = r1c1; product->r1c2 = r1c2; @@ -943,16 +943,16 @@ inline void bgc_fp32_matrix3x3_multiply_by_matrix2x3(BGC_FP32_Matrix2x3* const p product->r3c2 = r3c2; } -inline void bgc_fp64_matrix3x3_multiply_by_matrix2x3(BGC_FP64_Matrix2x3* const product, const BGC_FP64_Matrix3x3* const matrix1, const BGC_FP64_Matrix2x3* const matrix2) +inline void bgc_fp64_matrix3x3_multiply_by_matrix2x3(BGC_FP64_Matrix2x3* const product, const BGC_FP64_Matrix3x3* const matrix, const BGC_FP64_Matrix2x3* const matriy) { - 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 r1c1 = matrix->r1c1 * matriy->r1c1 + matrix->r1c2 * matriy->r2c1 + matrix->r1c3 * matriy->r3c1; + const double r1c2 = matrix->r1c1 * matriy->r1c2 + matrix->r1c2 * matriy->r2c2 + matrix->r1c3 * matriy->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 r2c1 = matrix->r2c1 * matriy->r1c1 + matrix->r2c2 * matriy->r2c1 + matrix->r2c3 * matriy->r3c1; + const double r2c2 = matrix->r2c1 * matriy->r1c2 + matrix->r2c2 * matriy->r2c2 + matrix->r2c3 * matriy->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; + const double r3c1 = matrix->r3c1 * matriy->r1c1 + matrix->r3c2 * matriy->r2c1 + matrix->r3c3 * matriy->r3c1; + const double r3c2 = matrix->r3c1 * matriy->r1c2 + matrix->r3c2 * matriy->r2c2 + matrix->r3c3 * matriy->r3c2; product->r1c1 = r1c1; product->r1c2 = r1c2; @@ -964,21 +964,21 @@ inline void bgc_fp64_matrix3x3_multiply_by_matrix2x3(BGC_FP64_Matrix2x3* const p product->r3c2 = r3c2; } -// ========== Matrix Product 3x3 at 3x3 ========= // +// ========== Matrix Product 3z at 3z ========= // -inline void bgc_fp32_matrix3x3_multiply_by_matrix3x3(BGC_FP32_Matrix3x3* const product, const BGC_FP32_Matrix3x3* const matrix1, const BGC_FP32_Matrix3x3* const matrix2) +inline void bgc_fp32_matrix3x3_multiply_by_matrix3x3(BGC_FP32_Matrix3x3* const product, const BGC_FP32_Matrix3x3* const matrix, const BGC_FP32_Matrix3x3* const matriy) { - 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 r1c1 = matrix->r1c1 * matriy->r1c1 + matrix->r1c2 * matriy->r2c1 + matrix->r1c3 * matriy->r3c1; + const float r1c2 = matrix->r1c1 * matriy->r1c2 + matrix->r1c2 * matriy->r2c2 + matrix->r1c3 * matriy->r3c2; + const float r1c3 = matrix->r1c1 * matriy->r1c3 + matrix->r1c2 * matriy->r2c3 + matrix->r1c3 * matriy->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 r2c1 = matrix->r2c1 * matriy->r1c1 + matrix->r2c2 * matriy->r2c1 + matrix->r2c3 * matriy->r3c1; + const float r2c2 = matrix->r2c1 * matriy->r1c2 + matrix->r2c2 * matriy->r2c2 + matrix->r2c3 * matriy->r3c2; + const float r2c3 = matrix->r2c1 * matriy->r1c3 + matrix->r2c2 * matriy->r2c3 + matrix->r2c3 * matriy->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; + const float r3c1 = matrix->r3c1 * matriy->r1c1 + matrix->r3c2 * matriy->r2c1 + matrix->r3c3 * matriy->r3c1; + const float r3c2 = matrix->r3c1 * matriy->r1c2 + matrix->r3c2 * matriy->r2c2 + matrix->r3c3 * matriy->r3c2; + const float r3c3 = matrix->r3c1 * matriy->r1c3 + matrix->r3c2 * matriy->r2c3 + matrix->r3c3 * matriy->r3c3; product->r1c1 = r1c1; product->r1c2 = r1c2; @@ -993,19 +993,19 @@ inline void bgc_fp32_matrix3x3_multiply_by_matrix3x3(BGC_FP32_Matrix3x3* const p product->r3c3 = r3c3; } -inline void bgc_fp64_matrix3x3_multiply_by_matrix3x3(BGC_FP64_Matrix3x3* const product, const BGC_FP64_Matrix3x3* const matrix1, const BGC_FP64_Matrix3x3* const matrix2) +inline void bgc_fp64_matrix3x3_multiply_by_matrix3x3(BGC_FP64_Matrix3x3* const product, const BGC_FP64_Matrix3x3* const matrix, const BGC_FP64_Matrix3x3* const matriy) { - 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 r1c1 = matrix->r1c1 * matriy->r1c1 + matrix->r1c2 * matriy->r2c1 + matrix->r1c3 * matriy->r3c1; + const double r1c2 = matrix->r1c1 * matriy->r1c2 + matrix->r1c2 * matriy->r2c2 + matrix->r1c3 * matriy->r3c2; + const double r1c3 = matrix->r1c1 * matriy->r1c3 + matrix->r1c2 * matriy->r2c3 + matrix->r1c3 * matriy->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 r2c1 = matrix->r2c1 * matriy->r1c1 + matrix->r2c2 * matriy->r2c1 + matrix->r2c3 * matriy->r3c1; + const double r2c2 = matrix->r2c1 * matriy->r1c2 + matrix->r2c2 * matriy->r2c2 + matrix->r2c3 * matriy->r3c2; + const double r2c3 = matrix->r2c1 * matriy->r1c3 + matrix->r2c2 * matriy->r2c3 + matrix->r2c3 * matriy->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; + const double r3c1 = matrix->r3c1 * matriy->r1c1 + matrix->r3c2 * matriy->r2c1 + matrix->r3c3 * matriy->r3c1; + const double r3c2 = matrix->r3c1 * matriy->r1c2 + matrix->r3c2 * matriy->r2c2 + matrix->r3c3 * matriy->r3c2; + const double r3c3 = matrix->r3c1 * matriy->r1c3 + matrix->r3c2 * matriy->r2c3 + matrix->r3c3 * matriy->r3c3; product->r1c1 = r1c1; product->r1c2 = r1c2; diff --git a/basic-geometry/quaternion.c b/basic-geometry/quaternion.c index 9a05b90..e659cae 100644 --- a/basic-geometry/quaternion.c +++ b/basic-geometry/quaternion.c @@ -7,8 +7,8 @@ extern inline void bgc_fp64_quaternion_reset(BGC_FP64_Quaternion* const quaterni extern inline void bgc_fp32_quaternion_make_unit(BGC_FP32_Quaternion* const quaternion); extern inline void bgc_fp64_quaternion_make_unit(BGC_FP64_Quaternion* const quaternion); -extern inline void bgc_fp32_quaternion_set_values(BGC_FP32_Quaternion* const quaternion, const float s0, const float x1, const float x2, const float x3); -extern inline void bgc_fp64_quaternion_set_values(BGC_FP64_Quaternion* const quaternion, const double s0, const double x1, const double x2, const double x3); +extern inline void bgc_fp32_quaternion_set_values(BGC_FP32_Quaternion* const quaternion, const float s, const float x, const float y, const float z); +extern inline void bgc_fp64_quaternion_set_values(BGC_FP64_Quaternion* const quaternion, const double s, const double x, const double y, const double z); extern inline float bgc_fp32_quaternion_get_square_magnitude(const BGC_FP32_Quaternion* const quaternion); extern inline double bgc_fp64_quaternion_get_square_magnitude(const BGC_FP64_Quaternion* const quaternion); @@ -158,13 +158,13 @@ extern inline int bgc_fp64_quaternion_are_close(const BGC_FP64_Quaternion* const int bgc_fp32_quaternion_get_power(BGC_FP32_Quaternion* const power, const BGC_FP32_Quaternion* const base, const float exponent) { - const float s0s0 = base->s0 * base->s0; - const float x1x1 = base->x1 * base->x1; - const float x2x2 = base->x2 * base->x2; - const float x3x3 = base->x3 * base->x3; + const float ss = base->s * base->s; + const float xx = base->x * base->x; + const float yy = base->y * base->y; + const float zz = base->z * base->z; - const float square_vector = x1x1 + (x2x2 + x3x3); - const float square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3); + const float square_vector = xx + (yy + zz); + const float square_modulus = (ss + xx) + (yy + zz); // isnan(square_modulus) means checking for NaN value at square_modulus if (isnan(square_modulus)) { @@ -172,40 +172,40 @@ int bgc_fp32_quaternion_get_power(BGC_FP32_Quaternion* const power, const BGC_FP } if (square_vector <= BGC_FP32_SQUARE_EPSILON) { - if (base->s0 < 0.0f) { + if (base->s < 0.0f) { return BGC_FAILURE; } - power->s0 = powf(base->s0, exponent); - power->x1 = 0.0f; - power->x2 = 0.0f; - power->x3 = 0.0f; + power->s = powf(base->s, exponent); + power->x = 0.0f; + power->y = 0.0f; + power->z = 0.0f; return BGC_SUCCESS; } const float vector_modulus = sqrtf(square_vector); - const float power_angle = atan2f(vector_modulus, base->s0) * exponent; + const float power_angle = atan2f(vector_modulus, base->s) * exponent; const float power_modulus = powf(square_modulus, 0.5f * exponent); const float multiplier = power_modulus * sinf(power_angle) / vector_modulus; - power->s0 = power_modulus * cosf(power_angle); - power->x1 = base->x1 * multiplier; - power->x2 = base->x2 * multiplier; - power->x3 = base->x3 * multiplier; + power->s = power_modulus * cosf(power_angle); + power->x = base->x * multiplier; + power->y = base->y * multiplier; + power->z = base->z * multiplier; return BGC_SUCCESS; } int bgc_fp64_quaternion_get_power(BGC_FP64_Quaternion* const power, const BGC_FP64_Quaternion* const base, const double exponent) { - const double s0s0 = base->s0 * base->s0; - const double x1x1 = base->x1 * base->x1; - const double x2x2 = base->x2 * base->x2; - const double x3x3 = base->x3 * base->x3; + const double ss = base->s * base->s; + const double xx = base->x * base->x; + const double yy = base->y * base->y; + const double zz = base->z * base->z; - const double square_vector = x1x1 + (x2x2 + x3x3); - const double square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3); + const double square_vector = xx + (yy + zz); + const double square_modulus = (ss + xx) + (yy + zz); // isnan(square_modulus) means checking for NaN value at square_modulus if (isnan(square_modulus)) { @@ -213,27 +213,27 @@ int bgc_fp64_quaternion_get_power(BGC_FP64_Quaternion* const power, const BGC_FP } if (square_vector <= BGC_FP64_SQUARE_EPSILON) { - if (base->s0 < 0.0) { + if (base->s < 0.0) { return BGC_FAILURE; } - power->s0 = pow(base->s0, exponent); - power->x1 = 0.0; - power->x2 = 0.0; - power->x3 = 0.0; + power->s = pow(base->s, exponent); + power->x = 0.0; + power->y = 0.0; + power->z = 0.0; return BGC_SUCCESS; } const double vector_modulus = sqrt(square_vector); - const double power_angle = atan2(vector_modulus, base->s0) * exponent; + const double power_angle = atan2(vector_modulus, base->s) * exponent; const double power_modulus = pow(square_modulus, 0.5 * exponent); const double multiplier = power_modulus * sin(power_angle) / vector_modulus; - power->s0 = power_modulus * cos(power_angle); - power->x1 = base->x1 * multiplier; - power->x2 = base->x2 * multiplier; - power->x3 = base->x3 * multiplier; + power->s = power_modulus * cos(power_angle); + power->x = base->x * multiplier; + power->y = base->y * multiplier; + power->z = base->z * multiplier; return BGC_SUCCESS; } diff --git a/basic-geometry/quaternion.h b/basic-geometry/quaternion.h index 0ed7db3..6c33a2c 100644 --- a/basic-geometry/quaternion.h +++ b/basic-geometry/quaternion.h @@ -12,66 +12,66 @@ inline void bgc_fp32_quaternion_reset(BGC_FP32_Quaternion* const quaternion) { - quaternion->s0 = 0.0f; - quaternion->x1 = 0.0f; - quaternion->x2 = 0.0f; - quaternion->x3 = 0.0f; + quaternion->s = 0.0f; + quaternion->x = 0.0f; + quaternion->y = 0.0f; + quaternion->z = 0.0f; } inline void bgc_fp64_quaternion_reset(BGC_FP64_Quaternion* const quaternion) { - quaternion->s0 = 0.0; - quaternion->x1 = 0.0; - quaternion->x2 = 0.0; - quaternion->x3 = 0.0; + quaternion->s = 0.0; + quaternion->x = 0.0; + quaternion->y = 0.0; + quaternion->z = 0.0; } // ================= Make Unit ================== // inline void bgc_fp32_quaternion_make_unit(BGC_FP32_Quaternion* const quaternion) { - quaternion->s0 = 1.0f; - quaternion->x1 = 0.0f; - quaternion->x2 = 0.0f; - quaternion->x3 = 0.0f; + quaternion->s = 1.0f; + quaternion->x = 0.0f; + quaternion->y = 0.0f; + quaternion->z = 0.0f; } inline void bgc_fp64_quaternion_make_unit(BGC_FP64_Quaternion* const quaternion) { - quaternion->s0 = 1.0; - quaternion->x1 = 0.0; - quaternion->x2 = 0.0; - quaternion->x3 = 0.0; + quaternion->s = 1.0; + quaternion->x = 0.0; + quaternion->y = 0.0; + quaternion->z = 0.0; } // ==================== Set ===================== // -inline void bgc_fp32_quaternion_set_values(BGC_FP32_Quaternion* const quaternion, const float s0, const float x1, const float x2, const float x3) +inline void bgc_fp32_quaternion_set_values(BGC_FP32_Quaternion* const quaternion, const float s, const float x, const float y, const float z) { - quaternion->s0 = s0; - quaternion->x1 = x1; - quaternion->x2 = x2; - quaternion->x3 = x3; + quaternion->s = s; + quaternion->x = x; + quaternion->y = y; + quaternion->z = z; } -inline void bgc_fp64_quaternion_set_values(BGC_FP64_Quaternion* const quaternion, const double s0, const double x1, const double x2, const double x3) +inline void bgc_fp64_quaternion_set_values(BGC_FP64_Quaternion* const quaternion, const double s, const double x, const double y, const double z) { - quaternion->s0 = s0; - quaternion->x1 = x1; - quaternion->x2 = x2; - quaternion->x3 = x3; + quaternion->s = s; + quaternion->x = x; + quaternion->y = y; + quaternion->z = z; } // ============= Get Square Modulus ============= // inline float bgc_fp32_quaternion_get_square_magnitude(const BGC_FP32_Quaternion* const quaternion) { - return (quaternion->s0 * quaternion->s0 + quaternion->x1 * quaternion->x1) + (quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3); + return (quaternion->s * quaternion->s + quaternion->x * quaternion->x) + (quaternion->y * quaternion->y + quaternion->z * quaternion->z); } inline double bgc_fp64_quaternion_get_square_magnitude(const BGC_FP64_Quaternion* const quaternion) { - return (quaternion->s0 * quaternion->s0 + quaternion->x1 * quaternion->x1) + (quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3); + return (quaternion->s * quaternion->s + quaternion->x * quaternion->x) + (quaternion->y * quaternion->y + quaternion->z * quaternion->z); } // ================ Get Modulus ================= // @@ -114,412 +114,412 @@ inline int bgc_fp64_quaternion_is_unit(const BGC_FP64_Quaternion* const quaterni inline int bgc_fp32_quaternion_is_pure(const BGC_FP32_Quaternion* const quaternion) { - return bgc_fp32_is_zero(quaternion->s0); + return bgc_fp32_is_zero(quaternion->s); } inline int bgc_fp64_quaternion_is_pure(const BGC_FP64_Quaternion* const quaternion) { - return bgc_fp64_is_zero(quaternion->s0); + return bgc_fp64_is_zero(quaternion->s); } // ================== Is Real =================== // inline int bgc_fp32_quaternion_is_real(const BGC_FP32_Quaternion* const quaternion) { - return quaternion->x1 * quaternion->x1 + quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3 <= BGC_FP32_SQUARE_EPSILON; + return quaternion->x * quaternion->x + quaternion->y * quaternion->y + quaternion->z * quaternion->z <= BGC_FP32_SQUARE_EPSILON; } inline int bgc_fp64_quaternion_is_real(const BGC_FP64_Quaternion* const quaternion) { - return quaternion->x1 * quaternion->x1 + quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3 <= BGC_FP64_SQUARE_EPSILON; + return quaternion->x * quaternion->x + quaternion->y * quaternion->y + quaternion->z * quaternion->z <= BGC_FP64_SQUARE_EPSILON; } // ==================== Copy ==================== // inline void bgc_fp32_quaternion_copy(BGC_FP32_Quaternion* const destination, const BGC_FP32_Quaternion* const source) { - destination->s0 = source->s0; - destination->x1 = source->x1; - destination->x2 = source->x2; - destination->x3 = source->x3; + destination->s = source->s; + destination->x = source->x; + destination->y = source->y; + destination->z = source->z; } inline void bgc_fp64_quaternion_copy(BGC_FP64_Quaternion* const destination, const BGC_FP64_Quaternion* const source) { - destination->s0 = source->s0; - destination->x1 = source->x1; - destination->x2 = source->x2; - destination->x3 = source->x3; + destination->s = source->s; + destination->x = source->x; + destination->y = source->y; + destination->z = source->z; } // ==================== Swap ==================== // inline void bgc_fp32_quaternion_swap(BGC_FP32_Quaternion* const quarternion1, BGC_FP32_Quaternion* const quarternion2) { - const float s0 = quarternion2->s0; - const float x1 = quarternion2->x1; - const float x2 = quarternion2->x2; - const float x3 = quarternion2->x3; + const float s = quarternion2->s; + const float x = quarternion2->x; + const float y = quarternion2->y; + const float z = quarternion2->z; - quarternion2->s0 = quarternion1->s0; - quarternion2->x1 = quarternion1->x1; - quarternion2->x2 = quarternion1->x2; - quarternion2->x3 = quarternion1->x3; + quarternion2->s = quarternion1->s; + quarternion2->x = quarternion1->x; + quarternion2->y = quarternion1->y; + quarternion2->z = quarternion1->z; - quarternion1->s0 = s0; - quarternion1->x1 = x1; - quarternion1->x2 = x2; - quarternion1->x3 = x3; + quarternion1->s = s; + quarternion1->x = x; + quarternion1->y = y; + quarternion1->z = z; } inline void bgc_fp64_quaternion_swap(BGC_FP64_Quaternion* const quarternion1, BGC_FP64_Quaternion* const quarternion2) { - const double s0 = quarternion2->s0; - const double x1 = quarternion2->x1; - const double x2 = quarternion2->x2; - const double x3 = quarternion2->x3; + const double s = quarternion2->s; + const double x = quarternion2->x; + const double y = quarternion2->y; + const double z = quarternion2->z; - quarternion2->s0 = quarternion1->s0; - quarternion2->x1 = quarternion1->x1; - quarternion2->x2 = quarternion1->x2; - quarternion2->x3 = quarternion1->x3; + quarternion2->s = quarternion1->s; + quarternion2->x = quarternion1->x; + quarternion2->y = quarternion1->y; + quarternion2->z = quarternion1->z; - quarternion1->s0 = s0; - quarternion1->x1 = x1; - quarternion1->x2 = x2; - quarternion1->x3 = x3; + quarternion1->s = s; + quarternion1->x = x; + quarternion1->y = y; + quarternion1->z = z; } // ================== Convert =================== // inline void bgc_fp32_quaternion_convert_to_fp64(BGC_FP64_Quaternion* const destination, const BGC_FP32_Quaternion* const source) { - destination->s0 = source->s0; - destination->x1 = source->x1; - destination->x2 = source->x2; - destination->x3 = source->x3; + destination->s = source->s; + destination->x = source->x; + destination->y = source->y; + destination->z = source->z; } inline void bgc_fp64_quaternion_convert_to_fp32(BGC_FP32_Quaternion* const destination, const BGC_FP64_Quaternion* const source) { - destination->s0 = (float)source->s0; - destination->x1 = (float)source->x1; - destination->x2 = (float)source->x2; - destination->x3 = (float)source->x3; + destination->s = (float)source->s; + destination->x = (float)source->x; + destination->y = (float)source->y; + destination->z = (float)source->z; } // ==================== Add ===================== // inline void bgc_fp32_quaternion_add(BGC_FP32_Quaternion* const sum, const BGC_FP32_Quaternion* const quaternion1, const BGC_FP32_Quaternion* const quaternion2) { - sum->s0 = quaternion1->s0 + quaternion2->s0; - sum->x1 = quaternion1->x1 + quaternion2->x1; - sum->x2 = quaternion1->x2 + quaternion2->x2; - sum->x3 = quaternion1->x3 + quaternion2->x3; + sum->s = quaternion1->s + quaternion2->s; + sum->x = quaternion1->x + quaternion2->x; + sum->y = quaternion1->y + quaternion2->y; + sum->z = quaternion1->z + quaternion2->z; } inline void bgc_fp64_quaternion_add(BGC_FP64_Quaternion* const sum, const BGC_FP64_Quaternion* const quaternion1, const BGC_FP64_Quaternion* const quaternion2) { - sum->s0 = quaternion1->s0 + quaternion2->s0; - sum->x1 = quaternion1->x1 + quaternion2->x1; - sum->x2 = quaternion1->x2 + quaternion2->x2; - sum->x3 = quaternion1->x3 + quaternion2->x3; + sum->s = quaternion1->s + quaternion2->s; + sum->x = quaternion1->x + quaternion2->x; + sum->y = quaternion1->y + quaternion2->y; + sum->z = quaternion1->z + quaternion2->z; } // ================= Add Scaled ================= // inline void bgc_fp32_quaternion_add_scaled(BGC_FP32_Quaternion* const sum, const BGC_FP32_Quaternion* const basic_quaternion, const BGC_FP32_Quaternion* const scalable_quaternion, const float scale) { - sum->s0 = basic_quaternion->s0 + scalable_quaternion->s0 * scale; - sum->x1 = basic_quaternion->x1 + scalable_quaternion->x1 * scale; - sum->x2 = basic_quaternion->x2 + scalable_quaternion->x2 * scale; - sum->x3 = basic_quaternion->x3 + scalable_quaternion->x3 * scale; + sum->s = basic_quaternion->s + scalable_quaternion->s * scale; + sum->x = basic_quaternion->x + scalable_quaternion->x * scale; + sum->y = basic_quaternion->y + scalable_quaternion->y * scale; + sum->z = basic_quaternion->z + scalable_quaternion->z * scale; } inline void bgc_fp64_quaternion_add_scaled(BGC_FP64_Quaternion* const sum, const BGC_FP64_Quaternion* const basic_quaternion, const BGC_FP64_Quaternion* const scalable_quaternion, const double scale) { - sum->s0 = basic_quaternion->s0 + scalable_quaternion->s0 * scale; - sum->x1 = basic_quaternion->x1 + scalable_quaternion->x1 * scale; - sum->x2 = basic_quaternion->x2 + scalable_quaternion->x2 * scale; - sum->x3 = basic_quaternion->x3 + scalable_quaternion->x3 * scale; + sum->s = basic_quaternion->s + scalable_quaternion->s * scale; + sum->x = basic_quaternion->x + scalable_quaternion->x * scale; + sum->y = basic_quaternion->y + scalable_quaternion->y * scale; + sum->z = basic_quaternion->z + scalable_quaternion->z * scale; } // ================== Subtract ================== // inline void bgc_fp32_quaternion_subtract(BGC_FP32_Quaternion* const difference, const BGC_FP32_Quaternion* const minuend, const BGC_FP32_Quaternion* const subtrahend) { - difference->s0 = minuend->s0 - subtrahend->s0; - difference->x1 = minuend->x1 - subtrahend->x1; - difference->x2 = minuend->x2 - subtrahend->x2; - difference->x3 = minuend->x3 - subtrahend->x3; + difference->s = minuend->s - subtrahend->s; + difference->x = minuend->x - subtrahend->x; + difference->y = minuend->y - subtrahend->y; + difference->z = minuend->z - subtrahend->z; } inline void bgc_fp64_quaternion_subtract(BGC_FP64_Quaternion* const difference, const BGC_FP64_Quaternion* const minuend, const BGC_FP64_Quaternion* const subtrahend) { - difference->s0 = minuend->s0 - subtrahend->s0; - difference->x1 = minuend->x1 - subtrahend->x1; - difference->x2 = minuend->x2 - subtrahend->x2; - difference->x3 = minuend->x3 - subtrahend->x3; + difference->s = minuend->s - subtrahend->s; + difference->x = minuend->x - subtrahend->x; + difference->y = minuend->y - subtrahend->y; + difference->z = minuend->z - subtrahend->z; } // ============== Subtract Scaled =============== // inline void bgc_fp32_quaternion_subtract_scaled(BGC_FP32_Quaternion* const difference, const BGC_FP32_Quaternion* const basic_quaternion, const BGC_FP32_Quaternion* const scalable_quaternion, const float scale) { - difference->s0 = basic_quaternion->s0 - scalable_quaternion->s0 * scale; - difference->x1 = basic_quaternion->x1 - scalable_quaternion->x1 * scale; - difference->x2 = basic_quaternion->x2 - scalable_quaternion->x2 * scale; - difference->x3 = basic_quaternion->x3 - scalable_quaternion->x3 * scale; + difference->s = basic_quaternion->s - scalable_quaternion->s * scale; + difference->x = basic_quaternion->x - scalable_quaternion->x * scale; + difference->y = basic_quaternion->y - scalable_quaternion->y * scale; + difference->z = basic_quaternion->z - scalable_quaternion->z * scale; } inline void bgc_fp64_quaternion_subtract_scaled(BGC_FP64_Quaternion* const difference, const BGC_FP64_Quaternion* const basic_quaternion, const BGC_FP64_Quaternion* const scalable_quaternion, const double scale) { - difference->s0 = basic_quaternion->s0 - scalable_quaternion->s0 * scale; - difference->x1 = basic_quaternion->x1 - scalable_quaternion->x1 * scale; - difference->x2 = basic_quaternion->x2 - scalable_quaternion->x2 * scale; - difference->x3 = basic_quaternion->x3 - scalable_quaternion->x3 * scale; + difference->s = basic_quaternion->s - scalable_quaternion->s * scale; + difference->x = basic_quaternion->x - scalable_quaternion->x * scale; + difference->y = basic_quaternion->y - scalable_quaternion->y * scale; + difference->z = basic_quaternion->z - scalable_quaternion->z * scale; } // ============= Multiply By Number ============= // inline void bgc_fp32_quaternion_multiply_by_real_number(BGC_FP32_Quaternion* const product, const BGC_FP32_Quaternion* const multiplicand, const float multiplier) { - product->s0 = multiplicand->s0 * multiplier; - product->x1 = multiplicand->x1 * multiplier; - product->x2 = multiplicand->x2 * multiplier; - product->x3 = multiplicand->x3 * multiplier; + product->s = multiplicand->s * multiplier; + product->x = multiplicand->x * multiplier; + product->y = multiplicand->y * multiplier; + product->z = multiplicand->z * multiplier; } inline void bgc_fp64_quaternion_multiply_by_real_number(BGC_FP64_Quaternion* const product, const BGC_FP64_Quaternion* const multiplicand, const double multiplier) { - product->s0 = multiplicand->s0 * multiplier; - product->x1 = multiplicand->x1 * multiplier; - product->x2 = multiplicand->x2 * multiplier; - product->x3 = multiplicand->x3 * multiplier; + product->s = multiplicand->s * multiplier; + product->x = multiplicand->x * multiplier; + product->y = multiplicand->y * multiplier; + product->z = multiplicand->z * multiplier; } // ========== Multiply By Dual Number =========== // inline void bgc_fp32_quaternion_multiply_by_dual_number(BGC_FP32_DualQuaternion* const product, const BGC_FP32_Quaternion* const multiplicand, const BGC_FP32_DualNumber* const multiplier) { - const float real_s0 = multiplicand->s0 * multiplier->real_part; - const float real_x1 = multiplicand->x1 * multiplier->real_part; - const float real_x2 = multiplicand->x2 * multiplier->real_part; - const float real_x3 = multiplicand->x3 * multiplier->real_part; + const float real_s = multiplicand->s * multiplier->real_part; + const float real_x = multiplicand->x * multiplier->real_part; + const float real_y = multiplicand->y * multiplier->real_part; + const float real_z = multiplicand->z * multiplier->real_part; - const float dual_s0 = multiplicand->s0 * multiplier->dual_part; - const float dual_x1 = multiplicand->x1 * multiplier->dual_part; - const float dual_x2 = multiplicand->x2 * multiplier->dual_part; - const float dual_x3 = multiplicand->x3 * multiplier->dual_part; + const float dual_s = multiplicand->s * multiplier->dual_part; + const float dual_x = multiplicand->x * multiplier->dual_part; + const float dual_y = multiplicand->y * multiplier->dual_part; + const float dual_z = multiplicand->z * multiplier->dual_part; - product->real_part.s0 = real_s0; - product->real_part.x1 = real_x1; - product->real_part.x2 = real_x2; - product->real_part.x3 = real_x3; + product->real_part.s = real_s; + product->real_part.x = real_x; + product->real_part.y = real_y; + product->real_part.z = real_z; - product->dual_part.s0 = dual_s0; - product->dual_part.x1 = dual_x1; - product->dual_part.x2 = dual_x2; - product->dual_part.x3 = dual_x3; + product->dual_part.s = dual_s; + product->dual_part.x = dual_x; + product->dual_part.y = dual_y; + product->dual_part.z = dual_z; } inline void bgc_fp64_quaternion_multiply_by_dual_number(BGC_FP64_DualQuaternion* const product, const BGC_FP64_Quaternion* const multiplicand, const BGC_FP64_DualNumber* const multiplier) { - const double real_s0 = multiplicand->s0 * multiplier->real_part; - const double real_x1 = multiplicand->x1 * multiplier->real_part; - const double real_x2 = multiplicand->x2 * multiplier->real_part; - const double real_x3 = multiplicand->x3 * multiplier->real_part; + const double real_s = multiplicand->s * multiplier->real_part; + const double real_x = multiplicand->x * multiplier->real_part; + const double real_y = multiplicand->y * multiplier->real_part; + const double real_z = multiplicand->z * multiplier->real_part; - const double dual_s0 = multiplicand->s0 * multiplier->dual_part; - const double dual_x1 = multiplicand->x1 * multiplier->dual_part; - const double dual_x2 = multiplicand->x2 * multiplier->dual_part; - const double dual_x3 = multiplicand->x3 * multiplier->dual_part; + const double dual_s = multiplicand->s * multiplier->dual_part; + const double dual_x = multiplicand->x * multiplier->dual_part; + const double dual_y = multiplicand->y * multiplier->dual_part; + const double dual_z = multiplicand->z * multiplier->dual_part; - product->real_part.s0 = real_s0; - product->real_part.x1 = real_x1; - product->real_part.x2 = real_x2; - product->real_part.x3 = real_x3; + product->real_part.s = real_s; + product->real_part.x = real_x; + product->real_part.y = real_y; + product->real_part.z = real_z; - product->dual_part.s0 = dual_s0; - product->dual_part.x1 = dual_x1; - product->dual_part.x2 = dual_x2; - product->dual_part.x3 = dual_x3; + product->dual_part.s = dual_s; + product->dual_part.x = dual_x; + product->dual_part.y = dual_y; + product->dual_part.z = dual_z; } // ====== Restrict Multiply By Dual Number ====== // inline void _bgc_fp32_restrict_quaternion_multiply_by_dual_number(BGC_FP32_DualQuaternion* restrict const product, const BGC_FP32_Quaternion* const multiplicand, const BGC_FP32_DualNumber* const multiplier) { - product->real_part.s0 = multiplicand->s0 * multiplier->real_part; - product->real_part.x1 = multiplicand->x1 * multiplier->real_part; - product->real_part.x2 = multiplicand->x2 * multiplier->real_part; - product->real_part.x3 = multiplicand->x3 * multiplier->real_part; + product->real_part.s = multiplicand->s * multiplier->real_part; + product->real_part.x = multiplicand->x * multiplier->real_part; + product->real_part.y = multiplicand->y * multiplier->real_part; + product->real_part.z = multiplicand->z * multiplier->real_part; - product->dual_part.s0 = multiplicand->s0 * multiplier->dual_part; - product->dual_part.x1 = multiplicand->x1 * multiplier->dual_part; - product->dual_part.x2 = multiplicand->x2 * multiplier->dual_part; - product->dual_part.x3 = multiplicand->x3 * multiplier->dual_part; + product->dual_part.s = multiplicand->s * multiplier->dual_part; + product->dual_part.x = multiplicand->x * multiplier->dual_part; + product->dual_part.y = multiplicand->y * multiplier->dual_part; + product->dual_part.z = multiplicand->z * multiplier->dual_part; } inline void _bgc_fp64_restrict_quaternion_multiply_by_dual_number(BGC_FP64_DualQuaternion* restrict const product, const BGC_FP64_Quaternion* const multiplicand, const BGC_FP64_DualNumber* const multiplier) { - product->real_part.s0 = multiplicand->s0 * multiplier->real_part; - product->real_part.x1 = multiplicand->x1 * multiplier->real_part; - product->real_part.x2 = multiplicand->x2 * multiplier->real_part; - product->real_part.x3 = multiplicand->x3 * multiplier->real_part; + product->real_part.s = multiplicand->s * multiplier->real_part; + product->real_part.x = multiplicand->x * multiplier->real_part; + product->real_part.y = multiplicand->y * multiplier->real_part; + product->real_part.z = multiplicand->z * multiplier->real_part; - product->dual_part.s0 = multiplicand->s0 * multiplier->dual_part; - product->dual_part.x1 = multiplicand->x1 * multiplier->dual_part; - product->dual_part.x2 = multiplicand->x2 * multiplier->dual_part; - product->dual_part.x3 = multiplicand->x3 * multiplier->dual_part; + product->dual_part.s = multiplicand->s * multiplier->dual_part; + product->dual_part.x = multiplicand->x * multiplier->dual_part; + product->dual_part.y = multiplicand->y * multiplier->dual_part; + product->dual_part.z = multiplicand->z * multiplier->dual_part; } // =========== Multiply By Quaternion =========== // inline void bgc_fp32_quaternion_multiply_by_quaternion(BGC_FP32_Quaternion* const product, const BGC_FP32_Quaternion* const left, const BGC_FP32_Quaternion* const right) { - const float s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3); - const float x1 = (left->x1 * right->s0 + left->s0 * right->x1) - (left->x3 * right->x2 - left->x2 * right->x3); - const float x2 = (left->x2 * right->s0 + left->s0 * right->x2) - (left->x1 * right->x3 - left->x3 * right->x1); - const float x3 = (left->x3 * right->s0 + left->s0 * right->x3) - (left->x2 * right->x1 - left->x1 * right->x2); + const float s = (left->s * right->s - left->x * right->x) - (left->y * right->y + left->z * right->z); + const float x = (left->x * right->s + left->s * right->x) - (left->z * right->y - left->y * right->z); + const float y = (left->y * right->s + left->s * right->y) - (left->x * right->z - left->z * right->x); + const float z = (left->z * right->s + left->s * right->z) - (left->y * right->x - left->x * right->y); - product->s0 = s0; - product->x1 = x1; - product->x2 = x2; - product->x3 = x3; + product->s = s; + product->x = x; + product->y = y; + product->z = z; } inline void bgc_fp64_quaternion_multiply_by_quaternion(BGC_FP64_Quaternion* const product, const BGC_FP64_Quaternion* const left, const BGC_FP64_Quaternion* const right) { - const double s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3); - const double x1 = (left->x1 * right->s0 + left->s0 * right->x1) - (left->x3 * right->x2 - left->x2 * right->x3); - const double x2 = (left->x2 * right->s0 + left->s0 * right->x2) - (left->x1 * right->x3 - left->x3 * right->x1); - const double x3 = (left->x3 * right->s0 + left->s0 * right->x3) - (left->x2 * right->x1 - left->x1 * right->x2); + const double s = (left->s * right->s - left->x * right->x) - (left->y * right->y + left->z * right->z); + const double x = (left->x * right->s + left->s * right->x) - (left->z * right->y - left->y * right->z); + const double y = (left->y * right->s + left->s * right->y) - (left->x * right->z - left->z * right->x); + const double z = (left->z * right->s + left->s * right->z) - (left->y * right->x - left->x * right->y); - product->s0 = s0; - product->x1 = x1; - product->x2 = x2; - product->x3 = x3; + product->s = s; + product->x = x; + product->y = y; + product->z = z; } // ====== Multiply By Conjugate Quaternion ====== // inline void bgc_fp32_quaternion_multiply_by_conjugate(BGC_FP32_Quaternion* const product, const BGC_FP32_Quaternion* const left, const BGC_FP32_Quaternion* const right) { - const float s0 = (left->s0 * right->s0 + left->x1 * right->x1) + (left->x2 * right->x2 + left->x3 * right->x3); - const float x1 = (left->x1 * right->s0 + left->x3 * right->x2) - (left->s0 * right->x1 + left->x2 * right->x3); - const float x2 = (left->x2 * right->s0 + left->x1 * right->x3) - (left->s0 * right->x2 + left->x3 * right->x1); - const float x3 = (left->x3 * right->s0 + left->x2 * right->x1) - (left->s0 * right->x3 + left->x1 * right->x2); + const float s = (left->s * right->s + left->x * right->x) + (left->y * right->y + left->z * right->z); + const float x = (left->x * right->s + left->z * right->y) - (left->s * right->x + left->y * right->z); + const float y = (left->y * right->s + left->x * right->z) - (left->s * right->y + left->z * right->x); + const float z = (left->z * right->s + left->y * right->x) - (left->s * right->z + left->x * right->y); - product->s0 = s0; - product->x1 = x1; - product->x2 = x2; - product->x3 = x3; + product->s = s; + product->x = x; + product->y = y; + product->z = z; } inline void bgc_fp64_quaternion_multiply_by_conjugate(BGC_FP64_Quaternion* const product, const BGC_FP64_Quaternion* const left, const BGC_FP64_Quaternion* const right) { - const double s0 = (left->s0 * right->s0 + left->x1 * right->x1) + (left->x2 * right->x2 + left->x3 * right->x3); - const double x1 = (left->x1 * right->s0 + left->x3 * right->x2) - (left->s0 * right->x1 + left->x2 * right->x3); - const double x2 = (left->x2 * right->s0 + left->x1 * right->x3) - (left->s0 * right->x2 + left->x3 * right->x1); - const double x3 = (left->x3 * right->s0 + left->x2 * right->x1) - (left->s0 * right->x3 + left->x1 * right->x2); + const double s = (left->s * right->s + left->x * right->x) + (left->y * right->y + left->z * right->z); + const double x = (left->x * right->s + left->z * right->y) - (left->s * right->x + left->y * right->z); + const double y = (left->y * right->s + left->x * right->z) - (left->s * right->y + left->z * right->x); + const double z = (left->z * right->s + left->y * right->x) - (left->s * right->z + left->x * right->y); - product->s0 = s0; - product->x1 = x1; - product->x2 = x2; - product->x3 = x3; + product->s = s; + product->x = x; + product->y = y; + product->z = z; } // ====== Multiply Conjugate By Quaternion ====== // inline void bgc_fp32_conjugate_quaternion_multiply_by_quaternion(BGC_FP32_Quaternion* const product, const BGC_FP32_Quaternion* const left, const BGC_FP32_Quaternion* const right) { - const float s0 = (left->s0 * right->s0 + left->x1 * right->x1) + (left->x2 * right->x2 + left->x3 * right->x3); - const float x1 = (left->s0 * right->x1 - left->x1 * right->s0) + (left->x3 * right->x2 - left->x2 * right->x3); - const float x2 = (left->s0 * right->x2 - left->x2 * right->s0) + (left->x1 * right->x3 - left->x3 * right->x1); - const float x3 = (left->s0 * right->x3 - left->x3 * right->s0) + (left->x2 * right->x1 - left->x1 * right->x2); + const float s = (left->s * right->s + left->x * right->x) + (left->y * right->y + left->z * right->z); + const float x = (left->s * right->x - left->x * right->s) + (left->z * right->y - left->y * right->z); + const float y = (left->s * right->y - left->y * right->s) + (left->x * right->z - left->z * right->x); + const float z = (left->s * right->z - left->z * right->s) + (left->y * right->x - left->x * right->y); - product->s0 = s0; - product->x1 = x1; - product->x2 = x2; - product->x3 = x3; + product->s = s; + product->x = x; + product->y = y; + product->z = z; } inline void bgc_fp64_conjugate_quaternion_multiply_by_quaternion(BGC_FP64_Quaternion* const product, const BGC_FP64_Quaternion* const left, const BGC_FP64_Quaternion* const right) { - const double s0 = (left->s0 * right->s0 + left->x1 * right->x1) + (left->x2 * right->x2 + left->x3 * right->x3); - const double x1 = (left->s0 * right->x1 - left->x1 * right->s0) + (left->x3 * right->x2 - left->x2 * right->x3); - const double x2 = (left->s0 * right->x2 - left->x2 * right->s0) + (left->x1 * right->x3 - left->x3 * right->x1); - const double x3 = (left->s0 * right->x3 - left->x3 * right->s0) + (left->x2 * right->x1 - left->x1 * right->x2); + const double s = (left->s * right->s + left->x * right->x) + (left->y * right->y + left->z * right->z); + const double x = (left->s * right->x - left->x * right->s) + (left->z * right->y - left->y * right->z); + const double y = (left->s * right->y - left->y * right->s) + (left->x * right->z - left->z * right->x); + const double z = (left->s * right->z - left->z * right->s) + (left->y * right->x - left->x * right->y); - product->s0 = s0; - product->x1 = x1; - product->x2 = x2; - product->x3 = x3; + product->s = s; + product->x = x; + product->y = y; + product->z = z; } // ====== Multiply Conjugate By Conjugate ======= // inline void bgc_fp32_conjugate_quaternion_multiply_by_conjugate(BGC_FP32_Quaternion* const product, const BGC_FP32_Quaternion* const left, const BGC_FP32_Quaternion* const right) { - const float s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3); - const float x1 = (left->x2 * right->x3 - left->x3 * right->x2) - (left->x1 * right->s0 + left->s0 * right->x1); - const float x2 = (left->x3 * right->x1 - left->x1 * right->x3) - (left->x2 * right->s0 + left->s0 * right->x2); - const float x3 = (left->x1 * right->x2 - left->x2 * right->x1) - (left->x3 * right->s0 + left->s0 * right->x3); + const float s = (left->s * right->s - left->x * right->x) - (left->y * right->y + left->z * right->z); + const float x = (left->y * right->z - left->z * right->y) - (left->x * right->s + left->s * right->x); + const float y = (left->z * right->x - left->x * right->z) - (left->y * right->s + left->s * right->y); + const float z = (left->x * right->y - left->y * right->x) - (left->z * right->s + left->s * right->z); - product->s0 = s0; - product->x1 = x1; - product->x2 = x2; - product->x3 = x3; + product->s = s; + product->x = x; + product->y = y; + product->z = z; } inline void bgc_fp64_conjugate_quaternion_multiply_by_conjugate(BGC_FP64_Quaternion* const product, const BGC_FP64_Quaternion* const left, const BGC_FP64_Quaternion* const right) { - const double s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3); - const double x1 = (left->x2 * right->x3 - left->x3 * right->x2) - (left->x1 * right->s0 + left->s0 * right->x1); - const double x2 = (left->x3 * right->x1 - left->x1 * right->x3) - (left->x2 * right->s0 + left->s0 * right->x2); - const double x3 = (left->x1 * right->x2 - left->x2 * right->x1) - (left->x3 * right->s0 + left->s0 * right->x3); + const double s = (left->s * right->s - left->x * right->x) - (left->y * right->y + left->z * right->z); + const double x = (left->y * right->z - left->z * right->y) - (left->x * right->s + left->s * right->x); + const double y = (left->z * right->x - left->x * right->z) - (left->y * right->s + left->s * right->y); + const double z = (left->x * right->y - left->y * right->x) - (left->z * right->s + left->s * right->z); - product->s0 = s0; - product->x1 = x1; - product->x2 = x2; - product->x3 = x3; + product->s = s; + product->x = x; + product->y = y; + product->z = z; } // ====== Restrict Multiply By Quaternion ======= // inline void _bgc_fp32_restrict_quaternion_multiply_by_quaternion(BGC_FP32_Quaternion* restrict const product, const BGC_FP32_Quaternion* const left, const BGC_FP32_Quaternion* const right) { - product->s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3); - product->x1 = (left->x1 * right->s0 + left->s0 * right->x1) - (left->x3 * right->x2 - left->x2 * right->x3); - product->x2 = (left->x2 * right->s0 + left->s0 * right->x2) - (left->x1 * right->x3 - left->x3 * right->x1); - product->x3 = (left->x3 * right->s0 + left->s0 * right->x3) - (left->x2 * right->x1 - left->x1 * right->x2); + product->s = (left->s * right->s - left->x * right->x) - (left->y * right->y + left->z * right->z); + product->x = (left->x * right->s + left->s * right->x) - (left->z * right->y - left->y * right->z); + product->y = (left->y * right->s + left->s * right->y) - (left->x * right->z - left->z * right->x); + product->z = (left->z * right->s + left->s * right->z) - (left->y * right->x - left->x * right->y); } inline void _bgc_fp64_restrict_quaternion_multiply_by_quaternion(BGC_FP64_Quaternion* restrict const product, const BGC_FP64_Quaternion* const left, const BGC_FP64_Quaternion* const right) { - product->s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3); - product->x1 = (left->x1 * right->s0 + left->s0 * right->x1) - (left->x3 * right->x2 - left->x2 * right->x3); - product->x2 = (left->x2 * right->s0 + left->s0 * right->x2) - (left->x1 * right->x3 - left->x3 * right->x1); - product->x3 = (left->x3 * right->s0 + left->s0 * right->x3) - (left->x2 * right->x1 - left->x1 * right->x2); + product->s = (left->s * right->s - left->x * right->x) - (left->y * right->y + left->z * right->z); + product->x = (left->x * right->s + left->s * right->x) - (left->z * right->y - left->y * right->z); + product->y = (left->y * right->s + left->s * right->y) - (left->x * right->z - left->z * right->x); + product->z = (left->z * right->s + left->s * right->z) - (left->y * right->x - left->x * right->y); } // = Restrict Multiply By Conjugate Quaternion == // inline void _bgc_fp32_restrict_quaternion_multiply_by_conjugate(BGC_FP32_Quaternion* restrict const product, const BGC_FP32_Quaternion* const left, const BGC_FP32_Quaternion* const right) { - product->s0 = (left->s0 * right->s0 + left->x1 * right->x1) + (left->x2 * right->x2 + left->x3 * right->x3); - product->x1 = (left->x1 * right->s0 + left->x3 * right->x2) - (left->s0 * right->x1 + left->x2 * right->x3); - product->x2 = (left->x2 * right->s0 + left->x1 * right->x3) - (left->s0 * right->x2 + left->x3 * right->x1); - product->x3 = (left->x3 * right->s0 + left->x2 * right->x1) - (left->s0 * right->x3 + left->x1 * right->x2); + product->s = (left->s * right->s + left->x * right->x) + (left->y * right->y + left->z * right->z); + product->x = (left->x * right->s + left->z * right->y) - (left->s * right->x + left->y * right->z); + product->y = (left->y * right->s + left->x * right->z) - (left->s * right->y + left->z * right->x); + product->z = (left->z * right->s + left->y * right->x) - (left->s * right->z + left->x * right->y); } inline void _bgc_fp64_restrict_quaternion_multiply_by_conjugate(BGC_FP64_Quaternion* restrict const product, const BGC_FP64_Quaternion* const left, const BGC_FP64_Quaternion* const right) { - product->s0 = (left->s0 * right->s0 + left->x1 * right->x1) + (left->x2 * right->x2 + left->x3 * right->x3); - product->x1 = (left->x1 * right->s0 + left->x3 * right->x2) - (left->s0 * right->x1 + left->x2 * right->x3); - product->x2 = (left->x2 * right->s0 + left->x1 * right->x3) - (left->s0 * right->x2 + left->x3 * right->x1); - product->x3 = (left->x3 * right->s0 + left->x2 * right->x1) - (left->s0 * right->x3 + left->x1 * right->x2); + product->s = (left->s * right->s + left->x * right->x) + (left->y * right->y + left->z * right->z); + product->x = (left->x * right->s + left->z * right->y) - (left->s * right->x + left->y * right->z); + product->y = (left->y * right->s + left->x * right->z) - (left->s * right->y + left->z * right->x); + product->z = (left->z * right->s + left->y * right->x) - (left->s * right->z + left->x * right->y); } // ======== Multiply By Dual Quaternion ========= // @@ -624,36 +624,36 @@ inline int bgc_fp64_quaternion_divide_by_conjugate(BGC_FP64_Quaternion* const qu inline void bgc_fp32_quaternion_get_mean2(BGC_FP32_Quaternion* const mean, const BGC_FP32_Quaternion* const quaternion1, const BGC_FP32_Quaternion* const quaternion2) { - mean->s0 = (quaternion1->s0 + quaternion2->s0) * 0.5f; - mean->x1 = (quaternion1->x1 + quaternion2->x1) * 0.5f; - mean->x2 = (quaternion1->x2 + quaternion2->x2) * 0.5f; - mean->x3 = (quaternion1->x3 + quaternion2->x3) * 0.5f; + mean->s = (quaternion1->s + quaternion2->s) * 0.5f; + mean->x = (quaternion1->x + quaternion2->x) * 0.5f; + mean->y = (quaternion1->y + quaternion2->y) * 0.5f; + mean->z = (quaternion1->z + quaternion2->z) * 0.5f; } inline void bgc_fp64_quaternion_get_mean2(BGC_FP64_Quaternion* const mean, const BGC_FP64_Quaternion* const quaternion1, const BGC_FP64_Quaternion* const quaternion2) { - mean->s0 = (quaternion1->s0 + quaternion2->s0) * 0.5f; - mean->x1 = (quaternion1->x1 + quaternion2->x1) * 0.5f; - mean->x2 = (quaternion1->x2 + quaternion2->x2) * 0.5f; - mean->x3 = (quaternion1->x3 + quaternion2->x3) * 0.5f; + mean->s = (quaternion1->s + quaternion2->s) * 0.5f; + mean->x = (quaternion1->x + quaternion2->x) * 0.5f; + mean->y = (quaternion1->y + quaternion2->y) * 0.5f; + mean->z = (quaternion1->z + quaternion2->z) * 0.5f; } // =============== Mean of Three ================ // inline void bgc_fp32_quaternion_get_mean3(BGC_FP32_Quaternion* const mean, const BGC_FP32_Quaternion* const quaternion1, const BGC_FP32_Quaternion* const quaternion2, const BGC_FP32_Quaternion* const quaternion3) { - mean->s0 = (quaternion1->s0 + quaternion2->s0 + quaternion3->s0) * BGC_FP32_ONE_THIRD; - mean->x1 = (quaternion1->x1 + quaternion2->x1 + quaternion3->x1) * BGC_FP32_ONE_THIRD; - mean->x2 = (quaternion1->x2 + quaternion2->x2 + quaternion3->x2) * BGC_FP32_ONE_THIRD; - mean->x3 = (quaternion1->x3 + quaternion2->x3 + quaternion3->x3) * BGC_FP32_ONE_THIRD; + mean->s = (quaternion1->s + quaternion2->s + quaternion3->s) * BGC_FP32_ONE_THIRD; + mean->x = (quaternion1->x + quaternion2->x + quaternion3->x) * BGC_FP32_ONE_THIRD; + mean->y = (quaternion1->y + quaternion2->y + quaternion3->y) * BGC_FP32_ONE_THIRD; + mean->z = (quaternion1->z + quaternion2->z + quaternion3->z) * BGC_FP32_ONE_THIRD; } inline void bgc_fp64_quaternion_get_mean3(BGC_FP64_Quaternion* const mean, const BGC_FP64_Quaternion* const quaternion1, const BGC_FP64_Quaternion* const quaternion2, const BGC_FP64_Quaternion* const quaternion3) { - mean->s0 = (quaternion1->s0 + quaternion2->s0 + quaternion3->s0) * BGC_FP64_ONE_THIRD; - mean->x1 = (quaternion1->x1 + quaternion2->x1 + quaternion3->x1) * BGC_FP64_ONE_THIRD; - mean->x2 = (quaternion1->x2 + quaternion2->x2 + quaternion3->x2) * BGC_FP64_ONE_THIRD; - mean->x3 = (quaternion1->x3 + quaternion2->x3 + quaternion3->x3) * BGC_FP64_ONE_THIRD; + mean->s = (quaternion1->s + quaternion2->s + quaternion3->s) * BGC_FP64_ONE_THIRD; + mean->x = (quaternion1->x + quaternion2->x + quaternion3->x) * BGC_FP64_ONE_THIRD; + mean->y = (quaternion1->y + quaternion2->y + quaternion3->y) * BGC_FP64_ONE_THIRD; + mean->z = (quaternion1->z + quaternion2->z + quaternion3->z) * BGC_FP64_ONE_THIRD; } // ============ Linear Interpolation ============ // @@ -662,98 +662,98 @@ inline void bgc_fp32_quaternion_interpolate(BGC_FP32_Quaternion* const interpola { const float counter_phase = 1.0f - phase; - interpolation->s0 = quaternion1->s0 * counter_phase + quaternion2->s0 * phase; - interpolation->x1 = quaternion1->x1 * counter_phase + quaternion2->x1 * phase; - interpolation->x2 = quaternion1->x2 * counter_phase + quaternion2->x2 * phase; - interpolation->x3 = quaternion1->x3 * counter_phase + quaternion2->x3 * phase; + interpolation->s = quaternion1->s * counter_phase + quaternion2->s * phase; + interpolation->x = quaternion1->x * counter_phase + quaternion2->x * phase; + interpolation->y = quaternion1->y * counter_phase + quaternion2->y * phase; + interpolation->z = quaternion1->z * counter_phase + quaternion2->z * phase; } inline void bgc_fp64_quaternion_interpolate(BGC_FP64_Quaternion* const interpolation, const BGC_FP64_Quaternion* const quaternion1, const BGC_FP64_Quaternion* const quaternion2, const double phase) { const double counter_phase = 1.0 - phase; - interpolation->s0 = quaternion1->s0 * counter_phase + quaternion2->s0 * phase; - interpolation->x1 = quaternion1->x1 * counter_phase + quaternion2->x1 * phase; - interpolation->x2 = quaternion1->x2 * counter_phase + quaternion2->x2 * phase; - interpolation->x3 = quaternion1->x3 * counter_phase + quaternion2->x3 * phase; + interpolation->s = quaternion1->s * counter_phase + quaternion2->s * phase; + interpolation->x = quaternion1->x * counter_phase + quaternion2->x * phase; + interpolation->y = quaternion1->y * counter_phase + quaternion2->y * phase; + interpolation->z = quaternion1->z * counter_phase + quaternion2->z * phase; } // ============== Get Dot Product =============== // inline float bgc_fp32_quaternion_get_dot_product(const BGC_FP32_Quaternion* const quaternion1, const BGC_FP32_Quaternion* const quaternion2) { - return (quaternion1->s0 * quaternion2->s0 + quaternion1->x1 * quaternion2->x1) + (quaternion1->x2 * quaternion2->x2 + quaternion1->x3 * quaternion2->x3); + return (quaternion1->s * quaternion2->s + quaternion1->x * quaternion2->x) + (quaternion1->y * quaternion2->y + quaternion1->z * quaternion2->z); } inline double bgc_fp64_quaternion_get_dot_product(const BGC_FP64_Quaternion* const quaternion1, const BGC_FP64_Quaternion* const quaternion2) { - return (quaternion1->s0 * quaternion2->s0 + quaternion1->x1 * quaternion2->x1) + (quaternion1->x2 * quaternion2->x2 + quaternion1->x3 * quaternion2->x3); + return (quaternion1->s * quaternion2->s + quaternion1->x * quaternion2->x) + (quaternion1->y * quaternion2->y + quaternion1->z * quaternion2->z); } // ================= Conjugate ================== // inline void bgc_fp32_quaternion_conjugate(BGC_FP32_Quaternion* const quaternion) { - quaternion->x1 = -quaternion->x1; - quaternion->x2 = -quaternion->x2; - quaternion->x3 = -quaternion->x3; + quaternion->x = -quaternion->x; + quaternion->y = -quaternion->y; + quaternion->z = -quaternion->z; } inline void bgc_fp64_quaternion_conjugate(BGC_FP64_Quaternion* const quaternion) { - quaternion->x1 = -quaternion->x1; - quaternion->x2 = -quaternion->x2; - quaternion->x3 = -quaternion->x3; + quaternion->x = -quaternion->x; + quaternion->y = -quaternion->y; + quaternion->z = -quaternion->z; } inline void bgc_fp32_quaternion_get_conjugate(BGC_FP32_Quaternion* const conjugate, const BGC_FP32_Quaternion* const quaternion) { - conjugate->s0 = quaternion->s0; - conjugate->x1 = -quaternion->x1; - conjugate->x2 = -quaternion->x2; - conjugate->x3 = -quaternion->x3; + conjugate->s = quaternion->s; + conjugate->x = -quaternion->x; + conjugate->y = -quaternion->y; + conjugate->z = -quaternion->z; } inline void bgc_fp64_quaternion_get_conjugate(BGC_FP64_Quaternion* const conjugate, const BGC_FP64_Quaternion* const quaternion) { - conjugate->s0 = quaternion->s0; - conjugate->x1 = -quaternion->x1; - conjugate->x2 = -quaternion->x2; - conjugate->x3 = -quaternion->x3; + conjugate->s = quaternion->s; + conjugate->x = -quaternion->x; + conjugate->y = -quaternion->y; + conjugate->z = -quaternion->z; } // ================== Negative ================== // inline void bgc_fp32_quaternion_revert(BGC_FP32_Quaternion* const quaternion) { - quaternion->s0 = -quaternion->s0; - quaternion->x1 = -quaternion->x1; - quaternion->x2 = -quaternion->x2; - quaternion->x3 = -quaternion->x3; + quaternion->s = -quaternion->s; + quaternion->x = -quaternion->x; + quaternion->y = -quaternion->y; + quaternion->z = -quaternion->z; } inline void bgc_fp64_quaternion_revert(BGC_FP64_Quaternion* const quaternion) { - quaternion->s0 = -quaternion->s0; - quaternion->x1 = -quaternion->x1; - quaternion->x2 = -quaternion->x2; - quaternion->x3 = -quaternion->x3; + quaternion->s = -quaternion->s; + quaternion->x = -quaternion->x; + quaternion->y = -quaternion->y; + quaternion->z = -quaternion->z; } inline void bgc_fp32_quaternion_get_reverse(BGC_FP32_Quaternion* const reverse, const BGC_FP32_Quaternion* const quaternion) { - reverse->s0 = -quaternion->s0; - reverse->x1 = -quaternion->x1; - reverse->x2 = -quaternion->x2; - reverse->x3 = -quaternion->x3; + reverse->s = -quaternion->s; + reverse->x = -quaternion->x; + reverse->y = -quaternion->y; + reverse->z = -quaternion->z; } inline void bgc_fp64_quaternion_get_reverse(BGC_FP64_Quaternion* const reverse, const BGC_FP64_Quaternion* const quaternion) { - reverse->s0 = -quaternion->s0; - reverse->x1 = -quaternion->x1; - reverse->x2 = -quaternion->x2; - reverse->x3 = -quaternion->x3; + reverse->s = -quaternion->s; + reverse->x = -quaternion->x; + reverse->y = -quaternion->y; + reverse->z = -quaternion->z; } // =================== Invert =================== // @@ -768,10 +768,10 @@ inline int bgc_fp32_quaternion_get_inverse(BGC_FP32_Quaternion* const inverse, c const float multiplicand = 1.0f / square_modulus; - inverse->s0 = quaternion->s0 * multiplicand; - inverse->x1 = -quaternion->x1 * multiplicand; - inverse->x2 = -quaternion->x2 * multiplicand; - inverse->x3 = -quaternion->x3 * multiplicand; + inverse->s = quaternion->s * multiplicand; + inverse->x = -quaternion->x * multiplicand; + inverse->y = -quaternion->y * multiplicand; + inverse->z = -quaternion->z * multiplicand; return BGC_SUCCESS; } @@ -786,10 +786,10 @@ inline int bgc_fp64_quaternion_get_inverse(BGC_FP64_Quaternion* const inverse, c const double multiplicand = 1.0 / square_modulus; - inverse->s0 = quaternion->s0 * multiplicand; - inverse->x1 = -quaternion->x1 * multiplicand; - inverse->x2 = -quaternion->x2 * multiplicand; - inverse->x3 = -quaternion->x3 * multiplicand; + inverse->s = quaternion->s * multiplicand; + inverse->x = -quaternion->x * multiplicand; + inverse->y = -quaternion->y * multiplicand; + inverse->z = -quaternion->z * multiplicand; return BGC_SUCCESS; } @@ -820,10 +820,10 @@ inline int bgc_fp32_quaternion_normalize(BGC_FP32_Quaternion* const quaternion) const float multiplier = sqrtf(1.0f / square_modulus); - quaternion->s0 *= multiplier; - quaternion->x1 *= multiplier; - quaternion->x2 *= multiplier; - quaternion->x3 *= multiplier; + quaternion->s *= multiplier; + quaternion->x *= multiplier; + quaternion->y *= multiplier; + quaternion->z *= multiplier; return BGC_SUCCESS; } @@ -842,10 +842,10 @@ inline int bgc_fp64_quaternion_normalize(BGC_FP64_Quaternion* const quaternion) const double multiplier = sqrt(1.0 / square_modulus); - quaternion->s0 *= multiplier; - quaternion->x1 *= multiplier; - quaternion->x2 *= multiplier; - quaternion->x3 *= multiplier; + quaternion->s *= multiplier; + quaternion->x *= multiplier; + quaternion->y *= multiplier; + quaternion->z *= multiplier; return BGC_SUCCESS; } @@ -897,33 +897,33 @@ int bgc_fp64_quaternion_get_power(BGC_FP64_Quaternion* const power, const BGC_FP // An internal function inline void _bgc_fp32_versor_turn_vector(BGC_FP32_Vector3* const turned_vector, const BGC_FP32_Quaternion* const quaternion, const BGC_FP32_Vector3* const original_vector) { - const float tx1 = 2.0f * (quaternion->x2 * original_vector->x3 - quaternion->x3 * original_vector->x2); - const float tx2 = 2.0f * (quaternion->x3 * original_vector->x1 - quaternion->x1 * original_vector->x3); - const float tx3 = 2.0f * (quaternion->x1 * original_vector->x2 - quaternion->x2 * original_vector->x1); + const float tx = 2.0f * (quaternion->y * original_vector->z - quaternion->z * original_vector->y); + const float ty = 2.0f * (quaternion->z * original_vector->x - quaternion->x * original_vector->z); + const float tz = 2.0f * (quaternion->x * original_vector->y - quaternion->y * original_vector->x); - const float x1 = (original_vector->x1 + tx1 * quaternion->s0) + (quaternion->x2 * tx3 - quaternion->x3 * tx2); - const float x2 = (original_vector->x2 + tx2 * quaternion->s0) + (quaternion->x3 * tx1 - quaternion->x1 * tx3); - const float x3 = (original_vector->x3 + tx3 * quaternion->s0) + (quaternion->x1 * tx2 - quaternion->x2 * tx1); + const float x = (original_vector->x + tx * quaternion->s) + (quaternion->y * tz - quaternion->z * ty); + const float y = (original_vector->y + ty * quaternion->s) + (quaternion->z * tx - quaternion->x * tz); + const float z = (original_vector->z + tz * quaternion->s) + (quaternion->x * ty - quaternion->y * tx); - turned_vector->x1 = x1; - turned_vector->x2 = x2; - turned_vector->x3 = x3; + turned_vector->x = x; + turned_vector->y = y; + turned_vector->z = z; } // An internal function inline void _bgc_fp64_versor_turn_vector(BGC_FP64_Vector3* const turned_vector, const BGC_FP64_Quaternion* const quaternion, const BGC_FP64_Vector3* const original_vector) { - const double tx1 = 2.0f * (quaternion->x2 * original_vector->x3 - quaternion->x3 * original_vector->x2); - const double tx2 = 2.0f * (quaternion->x3 * original_vector->x1 - quaternion->x1 * original_vector->x3); - const double tx3 = 2.0f * (quaternion->x1 * original_vector->x2 - quaternion->x2 * original_vector->x1); + const double tx = 2.0f * (quaternion->y * original_vector->z - quaternion->z * original_vector->y); + const double ty = 2.0f * (quaternion->z * original_vector->x - quaternion->x * original_vector->z); + const double tz = 2.0f * (quaternion->x * original_vector->y - quaternion->y * original_vector->x); - const double x1 = (original_vector->x1 + tx1 * quaternion->s0) + (quaternion->x2 * tx3 - quaternion->x3 * tx2); - const double x2 = (original_vector->x2 + tx2 * quaternion->s0) + (quaternion->x3 * tx1 - quaternion->x1 * tx3); - const double x3 = (original_vector->x3 + tx3 * quaternion->s0) + (quaternion->x1 * tx2 - quaternion->x2 * tx1); + const double x = (original_vector->x + tx * quaternion->s) + (quaternion->y * tz - quaternion->z * ty); + const double y = (original_vector->y + ty * quaternion->s) + (quaternion->z * tx - quaternion->x * tz); + const double z = (original_vector->z + tz * quaternion->s) + (quaternion->x * ty - quaternion->y * tx); - turned_vector->x1 = x1; - turned_vector->x2 = x2; - turned_vector->x3 = x3; + turned_vector->x = x; + turned_vector->y = y; + turned_vector->z = z; } // ========= Raw Turn Vector3 Backwards ========= // @@ -931,33 +931,33 @@ inline void _bgc_fp64_versor_turn_vector(BGC_FP64_Vector3* const turned_vector, // An internal function inline void _bgc_fp32_versor_turn_vector_back(BGC_FP32_Vector3* const turned_vector, const BGC_FP32_Quaternion* const quaternion, const BGC_FP32_Vector3* const original_vector) { - const float tx1 = 2.0f * (quaternion->x2 * original_vector->x3 - quaternion->x3 * original_vector->x2); - const float tx2 = 2.0f * (quaternion->x3 * original_vector->x1 - quaternion->x1 * original_vector->x3); - const float tx3 = 2.0f * (quaternion->x1 * original_vector->x2 - quaternion->x2 * original_vector->x1); + const float tx = 2.0f * (quaternion->y * original_vector->z - quaternion->z * original_vector->y); + const float ty = 2.0f * (quaternion->z * original_vector->x - quaternion->x * original_vector->z); + const float tz = 2.0f * (quaternion->x * original_vector->y - quaternion->y * original_vector->x); - const float x1 = (original_vector->x1 + tx1 * quaternion->s0) + (quaternion->x2 * tx3 - quaternion->x3 * tx2); - const float x2 = (original_vector->x2 + tx2 * quaternion->s0) + (quaternion->x3 * tx1 - quaternion->x1 * tx3); - const float x3 = (original_vector->x3 + tx3 * quaternion->s0) + (quaternion->x1 * tx2 - quaternion->x2 * tx1); + const float x = (original_vector->x + tx * quaternion->s) + (quaternion->y * tz - quaternion->z * ty); + const float y = (original_vector->y + ty * quaternion->s) + (quaternion->z * tx - quaternion->x * tz); + const float z = (original_vector->z + tz * quaternion->s) + (quaternion->x * ty - quaternion->y * tx); - turned_vector->x1 = x1; - turned_vector->x2 = x2; - turned_vector->x3 = x3; + turned_vector->x = x; + turned_vector->y = y; + turned_vector->z = z; } // An internal function inline void _bgc_fp64_versor_turn_vector_back(BGC_FP64_Vector3* const turned_vector, const BGC_FP64_Quaternion* const quaternion, const BGC_FP64_Vector3* const original_vector) { - const double tx1 = 2.0f * (quaternion->x2 * original_vector->x3 - quaternion->x3 * original_vector->x2); - const double tx2 = 2.0f * (quaternion->x3 * original_vector->x1 - quaternion->x1 * original_vector->x3); - const double tx3 = 2.0f * (quaternion->x1 * original_vector->x2 - quaternion->x2 * original_vector->x1); + const double tx = 2.0f * (quaternion->y * original_vector->z - quaternion->z * original_vector->y); + const double ty = 2.0f * (quaternion->z * original_vector->x - quaternion->x * original_vector->z); + const double tz = 2.0f * (quaternion->x * original_vector->y - quaternion->y * original_vector->x); - const double x1 = (original_vector->x1 + tx1 * quaternion->s0) + (quaternion->x2 * tx3 - quaternion->x3 * tx2); - const double x2 = (original_vector->x2 + tx2 * quaternion->s0) + (quaternion->x3 * tx1 - quaternion->x1 * tx3); - const double x3 = (original_vector->x3 + tx3 * quaternion->s0) + (quaternion->x1 * tx2 - quaternion->x2 * tx1); + const double x = (original_vector->x + tx * quaternion->s) + (quaternion->y * tz - quaternion->z * ty); + const double y = (original_vector->y + ty * quaternion->s) + (quaternion->z * tx - quaternion->x * tz); + const double z = (original_vector->z + tz * quaternion->s) + (quaternion->x * ty - quaternion->y * tx); - turned_vector->x1 = x1; - turned_vector->x2 = x2; - turned_vector->x3 = x3; + turned_vector->x = x; + turned_vector->y = y; + turned_vector->z = z; } // ================ Turn Vector3 ================ // @@ -972,17 +972,17 @@ inline int bgc_fp32_quaternion_turn_vector(BGC_FP32_Vector3* const turned_vector const float multiplier = 2.0f / square_modulus; - const float tx1 = multiplier * (quaternion->x2 * original_vector->x3 - quaternion->x3 * original_vector->x2); - const float tx2 = multiplier * (quaternion->x3 * original_vector->x1 - quaternion->x1 * original_vector->x3); - const float tx3 = multiplier * (quaternion->x1 * original_vector->x2 - quaternion->x2 * original_vector->x1); + const float tx = multiplier * (quaternion->y * original_vector->z - quaternion->z * original_vector->y); + const float ty = multiplier * (quaternion->z * original_vector->x - quaternion->x * original_vector->z); + const float tz = multiplier * (quaternion->x * original_vector->y - quaternion->y * original_vector->x); - const float x1 = (original_vector->x1 + tx1 * quaternion->s0) + (quaternion->x2 * tx3 - quaternion->x3 * tx2); - const float x2 = (original_vector->x2 + tx2 * quaternion->s0) + (quaternion->x3 * tx1 - quaternion->x1 * tx3); - const float x3 = (original_vector->x3 + tx3 * quaternion->s0) + (quaternion->x1 * tx2 - quaternion->x2 * tx1); + const float x = (original_vector->x + tx * quaternion->s) + (quaternion->y * tz - quaternion->z * ty); + const float y = (original_vector->y + ty * quaternion->s) + (quaternion->z * tx - quaternion->x * tz); + const float z = (original_vector->z + tz * quaternion->s) + (quaternion->x * ty - quaternion->y * tx); - turned_vector->x1 = x1; - turned_vector->x2 = x2; - turned_vector->x3 = x3; + turned_vector->x = x; + turned_vector->y = y; + turned_vector->z = z; return BGC_SUCCESS; @@ -998,17 +998,17 @@ inline int bgc_fp64_quaternion_turn_vector(BGC_FP64_Vector3* const turned_vector const double multiplier = 2.0 / square_modulus; - const double tx1 = multiplier * (quaternion->x2 * original_vector->x3 - quaternion->x3 * original_vector->x2); - const double tx2 = multiplier * (quaternion->x3 * original_vector->x1 - quaternion->x1 * original_vector->x3); - const double tx3 = multiplier * (quaternion->x1 * original_vector->x2 - quaternion->x2 * original_vector->x1); + const double tx = multiplier * (quaternion->y * original_vector->z - quaternion->z * original_vector->y); + const double ty = multiplier * (quaternion->z * original_vector->x - quaternion->x * original_vector->z); + const double tz = multiplier * (quaternion->x * original_vector->y - quaternion->y * original_vector->x); - const double x1 = (original_vector->x1 + tx1 * quaternion->s0) + (quaternion->x2 * tx3 - quaternion->x3 * tx2); - const double x2 = (original_vector->x2 + tx2 * quaternion->s0) + (quaternion->x3 * tx1 - quaternion->x1 * tx3); - const double x3 = (original_vector->x3 + tx3 * quaternion->s0) + (quaternion->x1 * tx2 - quaternion->x2 * tx1); + const double x = (original_vector->x + tx * quaternion->s) + (quaternion->y * tz - quaternion->z * ty); + const double y = (original_vector->y + ty * quaternion->s) + (quaternion->z * tx - quaternion->x * tz); + const double z = (original_vector->z + tz * quaternion->s) + (quaternion->x * ty - quaternion->y * tx); - turned_vector->x1 = x1; - turned_vector->x2 = x2; - turned_vector->x3 = x3; + turned_vector->x = x; + turned_vector->y = y; + turned_vector->z = z; return BGC_SUCCESS; @@ -1026,17 +1026,17 @@ inline int bgc_fp32_quaternion_turn_vector_back(BGC_FP32_Vector3* const turned_v const float multiplier = 2.0f / square_modulus; - const float tx1 = multiplier * (quaternion->x2 * original_vector->x3 - quaternion->x3 * original_vector->x2); - const float tx2 = multiplier * (quaternion->x3 * original_vector->x1 - quaternion->x1 * original_vector->x3); - const float tx3 = multiplier * (quaternion->x1 * original_vector->x2 - quaternion->x2 * original_vector->x1); + const float tx = multiplier * (quaternion->y * original_vector->z - quaternion->z * original_vector->y); + const float ty = multiplier * (quaternion->z * original_vector->x - quaternion->x * original_vector->z); + const float tz = multiplier * (quaternion->x * original_vector->y - quaternion->y * original_vector->x); - const float x1 = (original_vector->x1 - tx1 * quaternion->s0) + (quaternion->x2 * tx3 - quaternion->x3 * tx2); - const float x2 = (original_vector->x2 - tx2 * quaternion->s0) + (quaternion->x3 * tx1 - quaternion->x1 * tx3); - const float x3 = (original_vector->x3 - tx3 * quaternion->s0) + (quaternion->x1 * tx2 - quaternion->x2 * tx1); + const float x = (original_vector->x - tx * quaternion->s) + (quaternion->y * tz - quaternion->z * ty); + const float y = (original_vector->y - ty * quaternion->s) + (quaternion->z * tx - quaternion->x * tz); + const float z = (original_vector->z - tz * quaternion->s) + (quaternion->x * ty - quaternion->y * tx); - turned_vector->x1 = x1; - turned_vector->x2 = x2; - turned_vector->x3 = x3; + turned_vector->x = x; + turned_vector->y = y; + turned_vector->z = z; return BGC_SUCCESS; @@ -1052,17 +1052,17 @@ inline int bgc_fp64_quaternion_turn_vector_back(BGC_FP64_Vector3* const turned_v const double multiplier = 2.0 / square_modulus; - const double tx1 = multiplier * (quaternion->x2 * original_vector->x3 - quaternion->x3 * original_vector->x2); - const double tx2 = multiplier * (quaternion->x3 * original_vector->x1 - quaternion->x1 * original_vector->x3); - const double tx3 = multiplier * (quaternion->x1 * original_vector->x2 - quaternion->x2 * original_vector->x1); + const double tx = multiplier * (quaternion->y * original_vector->z - quaternion->z * original_vector->y); + const double ty = multiplier * (quaternion->z * original_vector->x - quaternion->x * original_vector->z); + const double tz = multiplier * (quaternion->x * original_vector->y - quaternion->y * original_vector->x); - const double x1 = (original_vector->x1 - tx1 * quaternion->s0) + (quaternion->x2 * tx3 - quaternion->x3 * tx2); - const double x2 = (original_vector->x2 - tx2 * quaternion->s0) + (quaternion->x3 * tx1 - quaternion->x1 * tx3); - const double x3 = (original_vector->x3 - tx3 * quaternion->s0) + (quaternion->x1 * tx2 - quaternion->x2 * tx1); + const double x = (original_vector->x - tx * quaternion->s) + (quaternion->y * tz - quaternion->z * ty); + const double y = (original_vector->y - ty * quaternion->s) + (quaternion->z * tx - quaternion->x * tz); + const double z = (original_vector->z - tz * quaternion->s) + (quaternion->x * ty - quaternion->y * tx); - turned_vector->x1 = x1; - turned_vector->x2 = x2; - turned_vector->x3 = x3; + turned_vector->x = x; + turned_vector->y = y; + turned_vector->z = z; return BGC_SUCCESS; @@ -1072,132 +1072,132 @@ inline int bgc_fp64_quaternion_turn_vector_back(BGC_FP64_Vector3* const turned_v inline void _bgc_fp32_versor_get_rotation_matrix(BGC_FP32_Matrix3x3* const matrix, const BGC_FP32_Quaternion* const versor) { - const float s0s0 = versor->s0 * versor->s0; - const float x1x1 = versor->x1 * versor->x1; - const float x2x2 = versor->x2 * versor->x2; - const float x3x3 = versor->x3 * versor->x3; + const float ss = versor->s * versor->s; + const float xx = versor->x * versor->x; + const float yy = versor->y * versor->y; + const float zz = versor->z * versor->z; - const float s0x1 = versor->s0 * versor->x1; - const float s0x2 = versor->s0 * versor->x2; - const float s0x3 = versor->s0 * versor->x3; + const float sx = versor->s * versor->x; + const float sy = versor->s * versor->y; + const float sz = versor->s * versor->z; - const float x1x2 = versor->x1 * versor->x2; - const float x1x3 = versor->x1 * versor->x3; + const float xy = versor->x * versor->y; + const float xz = versor->x * versor->z; - const float x2x3 = versor->x2 * versor->x3; + const float yz = versor->y * versor->z; - matrix->r1c1 = ((s0s0 + x1x1) - (x2x2 + x3x3)); - matrix->r2c2 = ((s0s0 + x2x2) - (x1x1 + x3x3)); - matrix->r3c3 = ((s0s0 + x3x3) - (x1x1 + x2x2)); + matrix->r1c1 = ((ss + xx) - (yy + zz)); + matrix->r2c2 = ((ss + yy) - (xx + zz)); + matrix->r3c3 = ((ss + zz) - (xx + yy)); - matrix->r1c2 = 2.0f * (x1x2 - s0x3); - matrix->r2c3 = 2.0f * (x2x3 - s0x1); - matrix->r3c1 = 2.0f * (x1x3 - s0x2); + matrix->r1c2 = 2.0f * (xy - sz); + matrix->r2c3 = 2.0f * (yz - sx); + matrix->r3c1 = 2.0f * (xz - sy); - matrix->r2c1 = 2.0f * (x1x2 + s0x3); - matrix->r3c2 = 2.0f * (x2x3 + s0x1); - matrix->r1c3 = 2.0f * (x1x3 + s0x2); + matrix->r2c1 = 2.0f * (xy + sz); + matrix->r3c2 = 2.0f * (yz + sx); + matrix->r1c3 = 2.0f * (xz + sy); } inline void _bgc_fp64_versor_get_rotation_matrix(BGC_FP64_Matrix3x3* const matrix, const BGC_FP64_Quaternion* const versor) { - const double s0s0 = versor->s0 * versor->s0; - const double x1x1 = versor->x1 * versor->x1; - const double x2x2 = versor->x2 * versor->x2; - const double x3x3 = versor->x3 * versor->x3; + const double ss = versor->s * versor->s; + const double xx = versor->x * versor->x; + const double yy = versor->y * versor->y; + const double zz = versor->z * versor->z; - const double s0x1 = versor->s0 * versor->x1; - const double s0x2 = versor->s0 * versor->x2; - const double s0x3 = versor->s0 * versor->x3; + const double sx = versor->s * versor->x; + const double sy = versor->s * versor->y; + const double sz = versor->s * versor->z; - const double x1x2 = versor->x1 * versor->x2; - const double x1x3 = versor->x1 * versor->x3; + const double xy = versor->x * versor->y; + const double xz = versor->x * versor->z; - const double x2x3 = versor->x2 * versor->x3; + const double yz = versor->y * versor->z; - matrix->r1c1 = ((s0s0 + x1x1) - (x2x2 + x3x3)); - matrix->r2c2 = ((s0s0 + x2x2) - (x1x1 + x3x3)); - matrix->r3c3 = ((s0s0 + x3x3) - (x1x1 + x2x2)); + matrix->r1c1 = ((ss + xx) - (yy + zz)); + matrix->r2c2 = ((ss + yy) - (xx + zz)); + matrix->r3c3 = ((ss + zz) - (xx + yy)); - matrix->r1c2 = 2.0 * (x1x2 - s0x3); - matrix->r2c3 = 2.0 * (x2x3 - s0x1); - matrix->r3c1 = 2.0 * (x1x3 - s0x2); + matrix->r1c2 = 2.0 * (xy - sz); + matrix->r2c3 = 2.0 * (yz - sx); + matrix->r3c1 = 2.0 * (xz - sy); - matrix->r2c1 = 2.0 * (x1x2 + s0x3); - matrix->r3c2 = 2.0 * (x2x3 + s0x1); - matrix->r1c3 = 2.0 * (x1x3 + s0x2); + matrix->r2c1 = 2.0 * (xy + sz); + matrix->r3c2 = 2.0 * (yz + sx); + matrix->r1c3 = 2.0 * (xz + sy); } // ========= Get Versor Reverse Matrix ========== // inline void _bgc_fp32_versor_get_reverse_matrix(BGC_FP32_Matrix3x3* const matrix, const BGC_FP32_Quaternion* const versor) { - const float s0s0 = versor->s0 * versor->s0; - const float x1x1 = versor->x1 * versor->x1; - const float x2x2 = versor->x2 * versor->x2; - const float x3x3 = versor->x3 * versor->x3; + const float ss = versor->s * versor->s; + const float xx = versor->x * versor->x; + const float yy = versor->y * versor->y; + const float zz = versor->z * versor->z; - const float s0x1 = versor->s0 * versor->x1; - const float s0x2 = versor->s0 * versor->x2; - const float s0x3 = versor->s0 * versor->x3; + const float sx = versor->s * versor->x; + const float sy = versor->s * versor->y; + const float sz = versor->s * versor->z; - const float x1x2 = versor->x1 * versor->x2; - const float x1x3 = versor->x1 * versor->x3; + const float xy = versor->x * versor->y; + const float xz = versor->x * versor->z; - const float x2x3 = versor->x2 * versor->x3; + const float yz = versor->y * versor->z; - matrix->r1c1 = ((s0s0 + x1x1) - (x2x2 + x3x3)); - matrix->r2c2 = ((s0s0 + x2x2) - (x1x1 + x3x3)); - matrix->r3c3 = ((s0s0 + x3x3) - (x1x1 + x2x2)); + matrix->r1c1 = ((ss + xx) - (yy + zz)); + matrix->r2c2 = ((ss + yy) - (xx + zz)); + matrix->r3c3 = ((ss + zz) - (xx + yy)); - matrix->r1c2 = 2.0f * (x1x2 + s0x3); - matrix->r2c3 = 2.0f * (x2x3 + s0x1); - matrix->r3c1 = 2.0f * (x1x3 + s0x2); + matrix->r1c2 = 2.0f * (xy + sz); + matrix->r2c3 = 2.0f * (yz + sx); + matrix->r3c1 = 2.0f * (xz + sy); - matrix->r2c1 = 2.0f * (x1x2 - s0x3); - matrix->r3c2 = 2.0f * (x2x3 - s0x1); - matrix->r1c3 = 2.0f * (x1x3 - s0x2); + matrix->r2c1 = 2.0f * (xy - sz); + matrix->r3c2 = 2.0f * (yz - sx); + matrix->r1c3 = 2.0f * (xz - sy); } inline void _bgc_fp64_versor_get_reverse_matrix(BGC_FP64_Matrix3x3* const matrix, const BGC_FP64_Quaternion* const versor) { - const double s0s0 = versor->s0 * versor->s0; - const double x1x1 = versor->x1 * versor->x1; - const double x2x2 = versor->x2 * versor->x2; - const double x3x3 = versor->x3 * versor->x3; + const double ss = versor->s * versor->s; + const double xx = versor->x * versor->x; + const double yy = versor->y * versor->y; + const double zz = versor->z * versor->z; - const double s0x1 = versor->s0 * versor->x1; - const double s0x2 = versor->s0 * versor->x2; - const double s0x3 = versor->s0 * versor->x3; + const double sx = versor->s * versor->x; + const double sy = versor->s * versor->y; + const double sz = versor->s * versor->z; - const double x1x2 = versor->x1 * versor->x2; - const double x1x3 = versor->x1 * versor->x3; + const double xy = versor->x * versor->y; + const double xz = versor->x * versor->z; - const double x2x3 = versor->x2 * versor->x3; + const double yz = versor->y * versor->z; - matrix->r1c1 = ((s0s0 + x1x1) - (x2x2 + x3x3)); - matrix->r2c2 = ((s0s0 + x2x2) - (x1x1 + x3x3)); - matrix->r3c3 = ((s0s0 + x3x3) - (x1x1 + x2x2)); + matrix->r1c1 = ((ss + xx) - (yy + zz)); + matrix->r2c2 = ((ss + yy) - (xx + zz)); + matrix->r3c3 = ((ss + zz) - (xx + yy)); - matrix->r1c2 = 2.0 * (x1x2 + s0x3); - matrix->r2c3 = 2.0 * (x2x3 + s0x1); - matrix->r3c1 = 2.0 * (x1x3 + s0x2); + matrix->r1c2 = 2.0 * (xy + sz); + matrix->r2c3 = 2.0 * (yz + sx); + matrix->r3c1 = 2.0 * (xz + sy); - matrix->r2c1 = 2.0 * (x1x2 - s0x3); - matrix->r3c2 = 2.0 * (x2x3 - s0x1); - matrix->r1c3 = 2.0 * (x1x3 - s0x2); + matrix->r2c1 = 2.0 * (xy - sz); + matrix->r3c2 = 2.0 * (yz - sx); + matrix->r1c3 = 2.0 * (xz - sy); } // ============ Get Rotation Matrix ============= // inline int bgc_fp32_quaternion_get_rotation_matrix(BGC_FP32_Matrix3x3* const rotation, const BGC_FP32_Quaternion* const quaternion) { - const float s0s0 = quaternion->s0 * quaternion->s0; - const float x1x1 = quaternion->x1 * quaternion->x1; - const float x2x2 = quaternion->x2 * quaternion->x2; - const float x3x3 = quaternion->x3 * quaternion->x3; + const float ss = quaternion->s * quaternion->s; + const float xx = quaternion->x * quaternion->x; + const float yy = quaternion->y * quaternion->y; + const float zz = quaternion->z * quaternion->z; - const float square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3); + const float square_modulus = (ss + xx) + (yy + zz); if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) { @@ -1207,38 +1207,38 @@ inline int bgc_fp32_quaternion_get_rotation_matrix(BGC_FP32_Matrix3x3* const rot const float corrector1 = 1.0f / square_modulus; - const float s0x1 = quaternion->s0 * quaternion->x1; - const float s0x2 = quaternion->s0 * quaternion->x2; - const float s0x3 = quaternion->s0 * quaternion->x3; - const float x1x2 = quaternion->x1 * quaternion->x2; - const float x1x3 = quaternion->x1 * quaternion->x3; - const float x2x3 = quaternion->x2 * quaternion->x3; + const float sx = quaternion->s * quaternion->x; + const float sy = quaternion->s * quaternion->y; + const float sz = quaternion->s * quaternion->z; + const float xy = quaternion->x * quaternion->y; + const float xz = quaternion->x * quaternion->z; + const float yz = quaternion->y * quaternion->z; const float corrector2 = 2.0f * corrector1; - rotation->r1c1 = corrector1 * ((s0s0 + x1x1) - (x2x2 + x3x3)); - rotation->r2c2 = corrector1 * ((s0s0 + x2x2) - (x1x1 + x3x3)); - rotation->r3c3 = corrector1 * ((s0s0 + x3x3) - (x1x1 + x2x2)); + rotation->r1c1 = corrector1 * ((ss + xx) - (yy + zz)); + rotation->r2c2 = corrector1 * ((ss + yy) - (xx + zz)); + rotation->r3c3 = corrector1 * ((ss + zz) - (xx + yy)); - rotation->r1c2 = corrector2 * (x1x2 - s0x3); - rotation->r2c3 = corrector2 * (x2x3 - s0x1); - rotation->r3c1 = corrector2 * (x1x3 - s0x2); + rotation->r1c2 = corrector2 * (xy - sz); + rotation->r2c3 = corrector2 * (yz - sx); + rotation->r3c1 = corrector2 * (xz - sy); - rotation->r2c1 = corrector2 * (x1x2 + s0x3); - rotation->r3c2 = corrector2 * (x2x3 + s0x1); - rotation->r1c3 = corrector2 * (x1x3 + s0x2); + rotation->r2c1 = corrector2 * (xy + sz); + rotation->r3c2 = corrector2 * (yz + sx); + rotation->r1c3 = corrector2 * (xz + sy); return BGC_SUCCESS; } inline int bgc_fp64_quaternion_get_rotation_matrix(BGC_FP64_Matrix3x3* const rotation, const BGC_FP64_Quaternion* const quaternion) { - const double s0s0 = quaternion->s0 * quaternion->s0; - const double x1x1 = quaternion->x1 * quaternion->x1; - const double x2x2 = quaternion->x2 * quaternion->x2; - const double x3x3 = quaternion->x3 * quaternion->x3; + const double ss = quaternion->s * quaternion->s; + const double xx = quaternion->x * quaternion->x; + const double yy = quaternion->y * quaternion->y; + const double zz = quaternion->z * quaternion->z; - const double square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3); + const double square_modulus = (ss + xx) + (yy + zz); if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) { @@ -1248,26 +1248,26 @@ inline int bgc_fp64_quaternion_get_rotation_matrix(BGC_FP64_Matrix3x3* const rot const double corrector1 = 1.0f / square_modulus; - const double s0x1 = quaternion->s0 * quaternion->x1; - const double s0x2 = quaternion->s0 * quaternion->x2; - const double s0x3 = quaternion->s0 * quaternion->x3; - const double x1x2 = quaternion->x1 * quaternion->x2; - const double x1x3 = quaternion->x1 * quaternion->x3; - const double x2x3 = quaternion->x2 * quaternion->x3; + const double sx = quaternion->s * quaternion->x; + const double sy = quaternion->s * quaternion->y; + const double sz = quaternion->s * quaternion->z; + const double xy = quaternion->x * quaternion->y; + const double xz = quaternion->x * quaternion->z; + const double yz = quaternion->y * quaternion->z; const double corrector2 = 2.0f * corrector1; - rotation->r1c1 = corrector1 * ((s0s0 + x1x1) - (x2x2 + x3x3)); - rotation->r2c2 = corrector1 * ((s0s0 + x2x2) - (x1x1 + x3x3)); - rotation->r3c3 = corrector1 * ((s0s0 + x3x3) - (x1x1 + x2x2)); + rotation->r1c1 = corrector1 * ((ss + xx) - (yy + zz)); + rotation->r2c2 = corrector1 * ((ss + yy) - (xx + zz)); + rotation->r3c3 = corrector1 * ((ss + zz) - (xx + yy)); - rotation->r1c2 = corrector2 * (x1x2 - s0x3); - rotation->r2c3 = corrector2 * (x2x3 - s0x1); - rotation->r3c1 = corrector2 * (x1x3 - s0x2); + rotation->r1c2 = corrector2 * (xy - sz); + rotation->r2c3 = corrector2 * (yz - sx); + rotation->r3c1 = corrector2 * (xz - sy); - rotation->r2c1 = corrector2 * (x1x2 + s0x3); - rotation->r3c2 = corrector2 * (x2x3 + s0x1); - rotation->r1c3 = corrector2 * (x1x3 + s0x2); + rotation->r2c1 = corrector2 * (xy + sz); + rotation->r3c2 = corrector2 * (yz + sx); + rotation->r1c3 = corrector2 * (xz + sy); return BGC_SUCCESS; } @@ -1276,12 +1276,12 @@ inline int bgc_fp64_quaternion_get_rotation_matrix(BGC_FP64_Matrix3x3* const rot inline int bgc_fp32_quaternion_get_reverse_matrix(BGC_FP32_Matrix3x3* const reverse, const BGC_FP32_Quaternion* const quaternion) { - const float s0s0 = quaternion->s0 * quaternion->s0; - const float x1x1 = quaternion->x1 * quaternion->x1; - const float x2x2 = quaternion->x2 * quaternion->x2; - const float x3x3 = quaternion->x3 * quaternion->x3; + const float ss = quaternion->s * quaternion->s; + const float xx = quaternion->x * quaternion->x; + const float yy = quaternion->y * quaternion->y; + const float zz = quaternion->z * quaternion->z; - const float square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3); + const float square_modulus = (ss + xx) + (yy + zz); if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) { @@ -1291,38 +1291,38 @@ inline int bgc_fp32_quaternion_get_reverse_matrix(BGC_FP32_Matrix3x3* const reve const float corrector1 = 1.0f / square_modulus; - const float s0x1 = quaternion->s0 * quaternion->x1; - const float s0x2 = quaternion->s0 * quaternion->x2; - const float s0x3 = quaternion->s0 * quaternion->x3; - const float x1x2 = quaternion->x1 * quaternion->x2; - const float x1x3 = quaternion->x1 * quaternion->x3; - const float x2x3 = quaternion->x2 * quaternion->x3; + const float sx = quaternion->s * quaternion->x; + const float sy = quaternion->s * quaternion->y; + const float sz = quaternion->s * quaternion->z; + const float xy = quaternion->x * quaternion->y; + const float xz = quaternion->x * quaternion->z; + const float yz = quaternion->y * quaternion->z; const float corrector2 = 2.0f * corrector1; - reverse->r1c1 = corrector1 * ((s0s0 + x1x1) - (x2x2 + x3x3)); - reverse->r2c2 = corrector1 * ((s0s0 + x2x2) - (x1x1 + x3x3)); - reverse->r3c3 = corrector1 * ((s0s0 + x3x3) - (x1x1 + x2x2)); + reverse->r1c1 = corrector1 * ((ss + xx) - (yy + zz)); + reverse->r2c2 = corrector1 * ((ss + yy) - (xx + zz)); + reverse->r3c3 = corrector1 * ((ss + zz) - (xx + yy)); - reverse->r1c2 = corrector2 * (x1x2 + s0x3); - reverse->r2c3 = corrector2 * (x2x3 + s0x1); - reverse->r3c1 = corrector2 * (x1x3 + s0x2); + reverse->r1c2 = corrector2 * (xy + sz); + reverse->r2c3 = corrector2 * (yz + sx); + reverse->r3c1 = corrector2 * (xz + sy); - reverse->r2c1 = corrector2 * (x1x2 - s0x3); - reverse->r3c2 = corrector2 * (x2x3 - s0x1); - reverse->r1c3 = corrector2 * (x1x3 - s0x2); + reverse->r2c1 = corrector2 * (xy - sz); + reverse->r3c2 = corrector2 * (yz - sx); + reverse->r1c3 = corrector2 * (xz - sy); return BGC_SUCCESS; } inline int bgc_fp64_quaternion_get_reverse_matrix(BGC_FP64_Matrix3x3* const reverse, const BGC_FP64_Quaternion* const quaternion) { - const double s0s0 = quaternion->s0 * quaternion->s0; - const double x1x1 = quaternion->x1 * quaternion->x1; - const double x2x2 = quaternion->x2 * quaternion->x2; - const double x3x3 = quaternion->x3 * quaternion->x3; + const double ss = quaternion->s * quaternion->s; + const double xx = quaternion->x * quaternion->x; + const double yy = quaternion->y * quaternion->y; + const double zz = quaternion->z * quaternion->z; - const double square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3); + const double square_modulus = (ss + xx) + (yy + zz); if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) { @@ -1332,26 +1332,26 @@ inline int bgc_fp64_quaternion_get_reverse_matrix(BGC_FP64_Matrix3x3* const reve const double corrector1 = 1.0f / square_modulus; - const double s0x1 = quaternion->s0 * quaternion->x1; - const double s0x2 = quaternion->s0 * quaternion->x2; - const double s0x3 = quaternion->s0 * quaternion->x3; - const double x1x2 = quaternion->x1 * quaternion->x2; - const double x1x3 = quaternion->x1 * quaternion->x3; - const double x2x3 = quaternion->x2 * quaternion->x3; + const double sx = quaternion->s * quaternion->x; + const double sy = quaternion->s * quaternion->y; + const double sz = quaternion->s * quaternion->z; + const double xy = quaternion->x * quaternion->y; + const double xz = quaternion->x * quaternion->z; + const double yz = quaternion->y * quaternion->z; const double corrector2 = 2.0f * corrector1; - reverse->r1c1 = corrector1 * ((s0s0 + x1x1) - (x2x2 + x3x3)); - reverse->r2c2 = corrector1 * ((s0s0 + x2x2) - (x1x1 + x3x3)); - reverse->r3c3 = corrector1 * ((s0s0 + x3x3) - (x1x1 + x2x2)); + reverse->r1c1 = corrector1 * ((ss + xx) - (yy + zz)); + reverse->r2c2 = corrector1 * ((ss + yy) - (xx + zz)); + reverse->r3c3 = corrector1 * ((ss + zz) - (xx + yy)); - reverse->r1c2 = corrector2 * (x1x2 + s0x3); - reverse->r2c3 = corrector2 * (x2x3 + s0x1); - reverse->r3c1 = corrector2 * (x1x3 + s0x2); + reverse->r1c2 = corrector2 * (xy + sz); + reverse->r2c3 = corrector2 * (yz + sx); + reverse->r3c1 = corrector2 * (xz + sy); - reverse->r2c1 = corrector2 * (x1x2 - s0x3); - reverse->r3c2 = corrector2 * (x2x3 - s0x1); - reverse->r1c3 = corrector2 * (x1x3 - s0x2); + reverse->r2c1 = corrector2 * (xy - sz); + reverse->r3c2 = corrector2 * (yz - sx); + reverse->r1c3 = corrector2 * (xz - sy); return BGC_SUCCESS; } @@ -1382,14 +1382,14 @@ inline int bgc_fp64_quaternion_get_both_matrices(BGC_FP64_Matrix3x3* const rotat inline int bgc_fp32_quaternion_are_close(const BGC_FP32_Quaternion* const quaternion1, const BGC_FP32_Quaternion* const quaternion2) { - const float ds0 = quaternion1->s0 - quaternion2->s0; - const float dx1 = quaternion1->x1 - quaternion2->x1; - const float dx2 = quaternion1->x2 - quaternion2->x2; - const float dx3 = quaternion1->x3 - quaternion2->x3; + const float ds = quaternion1->s - quaternion2->s; + const float dx = quaternion1->x - quaternion2->x; + const float dy = quaternion1->y - quaternion2->y; + const float dz = quaternion1->z - quaternion2->z; const float square_modulus1 = bgc_fp32_quaternion_get_square_magnitude(quaternion1); const float square_modulus2 = bgc_fp32_quaternion_get_square_magnitude(quaternion2); - const float square_distance = (ds0 * ds0 + dx1 * dx1) + (dx2 * dx2 + dx3 * dx3); + const float square_distance = (ds * ds + dx * dx) + (dy * dy + dz * dz); if (square_modulus1 <= BGC_FP32_EPSILON_EFFECTIVENESS_LIMIT || square_modulus2 <= BGC_FP32_EPSILON_EFFECTIVENESS_LIMIT) { return square_distance <= BGC_FP32_SQUARE_EPSILON; @@ -1400,14 +1400,14 @@ inline int bgc_fp32_quaternion_are_close(const BGC_FP32_Quaternion* const quater inline int bgc_fp64_quaternion_are_close(const BGC_FP64_Quaternion* const quaternion1, const BGC_FP64_Quaternion* const quaternion2) { - const double ds0 = quaternion1->s0 - quaternion2->s0; - const double dx1 = quaternion1->x1 - quaternion2->x1; - const double dx2 = quaternion1->x2 - quaternion2->x2; - const double dx3 = quaternion1->x3 - quaternion2->x3; + const double ds = quaternion1->s - quaternion2->s; + const double dx = quaternion1->x - quaternion2->x; + const double dy = quaternion1->y - quaternion2->y; + const double dz = quaternion1->z - quaternion2->z; const double square_modulus1 = bgc_fp64_quaternion_get_square_magnitude(quaternion1); const double square_modulus2 = bgc_fp64_quaternion_get_square_magnitude(quaternion2); - const double square_distance = (ds0 * ds0 + dx1 * dx1) + (dx2 * dx2 + dx3 * dx3); + const double square_distance = (ds * ds + dx * dx) + (dy * dy + dz * dz); if (square_modulus1 <= BGC_FP64_EPSILON_EFFECTIVENESS_LIMIT || square_modulus2 <= BGC_FP64_EPSILON_EFFECTIVENESS_LIMIT) { return square_distance <= BGC_FP64_SQUARE_EPSILON; diff --git a/basic-geometry/rigid-pose3.h b/basic-geometry/rigid-pose3.h index 6aaa3d6..3949909 100644 --- a/basic-geometry/rigid-pose3.h +++ b/basic-geometry/rigid-pose3.h @@ -12,28 +12,28 @@ inline void bgc_fp32_rigid_pose3_reset(BGC_FP32_RigidPose3* const pose) { - pose->_versor.real_part.s0 = 1.0f; - pose->_versor.real_part.x1 = 0.0f; - pose->_versor.real_part.x2 = 0.0f; - pose->_versor.real_part.x3 = 0.0f; + pose->_versor.real_part.s = 1.0f; + pose->_versor.real_part.x = 0.0f; + pose->_versor.real_part.y = 0.0f; + pose->_versor.real_part.z = 0.0f; - pose->_versor.dual_part.s0 = 0.0f; - pose->_versor.dual_part.x1 = 0.0f; - pose->_versor.dual_part.x2 = 0.0f; - pose->_versor.dual_part.x3 = 0.0f; + pose->_versor.dual_part.s = 0.0f; + pose->_versor.dual_part.x = 0.0f; + pose->_versor.dual_part.y = 0.0f; + pose->_versor.dual_part.z = 0.0f; } inline void bgc_fp64_rigid_pose3_reset(BGC_FP64_RigidPose3* const pose) { - pose->_versor.real_part.s0 = 1.0; - pose->_versor.real_part.x1 = 0.0; - pose->_versor.real_part.x2 = 0.0; - pose->_versor.real_part.x3 = 0.0; + pose->_versor.real_part.s = 1.0; + pose->_versor.real_part.x = 0.0; + pose->_versor.real_part.y = 0.0; + pose->_versor.real_part.z = 0.0; - pose->_versor.dual_part.s0 = 0.0; - pose->_versor.dual_part.x1 = 0.0; - pose->_versor.dual_part.x2 = 0.0; - pose->_versor.dual_part.x3 = 0.0; + pose->_versor.dual_part.s = 0.0; + pose->_versor.dual_part.x = 0.0; + pose->_versor.dual_part.y = 0.0; + pose->_versor.dual_part.z = 0.0; } // ================= Normalize ================== // @@ -182,7 +182,7 @@ inline void bgc_fp64_rigid_pose3_convert_to_fp32(BGC_FP32_RigidPose3* const dest inline void bgc_fp32_rigid_pose3_shorten(BGC_FP32_RigidPose3* const pose) { - if (pose->_versor.real_part.s0 < 0.0f) { + if (pose->_versor.real_part.s < 0.0f) { bgc_fp32_quaternion_revert(&pose->_versor.real_part); bgc_fp32_quaternion_revert(&pose->_versor.dual_part); } @@ -190,7 +190,7 @@ inline void bgc_fp32_rigid_pose3_shorten(BGC_FP32_RigidPose3* const pose) inline void bgc_fp64_rigid_pose3_shorten(BGC_FP64_RigidPose3* const pose) { - if (pose->_versor.real_part.s0 < 0.0) { + if (pose->_versor.real_part.s < 0.0) { bgc_fp64_quaternion_revert(&pose->_versor.real_part); bgc_fp64_quaternion_revert(&pose->_versor.dual_part); } @@ -200,7 +200,7 @@ inline void bgc_fp64_rigid_pose3_shorten(BGC_FP64_RigidPose3* const pose) inline void bgc_fp32_rigid_pose3_get_shortened(BGC_FP32_RigidPose3* const shortened, const BGC_FP32_RigidPose3* const pose) { - if (pose->_versor.real_part.s0 < 0.0f) { + if (pose->_versor.real_part.s < 0.0f) { bgc_fp32_quaternion_get_reverse(&shortened->_versor.real_part, &pose->_versor.real_part); bgc_fp32_quaternion_get_reverse(&shortened->_versor.dual_part, &pose->_versor.dual_part); } @@ -212,7 +212,7 @@ inline void bgc_fp32_rigid_pose3_get_shortened(BGC_FP32_RigidPose3* const shorte inline void bgc_fp64_rigid_pose3_get_shortened(BGC_FP64_RigidPose3* const shortened, const BGC_FP64_RigidPose3* const pose) { - if (pose->_versor.real_part.s0 < 0.0) { + if (pose->_versor.real_part.s < 0.0) { bgc_fp64_quaternion_get_reverse(&shortened->_versor.real_part, &pose->_versor.real_part); bgc_fp64_quaternion_get_reverse(&shortened->_versor.dual_part, &pose->_versor.dual_part); } @@ -351,9 +351,9 @@ inline void bgc_fp32_rigid_pose3_get_shift(BGC_FP32_Vector3* const shift, const const BGC_FP32_Quaternion* const real = &pose->_versor.real_part; const BGC_FP32_Quaternion* const dual = &pose->_versor.dual_part; - shift->x1 = 2.0f * ((dual->x1 * real->s0 + dual->x3 * real->x2) - (dual->s0 * real->x1 + dual->x2 * real->x3)); - shift->x2 = 2.0f * ((dual->x2 * real->s0 + dual->x1 * real->x3) - (dual->s0 * real->x2 + dual->x3 * real->x1)); - shift->x3 = 2.0f * ((dual->x3 * real->s0 + dual->x2 * real->x1) - (dual->s0 * real->x3 + dual->x1 * real->x2)); + shift->x = 2.0f * ((dual->x * real->s + dual->z * real->y) - (dual->s * real->x + dual->y * real->z)); + shift->y = 2.0f * ((dual->y * real->s + dual->x * real->z) - (dual->s * real->y + dual->z * real->x)); + shift->z = 2.0f * ((dual->z * real->s + dual->y * real->x) - (dual->s * real->z + dual->x * real->y)); } inline void bgc_fp64_rigid_pose3_get_shift(BGC_FP64_Vector3* const shift, const BGC_FP64_RigidPose3* const pose) @@ -361,9 +361,9 @@ inline void bgc_fp64_rigid_pose3_get_shift(BGC_FP64_Vector3* const shift, const const BGC_FP64_Quaternion* const real = &pose->_versor.real_part; const BGC_FP64_Quaternion* const dual = &pose->_versor.dual_part; - shift->x1 = 2.0 * ((dual->x1 * real->s0 + dual->x3 * real->x2) - (dual->s0 * real->x1 + dual->x2 * real->x3)); - shift->x2 = 2.0 * ((dual->x2 * real->s0 + dual->x1 * real->x3) - (dual->s0 * real->x2 + dual->x3 * real->x1)); - shift->x3 = 2.0 * ((dual->x3 * real->s0 + dual->x2 * real->x1) - (dual->s0 * real->x3 + dual->x1 * real->x2)); + shift->x = 2.0 * ((dual->x * real->s + dual->z * real->y) - (dual->s * real->x + dual->y * real->z)); + shift->y = 2.0 * ((dual->y * real->s + dual->x * real->z) - (dual->s * real->y + dual->z * real->x)); + shift->z = 2.0 * ((dual->z * real->s + dual->y * real->x) - (dual->s * real->z + dual->x * real->y)); } // ============= Get Reverse Shift ============= // @@ -373,9 +373,9 @@ inline void bgc_fp32_rigid_pose3_get_reverse_shift(BGC_FP32_Vector3* const shift const BGC_FP32_Quaternion* const real = &pose->_versor.real_part; const BGC_FP32_Quaternion* const dual = &pose->_versor.dual_part; - shift->x1 = 2.0f * ((dual->s0 * real->x1 - dual->x1 * real->s0) + (dual->x3 * real->x2 - dual->x2 * real->x3)); - shift->x2 = 2.0f * ((dual->s0 * real->x2 - dual->x2 * real->s0) + (dual->x1 * real->x3 - dual->x3 * real->x1)); - shift->x3 = 2.0f * ((dual->s0 * real->x3 - dual->x3 * real->s0) + (dual->x2 * real->x1 - dual->x1 * real->x2)); + shift->x = 2.0f * ((dual->s * real->x - dual->x * real->s) + (dual->z * real->y - dual->y * real->z)); + shift->y = 2.0f * ((dual->s * real->y - dual->y * real->s) + (dual->x * real->z - dual->z * real->x)); + shift->z = 2.0f * ((dual->s * real->z - dual->z * real->s) + (dual->y * real->x - dual->x * real->y)); } inline void bgc_fp64_rigid_pose3_get_reverse_shift(BGC_FP64_Vector3* const shift, const BGC_FP64_RigidPose3* const pose) @@ -383,9 +383,9 @@ inline void bgc_fp64_rigid_pose3_get_reverse_shift(BGC_FP64_Vector3* const shift const BGC_FP64_Quaternion* const real = &pose->_versor.real_part; const BGC_FP64_Quaternion* const dual = &pose->_versor.dual_part; - shift->x1 = 2.0 * ((dual->s0 * real->x1 - dual->x1 * real->s0) + (dual->x3 * real->x2 - dual->x2 * real->x3)); - shift->x2 = 2.0 * ((dual->s0 * real->x2 - dual->x2 * real->s0) + (dual->x1 * real->x3 - dual->x3 * real->x1)); - shift->x3 = 2.0 * ((dual->s0 * real->x3 - dual->x3 * real->s0) + (dual->x2 * real->x1 - dual->x1 * real->x2)); + shift->x = 2.0 * ((dual->s * real->x - dual->x * real->s) + (dual->z * real->y - dual->y * real->z)); + shift->y = 2.0 * ((dual->s * real->y - dual->y * real->s) + (dual->x * real->z - dual->z * real->x)); + shift->z = 2.0 * ((dual->s * real->z - dual->z * real->s) + (dual->y * real->x - dual->x * real->y)); } // ================ Get Affine3 ================= // @@ -439,10 +439,10 @@ inline void bgc_fp32_rigid_pose3_set_position(BGC_FP32_RigidPose3* const pose, c bgc_fp32_quaternion_copy(&pose->_versor.real_part, versor); - pose->_versor.dual_part.s0 = -0.5f * (shift->x1 * versor->x1 + shift->x2 * versor->x2 + shift->x3 * versor->x3); - pose->_versor.dual_part.x1 = -0.5f * (shift->x3 * versor->x2 - shift->x2 * versor->x3 - shift->x1 * versor->s0); - pose->_versor.dual_part.x2 = -0.5f * (shift->x1 * versor->x3 - shift->x3 * versor->x1 - shift->x2 * versor->s0); - pose->_versor.dual_part.x3 = -0.5f * (shift->x2 * versor->x1 - shift->x1 * versor->x2 - shift->x3 * versor->s0); + pose->_versor.dual_part.s = -0.5f * (shift->x * versor->x + shift->y * versor->y + shift->z * versor->z); + pose->_versor.dual_part.x = -0.5f * (shift->z * versor->y - shift->y * versor->z - shift->x * versor->s); + pose->_versor.dual_part.y = -0.5f * (shift->x * versor->z - shift->z * versor->x - shift->y * versor->s); + pose->_versor.dual_part.z = -0.5f * (shift->y * versor->x - shift->x * versor->y - shift->z * versor->s); } inline void bgc_fp64_rigid_pose3_set_position(BGC_FP64_RigidPose3* const pose, const BGC_FP64_Position3* const position) @@ -452,10 +452,10 @@ inline void bgc_fp64_rigid_pose3_set_position(BGC_FP64_RigidPose3* const pose, c bgc_fp64_quaternion_copy(&pose->_versor.real_part, versor); - pose->_versor.dual_part.s0 = -0.5 * (shift->x1 * versor->x1 + shift->x2 * versor->x2 + shift->x3 * versor->x3); - pose->_versor.dual_part.x1 = -0.5 * (shift->x3 * versor->x2 - shift->x2 * versor->x3 - shift->x1 * versor->s0); - pose->_versor.dual_part.x2 = -0.5 * (shift->x1 * versor->x3 - shift->x3 * versor->x1 - shift->x2 * versor->s0); - pose->_versor.dual_part.x3 = -0.5 * (shift->x2 * versor->x1 - shift->x1 * versor->x2 - shift->x3 * versor->s0); + pose->_versor.dual_part.s = -0.5 * (shift->x * versor->x + shift->y * versor->y + shift->z * versor->z); + pose->_versor.dual_part.x = -0.5 * (shift->z * versor->y - shift->y * versor->z - shift->x * versor->s); + pose->_versor.dual_part.y = -0.5 * (shift->x * versor->z - shift->z * versor->x - shift->y * versor->s); + pose->_versor.dual_part.z = -0.5 * (shift->y * versor->x - shift->x * versor->y - shift->z * versor->s); } // =========== Get Reverse Position3 ============ // @@ -481,10 +481,10 @@ inline void bgc_fp32_rigid_pose3_set_reverse_position(BGC_FP32_RigidPose3* const bgc_fp32_quaternion_get_conjugate(&pose->_versor.real_part, versor); - pose->_versor.dual_part.s0 = -0.5f * (versor->x1 * shift->x1 + versor->x2 * shift->x2 + versor->x3 * shift->x3); - pose->_versor.dual_part.x1 = -0.5f * (versor->s0 * shift->x1 + versor->x3 * shift->x2 - versor->x2 * shift->x3); - pose->_versor.dual_part.x2 = -0.5f * (versor->s0 * shift->x2 + versor->x1 * shift->x3 - versor->x3 * shift->x1); - pose->_versor.dual_part.x3 = -0.5f * (versor->s0 * shift->x3 + versor->x2 * shift->x1 - versor->x1 * shift->x2); + pose->_versor.dual_part.s = -0.5f * (versor->x * shift->x + versor->y * shift->y + versor->z * shift->z); + pose->_versor.dual_part.x = -0.5f * (versor->s * shift->x + versor->z * shift->y - versor->y * shift->z); + pose->_versor.dual_part.y = -0.5f * (versor->s * shift->y + versor->x * shift->z - versor->z * shift->x); + pose->_versor.dual_part.z = -0.5f * (versor->s * shift->z + versor->y * shift->x - versor->x * shift->y); } inline void bgc_fp64_rigid_pose3_set_reverse_position(BGC_FP64_RigidPose3* const pose, const BGC_FP64_Position3* const position) @@ -494,10 +494,10 @@ inline void bgc_fp64_rigid_pose3_set_reverse_position(BGC_FP64_RigidPose3* const bgc_fp64_quaternion_get_conjugate(&pose->_versor.real_part, versor); - pose->_versor.dual_part.s0 = -0.5f * (versor->x1 * shift->x1 + versor->x2 * shift->x2 + versor->x3 * shift->x3); - pose->_versor.dual_part.x1 = -0.5f * (versor->s0 * shift->x1 + versor->x3 * shift->x2 - versor->x2 * shift->x3); - pose->_versor.dual_part.x2 = -0.5f * (versor->s0 * shift->x2 + versor->x1 * shift->x3 - versor->x3 * shift->x1); - pose->_versor.dual_part.x3 = -0.5f * (versor->s0 * shift->x3 + versor->x2 * shift->x1 - versor->x1 * shift->x2); + pose->_versor.dual_part.s = -0.5f * (versor->x * shift->x + versor->y * shift->y + versor->z * shift->z); + pose->_versor.dual_part.x = -0.5f * (versor->s * shift->x + versor->z * shift->y - versor->y * shift->z); + pose->_versor.dual_part.y = -0.5f * (versor->s * shift->y + versor->x * shift->z - versor->z * shift->x); + pose->_versor.dual_part.z = -0.5f * (versor->s * shift->z + versor->y * shift->x - versor->x * shift->y); } // ============== Transform Vector ============== // diff --git a/basic-geometry/slerp3.c b/basic-geometry/slerp3.c index 7a1934a..94512e1 100644 --- a/basic-geometry/slerp3.c +++ b/basic-geometry/slerp3.c @@ -23,7 +23,7 @@ extern inline void bgc_fp64_slerp3_get_phase_both_matrices(BGC_FP64_Matrix3x3* c void bgc_fp32_slerp3_make(BGC_FP32_Slerp3* const slerp, const BGC_FP32_Turn3* const start, const BGC_FP32_Turn3* const augment) { - const float square_vector = augment->_versor.x1 * augment->_versor.x1 + augment->_versor.x2 * augment->_versor.x2 + augment->_versor.x3 * augment->_versor.x3; + const float square_vector = augment->_versor.x * augment->_versor.x + augment->_versor.y * augment->_versor.y + augment->_versor.z * augment->_versor.z; if (isnan(square_vector)) { bgc_fp32_slerp3_reset(slerp); @@ -31,15 +31,15 @@ void bgc_fp32_slerp3_make(BGC_FP32_Slerp3* const slerp, const BGC_FP32_Turn3* co } if (square_vector <= BGC_FP32_SQUARE_EPSILON) { - slerp->_cosine_weight.s0 = start->_versor.s0; - slerp->_cosine_weight.x1 = start->_versor.x1; - slerp->_cosine_weight.x2 = start->_versor.x2; - slerp->_cosine_weight.x3 = start->_versor.x3; + slerp->_cosine_weight.s = start->_versor.s; + slerp->_cosine_weight.x = start->_versor.x; + slerp->_cosine_weight.y = start->_versor.y; + slerp->_cosine_weight.z = start->_versor.z; - slerp->_sine_weight.s0 = 0.0f; - slerp->_sine_weight.x1 = 0.0f; - slerp->_sine_weight.x2 = 0.0f; - slerp->_sine_weight.x3 = 0.0f; + slerp->_sine_weight.s = 0.0f; + slerp->_sine_weight.x = 0.0f; + slerp->_sine_weight.y = 0.0f; + slerp->_sine_weight.z = 0.0f; slerp->radians = 0.0f; return; @@ -47,24 +47,24 @@ void bgc_fp32_slerp3_make(BGC_FP32_Slerp3* const slerp, const BGC_FP32_Turn3* co const float vector_modulus = sqrtf(square_vector); - slerp->radians = atan2f(vector_modulus, augment->_versor.s0); + slerp->radians = atan2f(vector_modulus, augment->_versor.s); const float multiplier = 1.0f / vector_modulus; - slerp->_cosine_weight.s0 = start->_versor.s0; - slerp->_cosine_weight.x1 = start->_versor.x1; - slerp->_cosine_weight.x2 = start->_versor.x2; - slerp->_cosine_weight.x3 = start->_versor.x3; + slerp->_cosine_weight.s = start->_versor.s; + slerp->_cosine_weight.x = start->_versor.x; + slerp->_cosine_weight.y = start->_versor.y; + slerp->_cosine_weight.z = start->_versor.z; - slerp->_sine_weight.s0 = -multiplier * (augment->_versor.x1 * start->_versor.x1 + augment->_versor.x2 * start->_versor.x2 + augment->_versor.x3 * start->_versor.x3); - slerp->_sine_weight.x1 = multiplier * (augment->_versor.x1 * start->_versor.s0 + augment->_versor.x2 * start->_versor.x3 - augment->_versor.x3 * start->_versor.x2); - slerp->_sine_weight.x2 = multiplier * (augment->_versor.x2 * start->_versor.s0 - augment->_versor.x1 * start->_versor.x3 + augment->_versor.x3 * start->_versor.x1); - slerp->_sine_weight.x3 = multiplier * (augment->_versor.x3 * start->_versor.s0 - augment->_versor.x2 * start->_versor.x1 + augment->_versor.x1 * start->_versor.x2); + slerp->_sine_weight.s = -multiplier * (augment->_versor.x * start->_versor.x + augment->_versor.y * start->_versor.y + augment->_versor.z * start->_versor.z); + slerp->_sine_weight.x = multiplier * (augment->_versor.x * start->_versor.s + augment->_versor.y * start->_versor.z - augment->_versor.z * start->_versor.y); + slerp->_sine_weight.y = multiplier * (augment->_versor.y * start->_versor.s - augment->_versor.x * start->_versor.z + augment->_versor.z * start->_versor.x); + slerp->_sine_weight.z = multiplier * (augment->_versor.z * start->_versor.s - augment->_versor.y * start->_versor.x + augment->_versor.x * start->_versor.y); } void bgc_fp64_slerp3_make(BGC_FP64_Slerp3* const slerp, const BGC_FP64_Turn3* const start, const BGC_FP64_Turn3* const augment) { - const double square_vector = augment->_versor.x1 * augment->_versor.x1 + augment->_versor.x2 * augment->_versor.x2 + augment->_versor.x3 * augment->_versor.x3; + const double square_vector = augment->_versor.x * augment->_versor.x + augment->_versor.y * augment->_versor.y + augment->_versor.z * augment->_versor.z; if (isnan(square_vector)) { bgc_fp64_slerp3_reset(slerp); @@ -72,15 +72,15 @@ void bgc_fp64_slerp3_make(BGC_FP64_Slerp3* const slerp, const BGC_FP64_Turn3* co } if (square_vector <= BGC_FP64_SQUARE_EPSILON) { - slerp->_cosine_weight.s0 = start->_versor.s0; - slerp->_cosine_weight.x1 = start->_versor.x1; - slerp->_cosine_weight.x2 = start->_versor.x2; - slerp->_cosine_weight.x3 = start->_versor.x3; + slerp->_cosine_weight.s = start->_versor.s; + slerp->_cosine_weight.x = start->_versor.x; + slerp->_cosine_weight.y = start->_versor.y; + slerp->_cosine_weight.z = start->_versor.z; - slerp->_sine_weight.s0 = 0.0; - slerp->_sine_weight.x1 = 0.0; - slerp->_sine_weight.x2 = 0.0; - slerp->_sine_weight.x3 = 0.0; + slerp->_sine_weight.s = 0.0; + slerp->_sine_weight.x = 0.0; + slerp->_sine_weight.y = 0.0; + slerp->_sine_weight.z = 0.0; slerp->radians = 0.0; return; @@ -88,17 +88,17 @@ void bgc_fp64_slerp3_make(BGC_FP64_Slerp3* const slerp, const BGC_FP64_Turn3* co const double vector_modulus = sqrt(square_vector); - slerp->radians = atan2(vector_modulus, augment->_versor.s0); + slerp->radians = atan2(vector_modulus, augment->_versor.s); const double multiplier = 1.0 / vector_modulus; - slerp->_cosine_weight.s0 = start->_versor.s0; - slerp->_cosine_weight.x1 = start->_versor.x1; - slerp->_cosine_weight.x2 = start->_versor.x2; - slerp->_cosine_weight.x3 = start->_versor.x3; + slerp->_cosine_weight.s = start->_versor.s; + slerp->_cosine_weight.x = start->_versor.x; + slerp->_cosine_weight.y = start->_versor.y; + slerp->_cosine_weight.z = start->_versor.z; - slerp->_sine_weight.s0 = -multiplier * (augment->_versor.x1 * start->_versor.x1 + augment->_versor.x2 * start->_versor.x2 + augment->_versor.x3 * start->_versor.x3); - slerp->_sine_weight.x1 = multiplier * (augment->_versor.x1 * start->_versor.s0 + augment->_versor.x2 * start->_versor.x3 - augment->_versor.x3 * start->_versor.x2); - slerp->_sine_weight.x2 = multiplier * (augment->_versor.x2 * start->_versor.s0 - augment->_versor.x1 * start->_versor.x3 + augment->_versor.x3 * start->_versor.x1); - slerp->_sine_weight.x3 = multiplier * (augment->_versor.x3 * start->_versor.s0 - augment->_versor.x2 * start->_versor.x1 + augment->_versor.x1 * start->_versor.x2); + slerp->_sine_weight.s = -multiplier * (augment->_versor.x * start->_versor.x + augment->_versor.y * start->_versor.y + augment->_versor.z * start->_versor.z); + slerp->_sine_weight.x = multiplier * (augment->_versor.x * start->_versor.s + augment->_versor.y * start->_versor.z - augment->_versor.z * start->_versor.y); + slerp->_sine_weight.y = multiplier * (augment->_versor.y * start->_versor.s - augment->_versor.x * start->_versor.z + augment->_versor.z * start->_versor.x); + slerp->_sine_weight.z = multiplier * (augment->_versor.z * start->_versor.s - augment->_versor.y * start->_versor.x + augment->_versor.x * start->_versor.y); } diff --git a/basic-geometry/slerp3.h b/basic-geometry/slerp3.h index 3712d82..8b547c8 100644 --- a/basic-geometry/slerp3.h +++ b/basic-geometry/slerp3.h @@ -9,30 +9,30 @@ inline void bgc_fp32_slerp3_reset(BGC_FP32_Slerp3* const slerp) { - slerp->_cosine_weight.s0 = 1.0f; - slerp->_cosine_weight.x1 = 0.0f; - slerp->_cosine_weight.x2 = 0.0f; - slerp->_cosine_weight.x3 = 0.0f; + slerp->_cosine_weight.s = 1.0f; + slerp->_cosine_weight.x = 0.0f; + slerp->_cosine_weight.y = 0.0f; + slerp->_cosine_weight.z = 0.0f; - slerp->_sine_weight.s0 = 0.0f; - slerp->_sine_weight.x1 = 0.0f; - slerp->_sine_weight.x2 = 0.0f; - slerp->_sine_weight.x3 = 0.0f; + slerp->_sine_weight.s = 0.0f; + slerp->_sine_weight.x = 0.0f; + slerp->_sine_weight.y = 0.0f; + slerp->_sine_weight.z = 0.0f; slerp->radians = 0.0f; } inline void bgc_fp64_slerp3_reset(BGC_FP64_Slerp3* const slerp) { - slerp->_cosine_weight.s0 = 1.0; - slerp->_cosine_weight.x1 = 0.0; - slerp->_cosine_weight.x2 = 0.0; - slerp->_cosine_weight.x3 = 0.0; + slerp->_cosine_weight.s = 1.0; + slerp->_cosine_weight.x = 0.0; + slerp->_cosine_weight.y = 0.0; + slerp->_cosine_weight.z = 0.0; - slerp->_sine_weight.s0 = 0.0; - slerp->_sine_weight.x1 = 0.0; - slerp->_sine_weight.x2 = 0.0; - slerp->_sine_weight.x3 = 0.0; + slerp->_sine_weight.s = 0.0; + slerp->_sine_weight.x = 0.0; + slerp->_sine_weight.y = 0.0; + slerp->_sine_weight.z = 0.0; slerp->radians = 0.0; } diff --git a/basic-geometry/turn2.c b/basic-geometry/turn2.c index 1f63d49..db0a5db 100644 --- a/basic-geometry/turn2.c +++ b/basic-geometry/turn2.c @@ -10,8 +10,8 @@ extern inline void bgc_fp64_turn2_reset(BGC_FP64_Turn2* const turn); extern void _bgc_fp32_turn2_normalize(BGC_FP32_Turn2* const turn); extern void _bgc_fp64_turn2_normalize(BGC_FP64_Turn2* const turn); -extern inline void bgc_fp32_turn2_set_values(BGC_FP32_Turn2* const turn, const float x1, const float x2); -extern inline void bgc_fp64_turn2_set_values(BGC_FP64_Turn2* const turn, const double x1, const double x2); +extern inline void bgc_fp32_turn2_set_values(BGC_FP32_Turn2* const turn, const float x, const float y); +extern inline void bgc_fp64_turn2_set_values(BGC_FP64_Turn2* const turn, const double x, const double y); extern inline void bgc_fp32_turn2_set_angle(BGC_FP32_Turn2* const turn, const float angle, const int angle_unit); extern inline void bgc_fp64_turn2_set_angle(BGC_FP64_Turn2* const turn, const double angle, const int angle_unit); diff --git a/basic-geometry/turn2.h b/basic-geometry/turn2.h index 822759d..9dc23d9 100644 --- a/basic-geometry/turn2.h +++ b/basic-geometry/turn2.h @@ -101,18 +101,18 @@ inline int bgc_fp64_turn2_is_idle(const BGC_FP64_Turn2* const turn) // ==================== Set ===================== // -inline void bgc_fp32_turn2_set_values(BGC_FP32_Turn2* const turn, const float x1, const float x2) +inline void bgc_fp32_turn2_set_values(BGC_FP32_Turn2* const turn, const float x, const float y) { - turn->_cos = x1; - turn->_sin = x2; + turn->_cos = x; + turn->_sin = y; _bgc_fp32_turn2_normalize(turn); } -inline void bgc_fp64_turn2_set_values(BGC_FP64_Turn2* const turn, const double x1, const double x2) +inline void bgc_fp64_turn2_set_values(BGC_FP64_Turn2* const turn, const double x, const double y) { - turn->_cos = x1; - turn->_sin = x2; + turn->_cos = x; + turn->_sin = y; _bgc_fp64_turn2_normalize(turn); } @@ -347,40 +347,40 @@ inline void bgc_fp64_turn2_get_reverse_matrix(BGC_FP64_Matrix2x2* const matrix, inline void bgc_fp32_turn2_vector(BGC_FP32_Vector2* const turned_vector, const BGC_FP32_Turn2* const turn, const BGC_FP32_Vector2* const vector) { - const float x1 = turn->_cos * vector->x1 - turn->_sin * vector->x2; - const float x2 = turn->_sin * vector->x1 + turn->_cos * vector->x2; + const float x = turn->_cos * vector->x - turn->_sin * vector->y; + const float y = turn->_sin * vector->x + turn->_cos * vector->y; - turned_vector->x1 = x1; - turned_vector->x2 = x2; + turned_vector->x = x; + turned_vector->y = y; } inline void bgc_fp64_turn2_vector(BGC_FP64_Vector2* const turned_vector, const BGC_FP64_Turn2* const turn, const BGC_FP64_Vector2* const vector) { - const double x1 = turn->_cos * vector->x1 - turn->_sin * vector->x2; - const double x2 = turn->_sin * vector->x1 + turn->_cos * vector->x2; + const double x = turn->_cos * vector->x - turn->_sin * vector->y; + const double y = turn->_sin * vector->x + turn->_cos * vector->y; - turned_vector->x1 = x1; - turned_vector->x2 = x2; + turned_vector->x = x; + turned_vector->y = y; } // ============ Turn Vector Backward ============ // inline void bgc_fp32_turn2_vector_back(BGC_FP32_Vector2* const turned_vector, const BGC_FP32_Turn2* const turn, const BGC_FP32_Vector2* const vector) { - const float x1 = turn->_sin * vector->x2 + turn->_cos * vector->x1; - const float x2 = turn->_cos * vector->x2 - turn->_sin * vector->x1; + const float x = turn->_sin * vector->y + turn->_cos * vector->x; + const float y = turn->_cos * vector->y - turn->_sin * vector->x; - turned_vector->x1 = x1; - turned_vector->x2 = x2; + turned_vector->x = x; + turned_vector->y = y; } inline void bgc_fp64_turn2_vector_back(BGC_FP64_Vector2* const turned_vector, const BGC_FP64_Turn2* const turn, const BGC_FP64_Vector2* const vector) { - const double x1 = turn->_sin * vector->x2 + turn->_cos * vector->x1; - const double x2 = turn->_cos * vector->x2 - turn->_sin * vector->x1; + const double x = turn->_sin * vector->y + turn->_cos * vector->x; + const double y = turn->_cos * vector->y - turn->_sin * vector->x; - turned_vector->x1 = x1; - turned_vector->x2 = x2; + turned_vector->x = x; + turned_vector->y = y; } // ================== Are Close ================= // diff --git a/basic-geometry/turn3.c b/basic-geometry/turn3.c index c3a4a5e..2254a61 100644 --- a/basic-geometry/turn3.c +++ b/basic-geometry/turn3.c @@ -12,8 +12,8 @@ extern inline void bgc_fp64_turn3_reset(BGC_FP64_Turn3* const turn); extern inline void _bgc_fp32_turn3_normalize(BGC_FP32_Turn3* const turn); extern inline void _bgc_fp64_turn3_normalize(BGC_FP64_Turn3* const turn); -extern inline void bgc_fp32_turn3_set_values(BGC_FP32_Turn3* const turn, const float s0, const float x1, const float x2, const float x3); -extern inline void bgc_fp64_turn3_set_values(BGC_FP64_Turn3* const turn, const double s0, const double x1, const double x2, const double x3); +extern inline void bgc_fp32_turn3_set_values(BGC_FP32_Turn3* const turn, const float s, const float x, const float y, const float z); +extern inline void bgc_fp64_turn3_set_values(BGC_FP64_Turn3* const turn, const double s, const double x, const double y, const double z); extern inline void bgc_fp32_turn3_get_quaternion(BGC_FP32_Quaternion* const quaternion, const BGC_FP32_Turn3* const turn); extern inline void bgc_fp64_turn3_get_quaternion(BGC_FP64_Quaternion* const quaternion, const BGC_FP64_Turn3* const turn); @@ -82,7 +82,7 @@ extern inline int bgc_fp64_turn3_are_close(const BGC_FP64_Turn3* const turn1, co float bgc_fp32_turn3_get_rotation(BGC_FP32_Vector3* const axis, const BGC_FP32_Turn3* const turn, const int angle_unit) { - const float square_vector_modulus = turn->_versor.x1 * turn->_versor.x1 + turn->_versor.x2 * turn->_versor.x2 + turn->_versor.x3 * turn->_versor.x3; + const float square_vector_modulus = turn->_versor.x * turn->_versor.x + turn->_versor.y * turn->_versor.y + turn->_versor.z * turn->_versor.z; if (square_vector_modulus <= BGC_FP32_SQUARE_EPSILON) { bgc_fp32_vector3_reset(axis); @@ -93,16 +93,16 @@ float bgc_fp32_turn3_get_rotation(BGC_FP32_Vector3* const axis, const BGC_FP32_T const float multiplier = 1.0f / vector_modulus; - axis->x1 = turn->_versor.x1 * multiplier; - axis->x2 = turn->_versor.x2 * multiplier; - axis->x3 = turn->_versor.x3 * multiplier; + axis->x = turn->_versor.x * multiplier; + axis->y = turn->_versor.y * multiplier; + axis->z = turn->_versor.z * multiplier; - return 2.0f * atan2f(vector_modulus, turn->_versor.s0); + return 2.0f * atan2f(vector_modulus, turn->_versor.s); } double bgc_fp64_turn3_get_rotation(BGC_FP64_Vector3* const axis, const BGC_FP64_Turn3* const turn, const int angle_unit) { - const double square_vector_modulus = turn->_versor.x1 * turn->_versor.x1 + turn->_versor.x2 * turn->_versor.x2 + turn->_versor.x3 * turn->_versor.x3; + const double square_vector_modulus = turn->_versor.x * turn->_versor.x + turn->_versor.y * turn->_versor.y + turn->_versor.z * turn->_versor.z; if (square_vector_modulus <= BGC_FP64_SQUARE_EPSILON) { bgc_fp64_vector3_reset(axis); @@ -113,18 +113,18 @@ double bgc_fp64_turn3_get_rotation(BGC_FP64_Vector3* const axis, const BGC_FP64_ const double multiplier = 1.0 / vector_modulus; - axis->x1 = turn->_versor.x1 * multiplier; - axis->x2 = turn->_versor.x2 * multiplier; - axis->x3 = turn->_versor.x3 * multiplier; + axis->x = turn->_versor.x * multiplier; + axis->y = turn->_versor.y * multiplier; + axis->z = turn->_versor.z * multiplier; - return 2.0 * atan2(vector_modulus, turn->_versor.s0); + return 2.0 * atan2(vector_modulus, turn->_versor.s); } // ================ Set Rotation ================ // -void bgc_fp32_turn3_set_rotation(BGC_FP32_Turn3* const turn, const float x1, const float x2, const float x3, const float angle, const int angle_unit) +void bgc_fp32_turn3_set_rotation(BGC_FP32_Turn3* const turn, const float x, const float y, const float z, const float angle, const int angle_unit) { - const float square_vector = x1 * x1 + x2 * x2 + x3 * x3; + const float square_vector = x * x + y * y + z * z; if (square_vector <= BGC_FP32_SQUARE_EPSILON) { bgc_fp32_turn3_reset(turn); @@ -142,14 +142,14 @@ void bgc_fp32_turn3_set_rotation(BGC_FP32_Turn3* const turn, const float x1, con const float multiplier = sine / sqrtf(square_vector); - bgc_fp32_quaternion_set_values(&turn->_versor, cosf(half_angle), x1 * multiplier, x2 * multiplier, x3 * multiplier); + bgc_fp32_quaternion_set_values(&turn->_versor, cosf(half_angle), x * multiplier, y * multiplier, z * multiplier); _bgc_fp32_turn3_normalize(turn); } -void bgc_fp64_turn3_set_rotation(BGC_FP64_Turn3* const turn, const double x1, const double x2, const double x3, const double angle, const int angle_unit) +void bgc_fp64_turn3_set_rotation(BGC_FP64_Turn3* const turn, const double x, const double y, const double z, const double angle, const int angle_unit) { - const double square_vector = x1 * x1 + x2 * x2 + x3 * x3; + const double square_vector = x * x + y * y + z * z; if (square_vector <= BGC_FP64_SQUARE_EPSILON) { bgc_fp64_turn3_reset(turn); @@ -167,7 +167,7 @@ void bgc_fp64_turn3_set_rotation(BGC_FP64_Turn3* const turn, const double x1, co const double multiplier = sine / sqrt(square_vector); - bgc_fp64_quaternion_set_values(&turn->_versor, cos(half_angle), x1 * multiplier, x2 * multiplier, x3 * multiplier); + bgc_fp64_quaternion_set_values(&turn->_versor, cos(half_angle), x * multiplier, y * multiplier, z * multiplier); _bgc_fp64_turn3_normalize(turn); } @@ -210,7 +210,7 @@ int bgc_fp32_turn3_find_direction_difference(BGC_FP32_Turn3* const turn, const B const float vector_multiplier = sinf(angle) / axis_modulus; - bgc_fp32_turn3_set_values(turn, cosf(angle), axis.x1 * vector_multiplier, axis.x2 * vector_multiplier, axis.x3 * vector_multiplier); + bgc_fp32_turn3_set_values(turn, cosf(angle), axis.x * vector_multiplier, axis.y * vector_multiplier, axis.z * vector_multiplier); return BGC_SUCCESS; } @@ -251,7 +251,7 @@ int bgc_fp64_turn3_find_direction_difference(BGC_FP64_Turn3* const turn, const B const double vector_multiplier = sin(angle) / axis_modulus; - bgc_fp64_turn3_set_values(turn, cos(angle), axis.x1 * vector_multiplier, axis.x2 * vector_multiplier, axis.x3 * vector_multiplier); + bgc_fp64_turn3_set_values(turn, cos(angle), axis.x * vector_multiplier, axis.y * vector_multiplier, axis.z * vector_multiplier); return BGC_SUCCESS; } @@ -332,18 +332,18 @@ static inline void _bgc_fp32_turn3_get_turning_quaternion(BGC_FP32_Quaternion* c if (axis_square_modulus <= BGC_FP32_SQUARE_EPSILON) { // unit_start and unit_end are co-directional, angle = 180 degrees if (dot_product >= 0.0f) { - quaternion->s0 = 1.0f; - quaternion->x1 = 0.0f; - quaternion->x2 = 0.0f; - quaternion->x3 = 0.0f; + quaternion->s = 1.0f; + quaternion->x = 0.0f; + quaternion->y = 0.0f; + quaternion->z = 0.0f; return; } // unit_start and unit_end are opposite, angle = 180 degrees - quaternion->s0 = 0.0f; - quaternion->x1 = unit_orthogonal->x1; - quaternion->x2 = unit_orthogonal->x2; - quaternion->x3 = unit_orthogonal->x3; + quaternion->s = 0.0f; + quaternion->x = unit_orthogonal->x; + quaternion->y = unit_orthogonal->y; + quaternion->z = unit_orthogonal->z; return; } @@ -353,10 +353,10 @@ static inline void _bgc_fp32_turn3_get_turning_quaternion(BGC_FP32_Quaternion* c const float multiplier = sinf(angle) / axis_modulus; - quaternion->s0 = cosf(angle); - quaternion->x1 = axis.x1 * multiplier; - quaternion->x2 = axis.x2 * multiplier; - quaternion->x3 = axis.x3 * multiplier; + quaternion->s = cosf(angle); + quaternion->x = axis.x * multiplier; + quaternion->y = axis.y * multiplier; + quaternion->z = axis.z * multiplier; } static inline void _bgc_fp64_turn3_get_turning_quaternion(BGC_FP64_Quaternion* const quaternion, const BGC_FP64_Vector3* const unit_start, const BGC_FP64_Vector3* const unit_end, const BGC_FP64_Vector3* const unit_orthogonal) @@ -373,18 +373,18 @@ static inline void _bgc_fp64_turn3_get_turning_quaternion(BGC_FP64_Quaternion* c if (axis_square_modulus <= BGC_FP64_SQUARE_EPSILON) { // unit_start and unit_end are co-directional, angle = 180 degrees if (dot_product >= 0.0) { - quaternion->s0 = 1.0; - quaternion->x1 = 0.0; - quaternion->x2 = 0.0; - quaternion->x3 = 0.0; + quaternion->s = 1.0; + quaternion->x = 0.0; + quaternion->y = 0.0; + quaternion->z = 0.0; return; } // unit_start and unit_end are opposite, angle = 180 degrees - quaternion->s0 = 0.0; - quaternion->x1 = unit_orthogonal->x1; - quaternion->x2 = unit_orthogonal->x2; - quaternion->x3 = unit_orthogonal->x3; + quaternion->s = 0.0; + quaternion->x = unit_orthogonal->x; + quaternion->y = unit_orthogonal->y; + quaternion->z = unit_orthogonal->z; return; } @@ -394,10 +394,10 @@ static inline void _bgc_fp64_turn3_get_turning_quaternion(BGC_FP64_Quaternion* c const double multiplier = sin(angle) / axis_modulus; - quaternion->s0 = cos(angle); - quaternion->x1 = axis.x1 * multiplier; - quaternion->x2 = axis.x2 * multiplier; - quaternion->x3 = axis.x3 * multiplier; + quaternion->s = cos(angle); + quaternion->x = axis.x * multiplier; + quaternion->y = axis.y * multiplier; + quaternion->z = axis.z * multiplier; } // ============ Make Pair Difference ============ // @@ -492,7 +492,7 @@ int bgc_fp64_turn3_find_pair_difference( void bgc_fp32_turn3_get_power(BGC_FP32_Turn3* const power, const BGC_FP32_Turn3* const base, const float exponent) { - const float square_vector = base->_versor.x1 * base->_versor.x1 + base->_versor.x2 * base->_versor.x2 + base->_versor.x3 * base->_versor.x3; + const float square_vector = base->_versor.x * base->_versor.x + base->_versor.y * base->_versor.y + base->_versor.z * base->_versor.z; if (square_vector <= BGC_FP32_SQUARE_EPSILON || square_vector != square_vector) { bgc_fp32_turn3_reset(power); @@ -501,16 +501,16 @@ void bgc_fp32_turn3_get_power(BGC_FP32_Turn3* const power, const BGC_FP32_Turn3* const float vector_modulus = sqrtf(square_vector); - const float angle = atan2f(vector_modulus, base->_versor.s0) * exponent; + const float angle = atan2f(vector_modulus, base->_versor.s) * exponent; const float multiplier = sinf(angle) / vector_modulus; - bgc_fp32_turn3_set_values(power, cosf(angle), base->_versor.x1 * multiplier, base->_versor.x2 * multiplier, base->_versor.x3 * multiplier); + bgc_fp32_turn3_set_values(power, cosf(angle), base->_versor.x * multiplier, base->_versor.y * multiplier, base->_versor.z * multiplier); } void bgc_fp64_turn3_get_power(BGC_FP64_Turn3* const power, const BGC_FP64_Turn3* const base, const double exponent) { - const double square_vector = base->_versor.x1 * base->_versor.x1 + base->_versor.x2 * base->_versor.x2 + base->_versor.x3 * base->_versor.x3; + const double square_vector = base->_versor.x * base->_versor.x + base->_versor.y * base->_versor.y + base->_versor.z * base->_versor.z; if (square_vector <= BGC_FP64_SQUARE_EPSILON || square_vector != square_vector) { bgc_fp64_turn3_reset(power); @@ -519,23 +519,23 @@ void bgc_fp64_turn3_get_power(BGC_FP64_Turn3* const power, const BGC_FP64_Turn3* const double vector_modulus = sqrt(square_vector); - const double angle = atan2(vector_modulus, base->_versor.s0) * exponent; + const double angle = atan2(vector_modulus, base->_versor.s) * exponent; const double multiplier = sin(angle) / vector_modulus; - bgc_fp64_turn3_set_values(power, cos(angle), base->_versor.x1 * multiplier, base->_versor.x2 * multiplier, base->_versor.x3 * multiplier); + bgc_fp64_turn3_set_values(power, cos(angle), base->_versor.x * multiplier, base->_versor.y * multiplier, base->_versor.z * multiplier); } // ============ Sphere Interpolation ============ // void bgc_fp32_turn3_spherically_interpolate(BGC_FP32_Turn3* const interpolation, const BGC_FP32_Turn3* const start, const BGC_FP32_Turn3* const end, const float phase) { - const float delta_s0 = (end->_versor.s0 * start->_versor.s0 + end->_versor.x1 * start->_versor.x1) + (end->_versor.x2 * start->_versor.x2 + end->_versor.x3 * start->_versor.x3); - const float delta_x1 = (end->_versor.x1 * start->_versor.s0 + end->_versor.x3 * start->_versor.x2) - (end->_versor.s0 * start->_versor.x1 + end->_versor.x2 * start->_versor.x3); - const float delta_x2 = (end->_versor.x2 * start->_versor.s0 + end->_versor.x1 * start->_versor.x3) - (end->_versor.s0 * start->_versor.x2 + end->_versor.x3 * start->_versor.x1); - const float delta_x3 = (end->_versor.x3 * start->_versor.s0 + end->_versor.x2 * start->_versor.x1) - (end->_versor.s0 * start->_versor.x3 + end->_versor.x1 * start->_versor.x2); + const float delta_s = (end->_versor.s * start->_versor.s + end->_versor.x * start->_versor.x) + (end->_versor.y * start->_versor.y + end->_versor.z * start->_versor.z); + const float delta_x = (end->_versor.x * start->_versor.s + end->_versor.z * start->_versor.y) - (end->_versor.s * start->_versor.x + end->_versor.y * start->_versor.z); + const float delta_y = (end->_versor.y * start->_versor.s + end->_versor.x * start->_versor.z) - (end->_versor.s * start->_versor.y + end->_versor.z * start->_versor.x); + const float delta_z = (end->_versor.z * start->_versor.s + end->_versor.y * start->_versor.x) - (end->_versor.s * start->_versor.z + end->_versor.x * start->_versor.y); - const float square_vector = delta_x1 * delta_x1 + delta_x2 * delta_x2 + delta_x3 * delta_x3; + const float square_vector = delta_x * delta_x + delta_y * delta_y + delta_z * delta_z; // square_vector != square_vector means checking for NaN value at square_vector if (square_vector <= BGC_FP32_SQUARE_EPSILON || isnan(square_vector)) { @@ -545,32 +545,32 @@ void bgc_fp32_turn3_spherically_interpolate(BGC_FP32_Turn3* const interpolation, // Calculating of the turning which fits the phase: const float vector_modulus = sqrtf(square_vector); - const float angle = atan2f(vector_modulus, delta_s0) * phase; + const float angle = atan2f(vector_modulus, delta_s) * phase; const float multiplier = sinf(angle) / vector_modulus; - const float turn_s0 = cosf(angle); - const float turn_x1 = delta_x1 * multiplier; - const float turn_x2 = delta_x2 * multiplier; - const float turn_x3 = delta_x3 * multiplier; + const float turn_s = cosf(angle); + const float turn_x = delta_x * multiplier; + const float turn_y = delta_y * multiplier; + const float turn_z = delta_z * multiplier; // Combining of starting orientation with the turning bgc_fp32_turn3_set_values( interpolation, - (turn_s0 * start->_versor.s0 - turn_x1 * start->_versor.x1) - (turn_x2 * start->_versor.x2 + turn_x3 * start->_versor.x3), - (turn_x1 * start->_versor.s0 + turn_s0 * start->_versor.x1) - (turn_x3 * start->_versor.x2 - turn_x2 * start->_versor.x3), - (turn_x2 * start->_versor.s0 + turn_s0 * start->_versor.x2) - (turn_x1 * start->_versor.x3 - turn_x3 * start->_versor.x1), - (turn_x3 * start->_versor.s0 + turn_s0 * start->_versor.x3) - (turn_x2 * start->_versor.x1 - turn_x1 * start->_versor.x2) + (turn_s * start->_versor.s - turn_x * start->_versor.x) - (turn_y * start->_versor.y + turn_z * start->_versor.z), + (turn_x * start->_versor.s + turn_s * start->_versor.x) - (turn_z * start->_versor.y - turn_y * start->_versor.z), + (turn_y * start->_versor.s + turn_s * start->_versor.y) - (turn_x * start->_versor.z - turn_z * start->_versor.x), + (turn_z * start->_versor.s + turn_s * start->_versor.z) - (turn_y * start->_versor.x - turn_x * start->_versor.y) ); } void bgc_fp64_turn3_spherically_interpolate(BGC_FP64_Turn3* const interpolation, const BGC_FP64_Turn3* const start, const BGC_FP64_Turn3* const end, const double phase) { - const double delta_s0 = (end->_versor.s0 * start->_versor.s0 + end->_versor.x1 * start->_versor.x1) + (end->_versor.x2 * start->_versor.x2 + end->_versor.x3 * start->_versor.x3); - const double delta_x1 = (end->_versor.x1 * start->_versor.s0 + end->_versor.x3 * start->_versor.x2) - (end->_versor.s0 * start->_versor.x1 + end->_versor.x2 * start->_versor.x3); - const double delta_x2 = (end->_versor.x2 * start->_versor.s0 + end->_versor.x1 * start->_versor.x3) - (end->_versor.s0 * start->_versor.x2 + end->_versor.x3 * start->_versor.x1); - const double delta_x3 = (end->_versor.x3 * start->_versor.s0 + end->_versor.x2 * start->_versor.x1) - (end->_versor.s0 * start->_versor.x3 + end->_versor.x1 * start->_versor.x2); + const double delta_s = (end->_versor.s * start->_versor.s + end->_versor.x * start->_versor.x) + (end->_versor.y * start->_versor.y + end->_versor.z * start->_versor.z); + const double delta_x = (end->_versor.x * start->_versor.s + end->_versor.z * start->_versor.y) - (end->_versor.s * start->_versor.x + end->_versor.y * start->_versor.z); + const double delta_y = (end->_versor.y * start->_versor.s + end->_versor.x * start->_versor.z) - (end->_versor.s * start->_versor.y + end->_versor.z * start->_versor.x); + const double delta_z = (end->_versor.z * start->_versor.s + end->_versor.y * start->_versor.x) - (end->_versor.s * start->_versor.z + end->_versor.x * start->_versor.y); - const double square_vector = delta_x1 * delta_x1 + delta_x2 * delta_x2 + delta_x3 * delta_x3; + const double square_vector = delta_x * delta_x + delta_y * delta_y + delta_z * delta_z; // square_vector != square_vector means checking for NaN value at square_vector if (square_vector <= BGC_FP64_SQUARE_EPSILON || isnan(square_vector)) { @@ -580,20 +580,20 @@ void bgc_fp64_turn3_spherically_interpolate(BGC_FP64_Turn3* const interpolation, // Calculating of the turning which fits the phase: const double vector_modulus = sqrt(square_vector); - const double angle = atan2(vector_modulus, delta_s0) * phase; + const double angle = atan2(vector_modulus, delta_s) * phase; const double multiplier = sin(angle) / vector_modulus; - const double turn_s0 = cos(angle); - const double turn_x1 = delta_x1 * multiplier; - const double turn_x2 = delta_x2 * multiplier; - const double turn_x3 = delta_x3 * multiplier; + const double turn_s = cos(angle); + const double turn_x = delta_x * multiplier; + const double turn_y = delta_y * multiplier; + const double turn_z = delta_z * multiplier; // Combining of starting orientation with the turning bgc_fp64_turn3_set_values( interpolation, - (turn_s0 * start->_versor.s0 - turn_x1 * start->_versor.x1) - (turn_x2 * start->_versor.x2 + turn_x3 * start->_versor.x3), - (turn_x1 * start->_versor.s0 + turn_s0 * start->_versor.x1) - (turn_x3 * start->_versor.x2 - turn_x2 * start->_versor.x3), - (turn_x2 * start->_versor.s0 + turn_s0 * start->_versor.x2) - (turn_x1 * start->_versor.x3 - turn_x3 * start->_versor.x1), - (turn_x3 * start->_versor.s0 + turn_s0 * start->_versor.x3) - (turn_x2 * start->_versor.x1 - turn_x1 * start->_versor.x2) + (turn_s * start->_versor.s - turn_x * start->_versor.x) - (turn_y * start->_versor.y + turn_z * start->_versor.z), + (turn_x * start->_versor.s + turn_s * start->_versor.x) - (turn_z * start->_versor.y - turn_y * start->_versor.z), + (turn_y * start->_versor.s + turn_s * start->_versor.y) - (turn_x * start->_versor.z - turn_z * start->_versor.x), + (turn_z * start->_versor.s + turn_s * start->_versor.z) - (turn_y * start->_versor.x - turn_x * start->_versor.y) ); } diff --git a/basic-geometry/turn3.h b/basic-geometry/turn3.h index 4fffe15..2e8f231 100644 --- a/basic-geometry/turn3.h +++ b/basic-geometry/turn3.h @@ -36,18 +36,18 @@ extern const BGC_FP64_Turn3 BGC_FP64_IDLE_TURN3; inline void bgc_fp32_turn3_reset(BGC_FP32_Turn3* const turn) { - turn->_versor.s0 = 1.0f; - turn->_versor.x1 = 0.0f; - turn->_versor.x2 = 0.0f; - turn->_versor.x3 = 0.0f; + turn->_versor.s = 1.0f; + turn->_versor.x = 0.0f; + turn->_versor.y = 0.0f; + turn->_versor.z = 0.0f; } inline void bgc_fp64_turn3_reset(BGC_FP64_Turn3* const turn) { - turn->_versor.s0 = 1.0; - turn->_versor.x1 = 0.0; - turn->_versor.x2 = 0.0; - turn->_versor.x3 = 0.0; + turn->_versor.s = 1.0; + turn->_versor.x = 0.0; + turn->_versor.y = 0.0; + turn->_versor.z = 0.0; } // ============= Private: Normalize ============= // @@ -61,19 +61,19 @@ inline void _bgc_fp32_turn3_normalize(BGC_FP32_Turn3* const turn) } if (square_magnitude <= BGC_FP32_SQUARE_EPSILON || isnan(square_magnitude)) { - turn->_versor.s0 = 1.0f; - turn->_versor.x1 = 0.0f; - turn->_versor.x2 = 0.0f; - turn->_versor.x3 = 0.0f; + turn->_versor.s = 1.0f; + turn->_versor.x = 0.0f; + turn->_versor.y = 0.0f; + turn->_versor.z = 0.0f; return; } const float multiplier = sqrtf(1.0f / square_magnitude); - turn->_versor.s0 *= multiplier; - turn->_versor.x1 *= multiplier; - turn->_versor.x2 *= multiplier; - turn->_versor.x3 *= multiplier; + turn->_versor.s *= multiplier; + turn->_versor.x *= multiplier; + turn->_versor.y *= multiplier; + turn->_versor.z *= multiplier; } inline void _bgc_fp64_turn3_normalize(BGC_FP64_Turn3* const turn) @@ -85,32 +85,32 @@ inline void _bgc_fp64_turn3_normalize(BGC_FP64_Turn3* const turn) } if (square_magnitude <= BGC_FP64_SQUARE_EPSILON || isnan(square_magnitude)) { - turn->_versor.s0 = 1.0; - turn->_versor.x1 = 0.0; - turn->_versor.x2 = 0.0; - turn->_versor.x3 = 0.0; + turn->_versor.s = 1.0; + turn->_versor.x = 0.0; + turn->_versor.y = 0.0; + turn->_versor.z = 0.0; return; } const double multiplier = sqrt(1.0 / square_magnitude); - turn->_versor.s0 *= multiplier; - turn->_versor.x1 *= multiplier; - turn->_versor.x2 *= multiplier; - turn->_versor.x3 *= multiplier; + turn->_versor.s *= multiplier; + turn->_versor.x *= multiplier; + turn->_versor.y *= multiplier; + turn->_versor.z *= multiplier; } // ================= Set Values ================= // -inline void bgc_fp32_turn3_set_values(BGC_FP32_Turn3* const turn, const float s0, const float x1, const float x2, const float x3) +inline void bgc_fp32_turn3_set_values(BGC_FP32_Turn3* const turn, const float s, const float x, const float y, const float z) { - bgc_fp32_quaternion_set_values(&turn->_versor, s0, x1, x2, x3); + bgc_fp32_quaternion_set_values(&turn->_versor, s, x, y, z); _bgc_fp32_turn3_normalize(turn); } -inline void bgc_fp64_turn3_set_values(BGC_FP64_Turn3* const turn, const double s0, const double x1, const double x2, const double x3) +inline void bgc_fp64_turn3_set_values(BGC_FP64_Turn3* const turn, const double s, const double x, const double y, const double z) { - bgc_fp64_quaternion_set_values(&turn->_versor, s0, x1, x2, x3); + bgc_fp64_quaternion_set_values(&turn->_versor, s, x, y, z); _bgc_fp64_turn3_normalize(turn); } @@ -148,9 +148,9 @@ double bgc_fp64_turn3_get_rotation(BGC_FP64_Vector3* const axis, const BGC_FP64_ // ================ Set Rotation ================ // -void bgc_fp32_turn3_set_rotation(BGC_FP32_Turn3* const turn, const float x1, const float x2, const float x3, const float angle, const int angle_unit); +void bgc_fp32_turn3_set_rotation(BGC_FP32_Turn3* const turn, const float x, const float y, const float z, const float angle, const int angle_unit); -void bgc_fp64_turn3_set_rotation(BGC_FP64_Turn3* const turn, const double x1, const double x2, const double x3, const double angle, const int angle_unit); +void bgc_fp64_turn3_set_rotation(BGC_FP64_Turn3* const turn, const double x, const double y, const double z, const double angle, const int angle_unit); // ========= Find Direction Difference ========== // @@ -231,21 +231,21 @@ inline void bgc_fp64_turn3_convert_to_fp32(BGC_FP32_Turn3* const destination, co inline void bgc_fp32_turn3_shorten(BGC_FP32_Turn3* const turn) { - if (turn->_versor.s0 < 0.0f) { + if (turn->_versor.s < 0.0f) { bgc_fp32_quaternion_revert(&turn->_versor); } } inline void bgc_fp64_turn3_shorten(BGC_FP64_Turn3* const turn) { - if (turn->_versor.s0 < 0.0) { + if (turn->_versor.s < 0.0) { bgc_fp64_quaternion_revert(&turn->_versor); } } inline void bgc_fp32_turn3_get_shortened(BGC_FP32_Turn3* const shortened, const BGC_FP32_Turn3* const turn) { - if (turn->_versor.s0 >= 0.0f) { + if (turn->_versor.s >= 0.0f) { bgc_fp32_quaternion_copy(&shortened->_versor, &turn->_versor); } else { @@ -255,7 +255,7 @@ inline void bgc_fp32_turn3_get_shortened(BGC_FP32_Turn3* const shortened, const inline void bgc_fp64_turn3_get_shortened(BGC_FP64_Turn3* const shortened, const BGC_FP64_Turn3* const turn) { - if (turn->_versor.s0 >= 0.0) { + if (turn->_versor.s >= 0.0) { bgc_fp64_quaternion_copy(&shortened->_versor, &turn->_versor); } else { diff --git a/basic-geometry/types.h b/basic-geometry/types.h index 36c8819..1445d66 100644 --- a/basic-geometry/types.h +++ b/basic-geometry/types.h @@ -5,24 +5,24 @@ typedef struct { - float x1, x2; + float x, y; } BGC_FP32_Vector2; typedef struct { - double x1, x2; + double x, y; } BGC_FP64_Vector2; // ================== Vector3 =================== // typedef struct { - float x1, x2, x3; + float x, y, z; } BGC_FP32_Vector3; typedef struct { - double x1, x2, x3; + double x, y, z; } BGC_FP64_Vector3; // ================== Matrix2x2 ================= // @@ -128,11 +128,11 @@ typedef struct // ================= Quaternion ================= // typedef struct { - float s0, x1, x2, x3; + float s, x, y, z; } BGC_FP32_Quaternion; typedef struct { - double s0, x1, x2, x3; + double s, x, y, z; } BGC_FP64_Quaternion; // =================== Turn3 ==================== // diff --git a/basic-geometry/vector2.c b/basic-geometry/vector2.c index 0ef178c..ff857b0 100644 --- a/basic-geometry/vector2.c +++ b/basic-geometry/vector2.c @@ -3,8 +3,8 @@ extern inline void bgc_fp32_vector2_reset(BGC_FP32_Vector2* const vector); extern inline void bgc_fp64_vector2_reset(BGC_FP64_Vector2* const vector); -extern inline void bgc_fp32_vector2_set_values(BGC_FP32_Vector2* const destination, const float x1, const float x2); -extern inline void bgc_fp64_vector2_set_values(BGC_FP64_Vector2* const destination, const double x1, const double x2); +extern inline void bgc_fp32_vector2_set_values(BGC_FP32_Vector2* const destination, const float x, const float y); +extern inline void bgc_fp64_vector2_set_values(BGC_FP64_Vector2* const destination, const double x, const double y); extern inline float bgc_fp32_vector2_get_squared_length(const BGC_FP32_Vector2* const vector); extern inline double bgc_fp64_vector2_get_squared_length(const BGC_FP64_Vector2* const vector); diff --git a/basic-geometry/vector2.h b/basic-geometry/vector2.h index 1daadde..fc95607 100644 --- a/basic-geometry/vector2.h +++ b/basic-geometry/vector2.h @@ -11,40 +11,40 @@ inline void bgc_fp32_vector2_reset(BGC_FP32_Vector2* const vector) { - vector->x1 = 0.0f; - vector->x2 = 0.0f; + vector->x = 0.0f; + vector->y = 0.0f; } inline void bgc_fp64_vector2_reset(BGC_FP64_Vector2* const vector) { - vector->x1 = 0.0; - vector->x2 = 0.0; + vector->x = 0.0; + vector->y = 0.0; } // ==================== Set ===================== // -inline void bgc_fp32_vector2_set_values(BGC_FP32_Vector2* const destination, const float x1, const float x2) +inline void bgc_fp32_vector2_set_values(BGC_FP32_Vector2* const destination, const float x, const float y) { - destination->x1 = x1; - destination->x2 = x2; + destination->x = x; + destination->y = y; } -inline void bgc_fp64_vector2_set_values(BGC_FP64_Vector2* const destination, const double x1, const double x2) +inline void bgc_fp64_vector2_set_values(BGC_FP64_Vector2* const destination, const double x, const double y) { - destination->x1 = x1; - destination->x2 = x2; + destination->x = x; + destination->y = y; } // ================== Modulus =================== // inline float bgc_fp32_vector2_get_squared_length(const BGC_FP32_Vector2* const vector) { - return vector->x1 * vector->x1 + vector->x2 * vector->x2; + return vector->x * vector->x + vector->y * vector->y; } inline double bgc_fp64_vector2_get_squared_length(const BGC_FP64_Vector2* const vector) { - return vector->x1 * vector->x1 + vector->x2 * vector->x2; + return vector->x * vector->x + vector->y * vector->y; } inline float bgc_fp32_vector2_get_length(const BGC_FP32_Vector2* const vector) @@ -83,160 +83,160 @@ inline int bgc_fp64_vector2_is_unit(const BGC_FP64_Vector2* const vector) inline void bgc_fp32_vector2_copy(BGC_FP32_Vector2* const destination, const BGC_FP32_Vector2* const source) { - destination->x1 = source->x1; - destination->x2 = source->x2; + destination->x = source->x; + destination->y = source->y; } inline void bgc_fp64_vector2_copy(BGC_FP64_Vector2* const destination, const BGC_FP64_Vector2* const source) { - destination->x1 = source->x1; - destination->x2 = source->x2; + destination->x = source->x; + destination->y = source->y; } // ==================== Swap ==================== // inline void bgc_fp32_vector2_swap(BGC_FP32_Vector2* const vector1, BGC_FP32_Vector2* const vector2) { - const float x1 = vector2->x1; - const float x2 = vector2->x2; + const float x = vector2->x; + const float y = vector2->y; - vector2->x1 = vector1->x1; - vector2->x2 = vector1->x2; + vector2->x = vector1->x; + vector2->y = vector1->y; - vector1->x1 = x1; - vector1->x2 = x2; + vector1->x = x; + vector1->y = y; } inline void bgc_fp64_vector2_swap(BGC_FP64_Vector2* const vector1, BGC_FP64_Vector2* const vector2) { - const double x1 = vector2->x1; - const double x2 = vector2->x2; + const double x = vector2->x; + const double y = vector2->y; - vector2->x1 = vector1->x1; - vector2->x2 = vector1->x2; + vector2->x = vector1->x; + vector2->y = vector1->y; - vector1->x1 = x1; - vector1->x2 = x2; + vector1->x = x; + vector1->y = y; } // ================== Convert =================== // inline void bgc_fp32_vector2_convert_to_fp64(BGC_FP64_Vector2* const destination, const BGC_FP32_Vector2* const source) { - destination->x1 = source->x1; - destination->x2 = source->x2; + destination->x = source->x; + destination->y = source->y; } inline void bgc_fp64_vector2_convert_to_fp32(BGC_FP32_Vector2* const destination, const BGC_FP64_Vector2* const source) { - destination->x1 = (float)source->x1; - destination->x2 = (float)source->x2; + destination->x = (float)source->x; + destination->y = (float)source->y; } // ==================== Add ===================== // inline void bgc_fp32_vector2_add(BGC_FP32_Vector2* const sum, const BGC_FP32_Vector2* const vector1, const BGC_FP32_Vector2* const vector2) { - sum->x1 = vector1->x1 + vector2->x1; - sum->x2 = vector1->x2 + vector2->x2; + sum->x = vector1->x + vector2->x; + sum->y = vector1->y + vector2->y; } inline void bgc_fp64_vector2_add(BGC_FP64_Vector2* const sum, const BGC_FP64_Vector2* const vector1, const BGC_FP64_Vector2* const vector2) { - sum->x1 = vector1->x1 + vector2->x1; - sum->x2 = vector1->x2 + vector2->x2; + sum->x = vector1->x + vector2->x; + sum->y = vector1->y + vector2->y; } // ================= Add Scaled ================= // inline void bgc_fp32_vector2_add_scaled(BGC_FP32_Vector2* const sum, const BGC_FP32_Vector2* const basic_vector, const BGC_FP32_Vector2* const scalable_vector, const float scale) { - sum->x1 = basic_vector->x1 + scalable_vector->x1 * scale; - sum->x2 = basic_vector->x2 + scalable_vector->x2 * scale; + sum->x = basic_vector->x + scalable_vector->x * scale; + sum->y = basic_vector->y + scalable_vector->y * scale; } inline void bgc_fp64_vector2_add_scaled(BGC_FP64_Vector2* const sum, const BGC_FP64_Vector2* const basic_vector, const BGC_FP64_Vector2* const scalable_vector, const double scale) { - sum->x1 = basic_vector->x1 + scalable_vector->x1 * scale; - sum->x2 = basic_vector->x2 + scalable_vector->x2 * scale; + sum->x = basic_vector->x + scalable_vector->x * scale; + sum->y = basic_vector->y + scalable_vector->y * scale; } // ================== Subtract ================== // inline void bgc_fp32_vector2_subtract(BGC_FP32_Vector2* const difference, const BGC_FP32_Vector2* const minuend, const BGC_FP32_Vector2* const subtrahend) { - difference->x1 = minuend->x1 - subtrahend->x1; - difference->x2 = minuend->x2 - subtrahend->x2; + difference->x = minuend->x - subtrahend->x; + difference->y = minuend->y - subtrahend->y; } inline void bgc_fp64_vector2_subtract(BGC_FP64_Vector2* const difference, const BGC_FP64_Vector2* const minuend, const BGC_FP64_Vector2* const subtrahend) { - difference->x1 = minuend->x1 - subtrahend->x1; - difference->x2 = minuend->x2 - subtrahend->x2; + difference->x = minuend->x - subtrahend->x; + difference->y = minuend->y - subtrahend->y; } // ============== Subtract Scaled =============== // inline void bgc_fp32_vector2_subtract_scaled(BGC_FP32_Vector2* const difference, const BGC_FP32_Vector2* const basic_vector, const BGC_FP32_Vector2* const scalable_vector, const float scale) { - difference->x1 = basic_vector->x1 - scalable_vector->x1 * scale; - difference->x2 = basic_vector->x2 - scalable_vector->x2 * scale; + difference->x = basic_vector->x - scalable_vector->x * scale; + difference->y = basic_vector->y - scalable_vector->y * scale; } inline void bgc_fp64_vector2_subtract_scaled(BGC_FP64_Vector2* const difference, const BGC_FP64_Vector2* const basic_vector, const BGC_FP64_Vector2* const scalable_vector, const double scale) { - difference->x1 = basic_vector->x1 - scalable_vector->x1 * scale; - difference->x2 = basic_vector->x2 - scalable_vector->x2 * scale; + difference->x = basic_vector->x - scalable_vector->x * scale; + difference->y = basic_vector->y - scalable_vector->y * scale; } // ================== Multiply ================== // inline void bgc_fp32_vector2_multiply_by_real_number(BGC_FP32_Vector2* const product, const BGC_FP32_Vector2* const multiplicand, const float multiplier) { - product->x1 = multiplicand->x1 * multiplier; - product->x2 = multiplicand->x2 * multiplier; + product->x = multiplicand->x * multiplier; + product->y = multiplicand->y * multiplier; } inline void bgc_fp64_vector2_multiply_by_real_number(BGC_FP64_Vector2* const product, const BGC_FP64_Vector2* const multiplicand, const double multiplier) { - product->x1 = multiplicand->x1 * multiplier; - product->x2 = multiplicand->x2 * multiplier; + product->x = multiplicand->x * multiplier; + product->y = multiplicand->y * multiplier; } // ============ Left Vector Product ============= // inline void bgc_fp32_vector2_multiply_by_matrix2x2(BGC_FP32_Vector2* const product, const BGC_FP32_Vector2* const vector, const BGC_FP32_Matrix2x2* const matrix) { - const float x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1; - const float x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2; + const float x = vector->x * matrix->r1c1 + vector->y * matrix->r2c1; + const float y = vector->x * matrix->r1c2 + vector->y * matrix->r2c2; - product->x1 = x1; - product->x2 = x2; + product->x = x; + product->y = y; } inline void bgc_fp64_vector2_multiply_by_matrix2x2(BGC_FP64_Vector2* const product, const BGC_FP64_Vector2* const vector, const BGC_FP64_Matrix2x2* const matrix) { - const double x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1; - const double x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2; + const double x = vector->x * matrix->r1c1 + vector->y * matrix->r2c1; + const double y = vector->x * matrix->r1c2 + vector->y * matrix->r2c2; - product->x1 = x1; - product->x2 = x2; + product->x = x; + product->y = y; } // ============ Left Vector Product ============= // inline void bgc_fp32_vector2_multiply_by_matrix3x2(BGC_FP32_Vector3* const product, const BGC_FP32_Vector2* const vector, const BGC_FP32_Matrix3x2* const matrix) { - product->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1; - product->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2; - product->x3 = vector->x1 * matrix->r1c3 + vector->x2 * matrix->r2c3; + product->x = vector->x * matrix->r1c1 + vector->y * matrix->r2c1; + product->y = vector->x * matrix->r1c2 + vector->y * matrix->r2c2; + product->z = vector->x * matrix->r1c3 + vector->y * matrix->r2c3; } inline void bgc_fp64_vector2_multiply_by_matrix3x2(BGC_FP64_Vector3* const product, const BGC_FP64_Vector2* const vector, const BGC_FP64_Matrix3x2* const matrix) { - product->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1; - product->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2; - product->x3 = vector->x1 * matrix->r1c3 + vector->x2 * matrix->r2c3; + product->x = vector->x * matrix->r1c1 + vector->y * matrix->r2c1; + product->y = vector->x * matrix->r1c2 + vector->y * matrix->r2c2; + product->z = vector->x * matrix->r1c3 + vector->y * matrix->r2c3; } // =================== Divide =================== // @@ -267,28 +267,28 @@ inline int bgc_fp64_vector2_divide_by_real_number(BGC_FP64_Vector2* const quotie inline void bgc_fp32_vector2_get_mean2(BGC_FP32_Vector2* const mean, const BGC_FP32_Vector2* const vector1, const BGC_FP32_Vector2* const vector2) { - mean->x1 = (vector1->x1 + vector2->x1) * 0.5f; - mean->x2 = (vector1->x2 + vector2->x2) * 0.5f; + mean->x = (vector1->x + vector2->x) * 0.5f; + mean->y = (vector1->y + vector2->y) * 0.5f; } inline void bgc_fp64_vector2_get_mean2(BGC_FP64_Vector2* const mean, const BGC_FP64_Vector2* const vector1, const BGC_FP64_Vector2* const vector2) { - mean->x1 = (vector1->x1 + vector2->x1) * 0.5; - mean->x2 = (vector1->x2 + vector2->x2) * 0.5; + mean->x = (vector1->x + vector2->x) * 0.5; + mean->y = (vector1->y + vector2->y) * 0.5; } // =============== Mean of Three ================ // inline void bgc_fp32_vector2_get_mean3(BGC_FP32_Vector2* const mean, const BGC_FP32_Vector2* const vector1, const BGC_FP32_Vector2* const vector2, const BGC_FP32_Vector2* const vector3) { - mean->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BGC_FP32_ONE_THIRD; - mean->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BGC_FP32_ONE_THIRD; + mean->x = (vector1->x + vector2->x + vector3->x) * BGC_FP32_ONE_THIRD; + mean->y = (vector1->y + vector2->y + vector3->y) * BGC_FP32_ONE_THIRD; } inline void bgc_fp64_vector2_get_mean3(BGC_FP64_Vector2* const mean, const BGC_FP64_Vector2* const vector1, const BGC_FP64_Vector2* const vector2, const BGC_FP64_Vector2* const vector3) { - mean->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BGC_FP64_ONE_THIRD; - mean->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BGC_FP64_ONE_THIRD; + mean->x = (vector1->x + vector2->x + vector3->x) * BGC_FP64_ONE_THIRD; + mean->y = (vector1->y + vector2->y + vector3->y) * BGC_FP64_ONE_THIRD; } // =================== Linear =================== // @@ -297,42 +297,42 @@ inline void bgc_fp32_vector2_interpolate(BGC_FP32_Vector2* const interpolation, { const float counter_phase = 1.0f - phase; - interpolation->x1 = first->x1 * counter_phase + second->x1 * phase; - interpolation->x2 = first->x2 * counter_phase + second->x2 * phase; + interpolation->x = first->x * counter_phase + second->x * phase; + interpolation->y = first->y * counter_phase + second->y * phase; } inline void bgc_fp64_vector2_interpolate(BGC_FP64_Vector2* const interpolation, const BGC_FP64_Vector2* const first, const BGC_FP64_Vector2* const second, const double phase) { const double counter_phase = 1.0 - phase; - interpolation->x1 = first->x1 * counter_phase + second->x1 * phase; - interpolation->x2 = first->x2 * counter_phase + second->x2 * phase; + interpolation->x = first->x * counter_phase + second->x * phase; + interpolation->y = first->y * counter_phase + second->y * phase; } // ================== Negative ================== // inline void bgc_fp32_vector2_revert(BGC_FP32_Vector2* const vector) { - vector->x1 = -vector->x1; - vector->x2 = -vector->x2; + vector->x = -vector->x; + vector->y = -vector->y; } inline void bgc_fp64_vector2_revert(BGC_FP64_Vector2* const vector) { - vector->x1 = -vector->x1; - vector->x2 = -vector->x2; + vector->x = -vector->x; + vector->y = -vector->y; } inline void bgc_fp32_vector2_get_reverse(BGC_FP32_Vector2* const reverse, const BGC_FP32_Vector2* const vector) { - reverse->x1 = -vector->x1; - reverse->x2 = -vector->x2; + reverse->x = -vector->x; + reverse->y = -vector->y; } inline void bgc_fp64_vector2_get_reverse(BGC_FP64_Vector2* const reverse, const BGC_FP64_Vector2* const vector) { - reverse->x1 = -vector->x1; - reverse->x2 = -vector->x2; + reverse->x = -vector->x; + reverse->y = -vector->y; } // ================= Normalize ================== // @@ -351,8 +351,8 @@ inline int bgc_fp32_vector2_normalize(BGC_FP32_Vector2* const vector) const float multiplier = sqrtf(1.0f / square_modulus); - vector->x1 *= multiplier; - vector->x2 *= multiplier; + vector->x *= multiplier; + vector->y *= multiplier; return BGC_SUCCESS; } @@ -371,8 +371,8 @@ inline int bgc_fp64_vector2_normalize(BGC_FP64_Vector2* const vector) const double multiplier = sqrt(1.0 / square_modulus); - vector->x1 *= multiplier; - vector->x2 *= multiplier; + vector->x *= multiplier; + vector->y *= multiplier; return BGC_SUCCESS; } @@ -417,24 +417,24 @@ inline int bgc_fp64_vector2_get_normalized(BGC_FP64_Vector2* const normalized, c inline float bgc_fp32_vector2_get_dot_product(const BGC_FP32_Vector2* const vector1, const BGC_FP32_Vector2* const vector2) { - return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2; + return vector1->x * vector2->x + vector1->y * vector2->y; } inline double bgc_fp64_vector2_get_dot_product(const BGC_FP64_Vector2* const vector1, const BGC_FP64_Vector2* const vector2) { - return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2; + return vector1->x * vector2->x + vector1->y * vector2->y; } // ============= Get Cross Product ============== // inline float bgc_fp32_vector2_get_cross_product(const BGC_FP32_Vector2* const vector1, const BGC_FP32_Vector2* const vector2) { - return vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1; + return vector1->x * vector2->y - vector1->y * vector2->x; } inline double bgc_fp64_vector2_get_cross_product(const BGC_FP64_Vector2* const vector1, const BGC_FP64_Vector2* const vector2) { - return vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1; + return vector1->x * vector2->y - vector1->y * vector2->x; } // ================= Get Angle ================== // @@ -447,18 +447,18 @@ double bgc_fp64_vector2_get_angle(const BGC_FP64_Vector2* const vector1, const B inline float bgc_fp32_vector2_get_square_distance(const BGC_FP32_Vector2* const vector1, const BGC_FP32_Vector2* const vector2) { - const float dx1 = vector1->x1 - vector2->x1; - const float dx2 = vector1->x2 - vector2->x2; + const float dx = vector1->x - vector2->x; + const float dy = vector1->y - vector2->y; - return dx1 * dx1 + dx2 * dx2; + return dx * dx + dy * dy; } inline double bgc_fp64_vector2_get_square_distance(const BGC_FP64_Vector2* const vector1, const BGC_FP64_Vector2* const vector2) { - const double dx1 = vector1->x1 - vector2->x1; - const double dx2 = vector1->x2 - vector2->x2; + const double dx = vector1->x - vector2->x; + const double dy = vector1->y - vector2->y; - return dx1 * dx1 + dx2 * dx2; + return dx * dx + dy * dy; } // ================== Distance ================== // diff --git a/basic-geometry/vector3.c b/basic-geometry/vector3.c index a45d9c3..e75be1f 100644 --- a/basic-geometry/vector3.c +++ b/basic-geometry/vector3.c @@ -3,8 +3,8 @@ extern inline void bgc_fp32_vector3_reset(BGC_FP32_Vector3* const vector); extern inline void bgc_fp64_vector3_reset(BGC_FP64_Vector3* const vector); -extern inline void bgc_fp32_vector3_set_values(BGC_FP32_Vector3* const destination, const float x1, const float x2, const float x3); -extern inline void bgc_fp64_vector3_set_values(BGC_FP64_Vector3* const destination, const double x1, const double x2, const double x3); +extern inline void bgc_fp32_vector3_set_values(BGC_FP32_Vector3* const destination, const float x, const float y, const float z); +extern inline void bgc_fp64_vector3_set_values(BGC_FP64_Vector3* const destination, const double x, const double y, const double z); extern inline float bgc_fp32_vector3_get_squared_length(const BGC_FP32_Vector3* const vector); extern inline double bgc_fp64_vector3_get_squared_length(const BGC_FP64_Vector3* const vector); diff --git a/basic-geometry/vector3.h b/basic-geometry/vector3.h index a006a91..db3174f 100644 --- a/basic-geometry/vector3.h +++ b/basic-geometry/vector3.h @@ -11,44 +11,44 @@ inline void bgc_fp32_vector3_reset(BGC_FP32_Vector3* const vector) { - vector->x1 = 0.0f; - vector->x2 = 0.0f; - vector->x3 = 0.0f; + vector->x = 0.0f; + vector->y = 0.0f; + vector->z = 0.0f; } inline void bgc_fp64_vector3_reset(BGC_FP64_Vector3* const vector) { - vector->x1 = 0.0; - vector->x2 = 0.0; - vector->x3 = 0.0; + vector->x = 0.0; + vector->y = 0.0; + vector->z = 0.0; } // ==================== Set ===================== // -inline void bgc_fp32_vector3_set_values(BGC_FP32_Vector3* const destination, const float x1, const float x2, const float x3) +inline void bgc_fp32_vector3_set_values(BGC_FP32_Vector3* const destination, const float x, const float y, const float z) { - destination->x1 = x1; - destination->x2 = x2; - destination->x3 = x3; + destination->x = x; + destination->y = y; + destination->z = z; } -inline void bgc_fp64_vector3_set_values(BGC_FP64_Vector3* const destination, const double x1, const double x2, const double x3) +inline void bgc_fp64_vector3_set_values(BGC_FP64_Vector3* const destination, const double x, const double y, const double z) { - destination->x1 = x1; - destination->x2 = x2; - destination->x3 = x3; + destination->x = x; + destination->y = y; + destination->z = z; } // ================== Modulus =================== // inline float bgc_fp32_vector3_get_squared_length(const BGC_FP32_Vector3* const vector) { - return vector->x1 * vector->x1 + vector->x2 * vector->x2 + vector->x3 * vector->x3; + return vector->x * vector->x + vector->y * vector->y + vector->z * vector->z; } inline double bgc_fp64_vector3_get_squared_length(const BGC_FP64_Vector3* const vector) { - return vector->x1 * vector->x1 + vector->x2 * vector->x2 + vector->x3 * vector->x3; + return vector->x * vector->x + vector->y * vector->y + vector->z * vector->z; } inline float bgc_fp32_vector3_get_length(const BGC_FP32_Vector3* const vector) @@ -87,246 +87,246 @@ inline int bgc_fp64_vector3_is_unit(const BGC_FP64_Vector3* const vector) inline void bgc_fp32_vector3_copy(BGC_FP32_Vector3* const destination, const BGC_FP32_Vector3* const source) { - destination->x1 = source->x1; - destination->x2 = source->x2; - destination->x3 = source->x3; + destination->x = source->x; + destination->y = source->y; + destination->z = source->z; } inline void bgc_fp64_vector3_copy(BGC_FP64_Vector3* const destination, const BGC_FP64_Vector3* const source) { - destination->x1 = source->x1; - destination->x2 = source->x2; - destination->x3 = source->x3; + destination->x = source->x; + destination->y = source->y; + destination->z = source->z; } // ==================== Swap ==================== // inline void bgc_fp32_vector3_swap(BGC_FP32_Vector3* const vector1, BGC_FP32_Vector3* const vector2) { - const float x1 = vector2->x1; - const float x2 = vector2->x2; - const float x3 = vector2->x3; + const float x = vector2->x; + const float y = vector2->y; + const float z = vector2->z; - vector2->x1 = vector1->x1; - vector2->x2 = vector1->x2; - vector2->x3 = vector1->x3; + vector2->x = vector1->x; + vector2->y = vector1->y; + vector2->z = vector1->z; - vector1->x1 = x1; - vector1->x2 = x2; - vector1->x3 = x3; + vector1->x = x; + vector1->y = y; + vector1->z = z; } inline void bgc_fp64_vector3_swap(BGC_FP64_Vector3* const vector1, BGC_FP64_Vector3* const vector2) { - const double x1 = vector2->x1; - const double x2 = vector2->x2; - const double x3 = vector2->x3; + const double x = vector2->x; + const double y = vector2->y; + const double z = vector2->z; - vector2->x1 = vector1->x1; - vector2->x2 = vector1->x2; - vector2->x3 = vector1->x3; + vector2->x = vector1->x; + vector2->y = vector1->y; + vector2->z = vector1->z; - vector1->x1 = x1; - vector1->x2 = x2; - vector1->x3 = x3; + vector1->x = x; + vector1->y = y; + vector1->z = z; } // ================== Convert =================== // inline void bgc_fp32_vector3_convert_to_fp64(BGC_FP64_Vector3* const destination, const BGC_FP32_Vector3* const source) { - destination->x1 = source->x1; - destination->x2 = source->x2; - destination->x3 = source->x3; + destination->x = source->x; + destination->y = source->y; + destination->z = source->z; } inline void bgc_fp64_vector3_convert_to_fp32(BGC_FP32_Vector3* const destination, const BGC_FP64_Vector3* const source) { - destination->x1 = (float)source->x1; - destination->x2 = (float)source->x2; - destination->x3 = (float)source->x3; + destination->x = (float)source->x; + destination->y = (float)source->y; + destination->z = (float)source->z; } // ==================== Add ===================== // inline void bgc_fp32_vector3_add(BGC_FP32_Vector3* const sum, const BGC_FP32_Vector3* const vector1, const BGC_FP32_Vector3* const vector2) { - sum->x1 = vector1->x1 + vector2->x1; - sum->x2 = vector1->x2 + vector2->x2; - sum->x3 = vector1->x3 + vector2->x3; + sum->x = vector1->x + vector2->x; + sum->y = vector1->y + vector2->y; + sum->z = vector1->z + vector2->z; } inline void bgc_fp64_vector3_add(BGC_FP64_Vector3* const sum, const BGC_FP64_Vector3* const vector1, const BGC_FP64_Vector3* const vector2) { - sum->x1 = vector1->x1 + vector2->x1; - sum->x2 = vector1->x2 + vector2->x2; - sum->x3 = vector1->x3 + vector2->x3; + sum->x = vector1->x + vector2->x; + sum->y = vector1->y + vector2->y; + sum->z = vector1->z + vector2->z; } // ================= Add scaled ================= // inline void bgc_fp32_vector3_add_scaled(BGC_FP32_Vector3* const sum, const BGC_FP32_Vector3* const basic_vector, const BGC_FP32_Vector3* const scalable_vector, const float scale) { - sum->x1 = basic_vector->x1 + scalable_vector->x1 * scale; - sum->x2 = basic_vector->x2 + scalable_vector->x2 * scale; - sum->x3 = basic_vector->x3 + scalable_vector->x3 * scale; + sum->x = basic_vector->x + scalable_vector->x * scale; + sum->y = basic_vector->y + scalable_vector->y * scale; + sum->z = basic_vector->z + scalable_vector->z * scale; } inline void bgc_fp64_vector3_add_scaled(BGC_FP64_Vector3* const sum, const BGC_FP64_Vector3* const basic_vector, const BGC_FP64_Vector3* const scalable_vector, const double scale) { - sum->x1 = basic_vector->x1 + scalable_vector->x1 * scale; - sum->x2 = basic_vector->x2 + scalable_vector->x2 * scale; - sum->x3 = basic_vector->x3 + scalable_vector->x3 * scale; + sum->x = basic_vector->x + scalable_vector->x * scale; + sum->y = basic_vector->y + scalable_vector->y * scale; + sum->z = basic_vector->z + scalable_vector->z * scale; } // ================== Subtract ================== // inline void bgc_fp32_vector3_subtract(BGC_FP32_Vector3* const difference, const BGC_FP32_Vector3* const minuend, const BGC_FP32_Vector3* const subtrahend) { - difference->x1 = minuend->x1 - subtrahend->x1; - difference->x2 = minuend->x2 - subtrahend->x2; - difference->x3 = minuend->x3 - subtrahend->x3; + difference->x = minuend->x - subtrahend->x; + difference->y = minuend->y - subtrahend->y; + difference->z = minuend->z - subtrahend->z; } inline void bgc_fp64_vector3_subtract(BGC_FP64_Vector3* const difference, const BGC_FP64_Vector3* const minuend, const BGC_FP64_Vector3* const subtrahend) { - difference->x1 = minuend->x1 - subtrahend->x1; - difference->x2 = minuend->x2 - subtrahend->x2; - difference->x3 = minuend->x3 - subtrahend->x3; + difference->x = minuend->x - subtrahend->x; + difference->y = minuend->y - subtrahend->y; + difference->z = minuend->z - subtrahend->z; } // ============== Subtract Scaled =============== // inline void bgc_fp32_vector3_subtract_scaled(BGC_FP32_Vector3* const difference, const BGC_FP32_Vector3* const basic_vector, const BGC_FP32_Vector3* const scalable_vector, const float scale) { - difference->x1 = basic_vector->x1 - scalable_vector->x1 * scale; - difference->x2 = basic_vector->x2 - scalable_vector->x2 * scale; - difference->x3 = basic_vector->x3 - scalable_vector->x3 * scale; + difference->x = basic_vector->x - scalable_vector->x * scale; + difference->y = basic_vector->y - scalable_vector->y * scale; + difference->z = basic_vector->z - scalable_vector->z * scale; } inline void bgc_fp64_vector3_subtract_scaled(BGC_FP64_Vector3* const difference, const BGC_FP64_Vector3* const basic_vector, const BGC_FP64_Vector3* const scalable_vector, const double scale) { - difference->x1 = basic_vector->x1 - scalable_vector->x1 * scale; - difference->x2 = basic_vector->x2 - scalable_vector->x2 * scale; - difference->x3 = basic_vector->x3 - scalable_vector->x3 * scale; + difference->x = basic_vector->x - scalable_vector->x * scale; + difference->y = basic_vector->y - scalable_vector->y * scale; + difference->z = basic_vector->z - scalable_vector->z * scale; } // ================== Multiply ================== // inline void bgc_fp32_vector3_multiply_by_real_number(BGC_FP32_Vector3* const product, const BGC_FP32_Vector3* const multiplicand, const float multiplier) { - product->x1 = multiplicand->x1 * multiplier; - product->x2 = multiplicand->x2 * multiplier; - product->x3 = multiplicand->x3 * multiplier; + product->x = multiplicand->x * multiplier; + product->y = multiplicand->y * multiplier; + product->z = multiplicand->z * multiplier; } inline void bgc_fp64_vector3_multiply_by_real_number(BGC_FP64_Vector3* const product, const BGC_FP64_Vector3* const multiplicand, const double multiplier) { - product->x1 = multiplicand->x1 * multiplier; - product->x2 = multiplicand->x2 * multiplier; - product->x3 = multiplicand->x3 * multiplier; + product->x = multiplicand->x * multiplier; + product->y = multiplicand->y * multiplier; + product->z = multiplicand->z * multiplier; } // ========== Multiply by Dual Number =========== // inline void bgc_fp32_vector3_multiply_by_dual_number(BGC_FP32_DualVector3* const product, const BGC_FP32_Vector3* const multiplicand, const BGC_FP32_DualNumber* const multiplier) { - const float real_x1 = multiplicand->x1 * multiplier->real_part; - const float real_x2 = multiplicand->x2 * multiplier->real_part; - const float real_x3 = multiplicand->x3 * multiplier->real_part; + const float real_x = multiplicand->x * multiplier->real_part; + const float real_y = multiplicand->y * multiplier->real_part; + const float real_z = multiplicand->z * multiplier->real_part; - const float dual_x1 = multiplicand->x1 * multiplier->dual_part; - const float dual_x2 = multiplicand->x2 * multiplier->dual_part; - const float dual_x3 = multiplicand->x3 * multiplier->dual_part; + const float dual_x = multiplicand->x * multiplier->dual_part; + const float dual_y = multiplicand->y * multiplier->dual_part; + const float dual_z = multiplicand->z * multiplier->dual_part; - product->real_part.x1 = real_x1; - product->real_part.x2 = real_x2; - product->real_part.x3 = real_x3; + product->real_part.x = real_x; + product->real_part.y = real_y; + product->real_part.z = real_z; - product->dual_part.x1 = dual_x1; - product->dual_part.x2 = dual_x2; - product->dual_part.x3 = dual_x3; + product->dual_part.x = dual_x; + product->dual_part.y = dual_y; + product->dual_part.z = dual_z; } inline void bgc_fp64_vector3_multiply_by_dual_number(BGC_FP64_DualVector3* const product, const BGC_FP64_Vector3* const multiplicand, const BGC_FP64_DualNumber* const multiplier) { - const double real_x1 = multiplicand->x1 * multiplier->real_part; - const double real_x2 = multiplicand->x2 * multiplier->real_part; - const double real_x3 = multiplicand->x3 * multiplier->real_part; + const double real_x = multiplicand->x * multiplier->real_part; + const double real_y = multiplicand->y * multiplier->real_part; + const double real_z = multiplicand->z * multiplier->real_part; - const double dual_x1 = multiplicand->x1 * multiplier->dual_part; - const double dual_x2 = multiplicand->x2 * multiplier->dual_part; - const double dual_x3 = multiplicand->x3 * multiplier->dual_part; + const double dual_x = multiplicand->x * multiplier->dual_part; + const double dual_y = multiplicand->y * multiplier->dual_part; + const double dual_z = multiplicand->z * multiplier->dual_part; - product->real_part.x1 = real_x1; - product->real_part.x2 = real_x2; - product->real_part.x3 = real_x3; + product->real_part.x = real_x; + product->real_part.y = real_y; + product->real_part.z = real_z; - product->dual_part.x1 = dual_x1; - product->dual_part.x2 = dual_x2; - product->dual_part.x3 = dual_x3; + product->dual_part.x = dual_x; + product->dual_part.y = dual_y; + product->dual_part.z = dual_z; } // ====== Restrict Multiply by Dual Number ====== // inline void _bgc_fp32_restrict_vector3_multiply_by_dual_number(BGC_FP32_DualVector3* restrict const product, const BGC_FP32_Vector3* const multiplicand, const BGC_FP32_DualNumber* const multiplier) { - product->real_part.x1 = multiplicand->x1 * multiplier->real_part; - product->real_part.x2 = multiplicand->x2 * multiplier->real_part; - product->real_part.x3 = multiplicand->x3 * multiplier->real_part; + product->real_part.x = multiplicand->x * multiplier->real_part; + product->real_part.y = multiplicand->y * multiplier->real_part; + product->real_part.z = multiplicand->z * multiplier->real_part; - product->dual_part.x1 = multiplicand->x1 * multiplier->dual_part; - product->dual_part.x2 = multiplicand->x2 * multiplier->dual_part; - product->dual_part.x3 = multiplicand->x3 * multiplier->dual_part; + product->dual_part.x = multiplicand->x * multiplier->dual_part; + product->dual_part.y = multiplicand->y * multiplier->dual_part; + product->dual_part.z = multiplicand->z * multiplier->dual_part; } inline void _bgc_fp64_restrict_vector3_multiply_by_dual_number(BGC_FP64_DualVector3* restrict const product, const BGC_FP64_Vector3* const multiplicand, const BGC_FP64_DualNumber* const multiplier) { - product->real_part.x1 = multiplicand->x1 * multiplier->real_part; - product->real_part.x2 = multiplicand->x2 * multiplier->real_part; - product->real_part.x3 = multiplicand->x3 * multiplier->real_part; + product->real_part.x = multiplicand->x * multiplier->real_part; + product->real_part.y = multiplicand->y * multiplier->real_part; + product->real_part.z = multiplicand->z * multiplier->real_part; - product->dual_part.x1 = multiplicand->x1 * multiplier->dual_part; - product->dual_part.x2 = multiplicand->x2 * multiplier->dual_part; - product->dual_part.x3 = multiplicand->x3 * multiplier->dual_part; + product->dual_part.x = multiplicand->x * multiplier->dual_part; + product->dual_part.y = multiplicand->y * multiplier->dual_part; + product->dual_part.z = multiplicand->z * multiplier->dual_part; } // ============ Left Vector Product ============= // inline void bgc_fp32_vector3_multiply_by_matrix2x3(BGC_FP32_Vector2* const product, const BGC_FP32_Vector3* const vector, const BGC_FP32_Matrix2x3* const matrix) { - product->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1; - product->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2; + product->x = vector->x * matrix->r1c1 + vector->y * matrix->r2c1 + vector->z * matrix->r3c1; + product->y = vector->x * matrix->r1c2 + vector->y * matrix->r2c2 + vector->z * matrix->r3c2; } inline void bgc_fp64_vector3_multiply_by_matrix2x3(BGC_FP64_Vector2* const product, const BGC_FP64_Vector3* const vector, const BGC_FP64_Matrix2x3* const matrix) { - product->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1; - product->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2; + product->x = vector->x * matrix->r1c1 + vector->y * matrix->r2c1 + vector->z * matrix->r3c1; + product->y = vector->x * matrix->r1c2 + vector->y * matrix->r2c2 + vector->z * matrix->r3c2; } // ============ Left Vector Product ============= // inline void bgc_fp32_vector3_multiply_by_matrix3x3(BGC_FP32_Vector3* const product, const BGC_FP32_Vector3* const vector, const BGC_FP32_Matrix3x3* const matrix) { - const float x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1; - const float x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2; - const float x3 = vector->x1 * matrix->r1c3 + vector->x2 * matrix->r2c3 + vector->x3 * matrix->r3c3; + const float x = vector->x * matrix->r1c1 + vector->y * matrix->r2c1 + vector->z * matrix->r3c1; + const float y = vector->x * matrix->r1c2 + vector->y * matrix->r2c2 + vector->z * matrix->r3c2; + const float z = vector->x * matrix->r1c3 + vector->y * matrix->r2c3 + vector->z * matrix->r3c3; - product->x1 = x1; - product->x2 = x2; - product->x3 = x3; + product->x = x; + product->y = y; + product->z = z; } inline void bgc_fp64_vector3_multiply_by_matrix3x3(BGC_FP64_Vector3* const product, const BGC_FP64_Vector3* const vector, const BGC_FP64_Matrix3x3* const matrix) { - const double x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1; - const double x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2; - const double x3 = vector->x1 * matrix->r1c3 + vector->x2 * matrix->r2c3 + vector->x3 * matrix->r3c3; + const double x = vector->x * matrix->r1c1 + vector->y * matrix->r2c1 + vector->z * matrix->r3c1; + const double y = vector->x * matrix->r1c2 + vector->y * matrix->r2c2 + vector->z * matrix->r3c2; + const double z = vector->x * matrix->r1c3 + vector->y * matrix->r2c3 + vector->z * matrix->r3c3; - product->x1 = x1; - product->x2 = x2; - product->x3 = x3; + product->x = x; + product->y = y; + product->z = z; } // =================== Divide =================== // @@ -357,32 +357,32 @@ inline int bgc_fp64_vector3_divide_by_real_number(BGC_FP64_Vector3* const quotie inline void bgc_fp32_vector3_get_mean2(BGC_FP32_Vector3* const mean, const BGC_FP32_Vector3* const vector1, const BGC_FP32_Vector3* const vector2) { - mean->x1 = (vector1->x1 + vector2->x1) * 0.5f; - mean->x2 = (vector1->x2 + vector2->x2) * 0.5f; - mean->x3 = (vector1->x3 + vector2->x3) * 0.5f; + mean->x = (vector1->x + vector2->x) * 0.5f; + mean->y = (vector1->y + vector2->y) * 0.5f; + mean->z = (vector1->z + vector2->z) * 0.5f; } inline void bgc_fp64_vector3_get_mean2(BGC_FP64_Vector3* const mean, const BGC_FP64_Vector3* const vector1, const BGC_FP64_Vector3* const vector2) { - mean->x1 = (vector1->x1 + vector2->x1) * 0.5; - mean->x2 = (vector1->x2 + vector2->x2) * 0.5; - mean->x3 = (vector1->x3 + vector2->x3) * 0.5; + mean->x = (vector1->x + vector2->x) * 0.5; + mean->y = (vector1->y + vector2->y) * 0.5; + mean->z = (vector1->z + vector2->z) * 0.5; } // ================== Average3 ================== // inline void bgc_fp32_vector3_get_mean3(BGC_FP32_Vector3* const mean, const BGC_FP32_Vector3* const vector1, const BGC_FP32_Vector3* const vector2, const BGC_FP32_Vector3* const vector3) { - mean->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BGC_FP32_ONE_THIRD; - mean->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BGC_FP32_ONE_THIRD; - mean->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * BGC_FP32_ONE_THIRD; + mean->x = (vector1->x + vector2->x + vector3->x) * BGC_FP32_ONE_THIRD; + mean->y = (vector1->y + vector2->y + vector3->y) * BGC_FP32_ONE_THIRD; + mean->z = (vector1->z + vector2->z + vector3->z) * BGC_FP32_ONE_THIRD; } inline void bgc_fp64_vector3_get_mean3(BGC_FP64_Vector3* const mean, const BGC_FP64_Vector3* const vector1, const BGC_FP64_Vector3* const vector2, const BGC_FP64_Vector3* const vector3) { - mean->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BGC_FP64_ONE_THIRD; - mean->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BGC_FP64_ONE_THIRD; - mean->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * BGC_FP64_ONE_THIRD; + mean->x = (vector1->x + vector2->x + vector3->x) * BGC_FP64_ONE_THIRD; + mean->y = (vector1->y + vector2->y + vector3->y) * BGC_FP64_ONE_THIRD; + mean->z = (vector1->z + vector2->z + vector3->z) * BGC_FP64_ONE_THIRD; } // =================== Linear =================== // @@ -391,48 +391,48 @@ inline void bgc_fp32_vector3_interpolate(BGC_FP32_Vector3* const interpolation, { const float counter_phase = 1.0f - phase; - interpolation->x1 = first->x1 * counter_phase + second->x1 * phase; - interpolation->x2 = first->x2 * counter_phase + second->x2 * phase; - interpolation->x3 = first->x3 * counter_phase + second->x3 * phase; + interpolation->x = first->x * counter_phase + second->x * phase; + interpolation->y = first->y * counter_phase + second->y * phase; + interpolation->z = first->z * counter_phase + second->z * phase; } inline void bgc_fp64_vector3_interpolate(BGC_FP64_Vector3* const interpolation, const BGC_FP64_Vector3* const first, const BGC_FP64_Vector3* const second, const double phase) { const double counter_phase = 1.0 - phase; - interpolation->x1 = first->x1 * counter_phase + second->x1 * phase; - interpolation->x2 = first->x2 * counter_phase + second->x2 * phase; - interpolation->x3 = first->x3 * counter_phase + second->x3 * phase; + interpolation->x = first->x * counter_phase + second->x * phase; + interpolation->y = first->y * counter_phase + second->y * phase; + interpolation->z = first->z * counter_phase + second->z * phase; } // ================== Negative ================== // inline void bgc_fp32_vector3_revert(BGC_FP32_Vector3* const vector) { - vector->x1 = -vector->x1; - vector->x2 = -vector->x2; - vector->x3 = -vector->x3; + vector->x = -vector->x; + vector->y = -vector->y; + vector->z = -vector->z; } inline void bgc_fp64_vector3_revert(BGC_FP64_Vector3* const vector) { - vector->x1 = -vector->x1; - vector->x2 = -vector->x2; - vector->x3 = -vector->x3; + vector->x = -vector->x; + vector->y = -vector->y; + vector->z = -vector->z; } inline void bgc_fp32_vector3_get_reverse(BGC_FP32_Vector3* const reverse, const BGC_FP32_Vector3* const vector) { - reverse->x1 = -vector->x1; - reverse->x2 = -vector->x2; - reverse->x3 = -vector->x3; + reverse->x = -vector->x; + reverse->y = -vector->y; + reverse->z = -vector->z; } inline void bgc_fp64_vector3_get_reverse(BGC_FP64_Vector3* const reverse, const BGC_FP64_Vector3* const vector) { - reverse->x1 = -vector->x1; - reverse->x2 = -vector->x2; - reverse->x3 = -vector->x3; + reverse->x = -vector->x; + reverse->y = -vector->y; + reverse->z = -vector->z; } // ================= Normalize ================== // @@ -451,9 +451,9 @@ inline int bgc_fp32_vector3_normalize(BGC_FP32_Vector3* const vector) const float multiplier = sqrtf(1.0f / square_modulus); - vector->x1 *= multiplier; - vector->x2 *= multiplier; - vector->x3 *= multiplier; + vector->x *= multiplier; + vector->y *= multiplier; + vector->z *= multiplier; return BGC_SUCCESS; } @@ -472,9 +472,9 @@ inline int bgc_fp64_vector3_normalize(BGC_FP64_Vector3* const vector) const double multiplier = sqrt(1.0 / square_modulus); - vector->x1 *= multiplier; - vector->x2 *= multiplier; - vector->x3 *= multiplier; + vector->x *= multiplier; + vector->y *= multiplier; + vector->z *= multiplier; return BGC_SUCCESS; } @@ -519,68 +519,68 @@ inline int bgc_fp64_vector3_get_normalized(BGC_FP64_Vector3* const normalized, c inline float bgc_fp32_vector3_get_dot_product(const BGC_FP32_Vector3* const vector1, const BGC_FP32_Vector3* const vector2) { - return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2 + vector1->x3 * vector2->x3; + return vector1->x * vector2->x + vector1->y * vector2->y + vector1->z * vector2->z; } inline double bgc_fp64_vector3_get_dot_product(const BGC_FP64_Vector3* const vector1, const BGC_FP64_Vector3* const vector2) { - return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2 + vector1->x3 * vector2->x3; + return vector1->x * vector2->x + vector1->y * vector2->y + vector1->z * vector2->z; } // =============== Triple Product =============== // inline float bgc_fp32_vector3_get_triple_product(const BGC_FP32_Vector3* const vector1, const BGC_FP32_Vector3* const vector2, const BGC_FP32_Vector3* const vector3) { - return vector1->x1 * (vector2->x2 * vector3->x3 - vector2->x3 * vector3->x2) - + vector1->x2 * (vector2->x3 * vector3->x1 - vector2->x1 * vector3->x3) - + vector1->x3 * (vector2->x1 * vector3->x2 - vector2->x2 * vector3->x1); + return vector1->x * (vector2->y * vector3->z - vector2->z * vector3->y) + + vector1->y * (vector2->z * vector3->x - vector2->x * vector3->z) + + vector1->z * (vector2->x * vector3->y - vector2->y * vector3->x); } inline double bgc_fp64_vector3_get_triple_product(const BGC_FP64_Vector3* const vector1, const BGC_FP64_Vector3* const vector2, const BGC_FP64_Vector3* const vector3) { - return vector1->x1 * (vector2->x2 * vector3->x3 - vector2->x3 * vector3->x2) - + vector1->x2 * (vector2->x3 * vector3->x1 - vector2->x1 * vector3->x3) - + vector1->x3 * (vector2->x1 * vector3->x2 - vector2->x2 * vector3->x1); + return vector1->x * (vector2->y * vector3->z - vector2->z * vector3->y) + + vector1->y * (vector2->z * vector3->x - vector2->x * vector3->z) + + vector1->z * (vector2->x * vector3->y - vector2->y * vector3->x); } // =========== Restrict Cross Product =========== // inline void _bgc_fp32_restrict_vector3_get_cross_product(BGC_FP32_Vector3* restrict const product, const BGC_FP32_Vector3* const vector1, const BGC_FP32_Vector3* const vector2) { - product->x1 = vector1->x2 * vector2->x3 - vector1->x3 * vector2->x2; - product->x2 = vector1->x3 * vector2->x1 - vector1->x1 * vector2->x3; - product->x3 = vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1; + product->x = vector1->y * vector2->z - vector1->z * vector2->y; + product->y = vector1->z * vector2->x - vector1->x * vector2->z; + product->z = vector1->x * vector2->y - vector1->y * vector2->x; } inline void _bgc_fp64_restrict_vector3_get_cross_product(BGC_FP64_Vector3* restrict const product, const BGC_FP64_Vector3* const vector1, const BGC_FP64_Vector3* const vector2) { - product->x1 = vector1->x2 * vector2->x3 - vector1->x3 * vector2->x2; - product->x2 = vector1->x3 * vector2->x1 - vector1->x1 * vector2->x3; - product->x3 = vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1; + product->x = vector1->y * vector2->z - vector1->z * vector2->y; + product->y = vector1->z * vector2->x - vector1->x * vector2->z; + product->z = vector1->x * vector2->y - vector1->y * vector2->x; } // =============== Cross Product ================ // inline void bgc_fp32_vector3_get_cross_product(BGC_FP32_Vector3* const product, const BGC_FP32_Vector3* const vector1, const BGC_FP32_Vector3* const vector2) { - const float x1 = vector1->x2 * vector2->x3 - vector1->x3 * vector2->x2; - const float x2 = vector1->x3 * vector2->x1 - vector1->x1 * vector2->x3; - const float x3 = vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1; + const float x = vector1->y * vector2->z - vector1->z * vector2->y; + const float y = vector1->z * vector2->x - vector1->x * vector2->z; + const float z = vector1->x * vector2->y - vector1->y * vector2->x; - product->x1 = x1; - product->x2 = x2; - product->x3 = x3; + product->x = x; + product->y = y; + product->z = z; } inline void bgc_fp64_vector3_get_cross_product(BGC_FP64_Vector3* const product, const BGC_FP64_Vector3* const vector1, const BGC_FP64_Vector3* const vector2) { - const double x1 = vector1->x2 * vector2->x3 - vector1->x3 * vector2->x2; - const double x2 = vector1->x3 * vector2->x1 - vector1->x1 * vector2->x3; - const double x3 = vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1; + const double x = vector1->y * vector2->z - vector1->z * vector2->y; + const double y = vector1->z * vector2->x - vector1->x * vector2->z; + const double z = vector1->x * vector2->y - vector1->y * vector2->x; - product->x1 = x1; - product->x2 = x2; - product->x3 = x3; + product->x = x; + product->y = y; + product->z = z; } // ============ Double Cross Product ============ // @@ -591,9 +591,9 @@ inline void bgc_fp32_vector3_get_double_cross(BGC_FP32_Vector3* const product, c const float ac = bgc_fp32_vector3_get_dot_product(vector1, vector3); const float ab = bgc_fp32_vector3_get_dot_product(vector1, vector2); - product->x1 = vector2->x1 * ac - vector3->x1 * ab; - product->x2 = vector2->x2 * ac - vector3->x2 * ab; - product->x3 = vector2->x3 * ac - vector3->x3 * ab; + product->x = vector2->x * ac - vector3->x * ab; + product->y = vector2->y * ac - vector3->y * ab; + product->z = vector2->z * ac - vector3->z * ab; } // [a x [b x c]] = b * (a, c) - c * (a, b) @@ -602,9 +602,9 @@ inline void bgc_fp64_vector3_get_double_cross(BGC_FP64_Vector3* const product, c const double ac = bgc_fp64_vector3_get_dot_product(vector1, vector3); const double ab = bgc_fp64_vector3_get_dot_product(vector1, vector2); - product->x1 = vector2->x1 * ac - vector3->x1 * ab; - product->x2 = vector2->x2 * ac - vector3->x2 * ab; - product->x3 = vector2->x3 * ac - vector3->x3 * ab; + product->x = vector2->x * ac - vector3->x * ab; + product->y = vector2->y * ac - vector3->y * ab; + product->z = vector2->z * ac - vector3->z * ab; } // ====== Alternative Double Cross Product ====== // @@ -615,9 +615,9 @@ inline void bgc_fp32_vector3_get_alternative_double_cross(BGC_FP32_Vector3* cons 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; + product->x = vector2->x * ac - vector1->x * bc; + product->y = vector2->y * ac - vector1->y * bc; + product->z = vector2->z * ac - vector1->z * bc; } // [[a x b] x c] = - [c x [a x b]] = -(a * (b, c) - b * (a, c)) = b * (a, c) - a * (b, c) @@ -626,9 +626,9 @@ inline void bgc_fp64_vector3_get_alternative_double_cross(BGC_FP64_Vector3* cons 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; + product->x = vector2->x * ac - vector1->x * bc; + product->y = vector2->y * ac - vector1->y * bc; + product->z = vector2->z * ac - vector1->z * bc; } // =================== Angle ==================== // @@ -641,20 +641,20 @@ double bgc_fp64_vector3_get_angle(const BGC_FP64_Vector3* const vector1, const B inline float bgc_fp32_vector3_get_square_distance(const BGC_FP32_Vector3* const vector1, const BGC_FP32_Vector3* const vector2) { - const float dx1 = (vector1->x1 - vector2->x1); - const float dx2 = (vector1->x2 - vector2->x2); - const float dx3 = (vector1->x3 - vector2->x3); + const float dx = (vector1->x - vector2->x); + const float dy = (vector1->y - vector2->y); + const float dz = (vector1->z - vector2->z); - return dx1 * dx1 + dx2 * dx2 + dx3 * dx3; + return dx * dx + dy * dy + dz * dz; } inline double bgc_fp64_vector3_get_square_distance(const BGC_FP64_Vector3* const vector1, const BGC_FP64_Vector3* const vector2) { - const double dx1 = (vector1->x1 - vector2->x1); - const double dx2 = (vector1->x2 - vector2->x2); - const double dx3 = (vector1->x3 - vector2->x3); + const double dx = (vector1->x - vector2->x); + const double dy = (vector1->y - vector2->y); + const double dz = (vector1->z - vector2->z); - return dx1 * dx1 + dx2 * dx2 + dx3 * dx3; + return dx * dx + dy * dy + dz * dz; } // ================== Distance ================== // diff --git a/docs/intro-eng.md b/docs/intro-eng.md index 2f06186..42f56c1 100644 --- a/docs/intro-eng.md +++ b/docs/intro-eng.md @@ -4,12 +4,17 @@ ### Prefixes -The library uses prefixes in names of types, constants and functions. +C programming language does not have namespaces, thus prefixes often play role +of namespaces in C code. + +The library uses prefixes in names of types, constants and functions to avoid +name conflict with of othr libraries. The main prefix is **BGC** which means **B**asic **G**eometric **C**omputations. -The structure types have prefix in the form **Bgc**. For example: BgcVector3FP64, -BgcVersorFP32, BgcMatrix2x2FP32. +The structure types and contstans have prefix in the form **Bgc**. For example: +BgcVector3FP64, BGC_FP32_Quaternion, BGC_FP32_Matrix2x2, BGC_FP32_EPSILON, +BGC_FP64_TWO_PI. The constants have prefix in the form **BGC_**. For example: BGC_EPSYLON_FP32, BGC_TWO_PI_FP64. @@ -31,29 +36,19 @@ Thus there are two suffixes of types: * **FP64** - means **F**loating **P**oint, **64** bit, which corresponds to the **double** type of the C language. -The types of structures which are based in the **float** type have **FP32** as -the type prefix: BgcVector3FP32, BgcMatrix3x2FP32, BgcQuaternionFP32. +The constants and the types of structures which are based in the **float** type +have **FP32** as the type prefix: BGC_FP32_Vector3, BGC_FP32_Matrix3x2, +BGC_FP32_Quaternion, BGC_FP32_PI, BGC_FP32_EPSILON. -The types of structures which are based in the **double** type have **FP64** as -the type prefix: BgcVector2FP64, BgcMatrix2x3FP64, BgcVersorFP64. - -The constants of the **float** type have **_FP32** as the type suffix: -BGC_PI_FP32, BGC_EPSYLON_FP32. - -The constants of the **double** type have **_FP64** as the type suffix: -BGC_HALF_PI_FP64, BGC_ONE_THIRD_FP64. +The constants and the types of structures which are based in the **double** type +have **FP64** as the type prefix: BGC_FP64_Vector2, BGC_FP64_Matrix2x3, +BGC_FP64_Turn3, BGC_FP64_HALF_PI, BGC_FP64_ONE_THIRD. The functions which works with data of the **float** type have **_fp32** as -the type suffix: bgc_vector2_get_modulus_fp64, bgc_radians_to_degrees_fp32. +the type suffix: bcg_fp32_vector2_get_length, bgc_fp32_radians_to_degrees. The functions which works with data of the **double** type have **_fp64** as -the type suffix: bgc_vector3_reset_fp64, bgc_radians_normalize_fp64. - -## Entities - -- [Angles](angle-eng.md) -- [Vectors 2D](vector2-eng.md) -- [Vectors 3D](vector3-eng.md) -- [Quaternions](quaternion-eng.md) -- [Versors](versor-eng.md) +the type suffix: bgc_fp64_vector3_reset, bgc_fp64_normalize_radians. +Using of such prefixes of a basic type allows to enhance the library with new +basic types in future. \ No newline at end of file diff --git a/docs/intro-rus.md b/docs/intro-rus.md index 6a6b3f2..7d2d686 100644 --- a/docs/intro-rus.md +++ b/docs/intro-rus.md @@ -4,26 +4,27 @@ ### Префиксы -Библиотека использует префиксы в названиях типов, констант и функций. +В языке программирования C (Си) нет пространств имён, потому роль пространств +имён играют префиксы в названиях. + +Библиотека использует префиксы в названиях типов, констант и функций для +того, чтобы избежать конфликтов в названиях констант, типов и функций с другими +библиотеками. Основным префиксом является **BGC** (сокращение от **B**asic **G**eometric **C**omputations / Базовые Геометрие Вычисления). -Для структур данных префикс имеет вид **Bgc**, например: BgcVector3FP64, -BgcVersorFP32, BgcMatrix2x2FP32. +Для констант и структур данных префикс имеет вид **BGC_**, например: +BgcVector3FP64, BGC_FP32_Quaternion, BGC_FP32_Matrix2x2, BGC_FP32_EPSILON, +BGC_FP64_TWO_PI. -Константы имеют префикс в виде **BGC_**, например: BGC_EPSYLON_FP32, -BGC_TWO_PI_FP64. +Функции имеют префикс в виде **bgc_**, например: bgc_fp32_turn3_combine, +bgc_fp64_matrix3x3_subtract. -Функции имеют префикс в виде **bgc_**, например: bgc_versor_combine_fp32, -bgc_matrix3x3_subtract_fp64. +После префикса библиотеки идёт префикс базового типа. -### Cуффиксы - -Названия констант, типов и функций оканчиваются суффиксом, указывающим на -базовый тип. Библиотека использует два типа чисел с плавающей запятой: -**float** и **double** (типы **binary32** и **binary64** стандарта -**IEEE 754**). +Библиотека использует два типа чисел с плавающей запятой: **float** и **double** +(типы **binary32** и **binary64** стандарта **IEEE 754**). Поэтому в библиотеке есть два префикса типа: @@ -33,27 +34,19 @@ bgc_matrix3x3_subtract_fp64. * **FP64** - означает **F**loating **P**oint **64** bit, то есть, число с плавающей запятой, 64 бита, что соответствует типу **double** языка Си. -Типы структур, использующие тип **float** имеют суффикс **FP32**: -BgcVector3FP32, BgcMatrix3x2FP32, BgcQuaternionFP32 +Типы структур и константы, основанные на типе **float** имеют префикс **FP32_**: +BGC_FP32_Vector3, BGC_FP32_Matrix3x2, BGC_FP32_Quaternion, BGC_FP32_PI, +BGC_FP32_EPSILON. -Типы структур, использующие тип **double** имеют суффикс **FP64**: -BgcVector2FP64, BgcMatrix2x3FP64, BgcVersorFP64 - -Константы типа **float** имеют суффикс **_FP32**: BGC_PI_FP32, BGC_EPSYLON_FP32. - -Константы типа **double** имеют суффикс **_FP64**: BGC_HALF_PI_FP64, -BGC_ONE_THIRD_FP64. +Типы структур и константы, основанные на типе **double** имеют префикс +**FP64_**: BGC_FP64_Vector2, BGC_FP64_Matrix2x3, BGC_FP64_Turn3, +BGC_FP64_HALF_PI, BGC_FP64_ONE_THIRD. Функции, которые работают с данными типа **float** имеют суффикс **_fp32**: -bcg_vector2_get_modulus_fp32, bgc_radians_to_degrees_fp32. +bcg_fp32_vector2_get_length, bgc_fp32_radians_to_degrees. Функции, которые работают с данными типа **double** имеют суффикс **_fp64**: -bgc_vector3_reset_fp64, bgc_radians_normalize_fp64. +bgc_fp64_vector3_reset, bgc_fp64_normalize_radians. -## Сущности - -- [Углы](angle-rus.md) -- [2D векторы](vector2-rus.md) -- [3D векторы](vector2-rus.md) -- [Кватернионы](quaternion-rus.md) -- [Версоры](versor-rus.md) +Использование подобных префиксов позволяет расширять библиотеку используя новые +новые базовые типы в будущем. \ No newline at end of file diff --git a/docs/vector3-eng.md b/docs/vector3-eng.md index 80d6146..8474a4f 100644 --- a/docs/vector3-eng.md +++ b/docs/vector3-eng.md @@ -1,21 +1,21 @@ # Three-dimensional vectors There are two types of 3D vectors in the library: -- **BgcVector3FP32** - vector using single-precision floating-point numbers -- **BgcVector3FP64** - vector using double-precision floating-point numbers +- **BGC_FP32_Vector3** - vector using single-precision floating-point numbers +- **BGC_FP64_Vector3** - vector using double-precision floating-point numbers Structure definitions: ```c typedef struct { - float x1, x2, x3; - } BgcVector3FP32; + float x, y, z; + } BGC_FP32_Vector3; typedef struct { - double x1, x2, x3; - } BgcVector3FP64; + double x, y, z; + } BGC_FP64_Vector3; ``` ## Functions diff --git a/docs/vector3-rus.md b/docs/vector3-rus.md index 2a8e4d4..a51409e 100644 --- a/docs/vector3-rus.md +++ b/docs/vector3-rus.md @@ -1,30 +1,32 @@ # Трёхмерные векторы векторы -В библиотеке есть два типа двумерных векторов: -- **BgcVector3FP32** - вектор с использованием чисел с плавающей запятой одинарной точности -- **BgcVector3FP64** - вектор с использованием чисел с плавающей запятой двойной точности +В библиотеке есть два типа трёхмерных векторов: +- **BGC_FP32_Vector3** - вектор с использованием чисел с плавающей запятой +одинарной точности +- **BGC_FP64_Vector3** - вектор с использованием чисел с плавающей запятой +двойной точности Определения структур: ```c typedef struct { - float x1, x2, x3; - } BgcVector3FP32; + float x, y, z; + } BGC_FP32_Vector3; typedef struct { - double x1, x2, x3; - } BgcVector3FP64; + double x, y, z; + } BGC_FP64_Vector3; ``` ## Функции | Функции для BgcVector3FP32 | Функции для BgcVector3FP64 | |:-------------------------------------------------------------:|:-------------------------------------------------------------:| -| [bgc_vector3_reset_fp32](vector3/reset-rus.md) | [bgc_vector3_reset_fp64](vector3/reset-rus.md) | -| [bgc_vector3_set_values_fp32](vector3/set-values-rus.md) | [bgc_vector3_set_values_fp64](vector3/set-values-rus.md) | -| [bgc_vector3_copy_fp32](vector3/copy-rus.md) | [bgc_vector3_copy_fp64](vector3/copy-rus.md) | -| [bgc_vector3_swap_fp32](vector3/swap-rus.md) | [bgc_vector3_swap_fp64](vector3/swap-rus.md) | +| [bgc_fp32_vector3_reset](vector3/reset-rus.md) | [bgc_fp64_vector3_reset](vector3/reset-rus.md) | +| [bgc_fp32_vector3_set_values](vector3/set-values-rus.md) | [bgc_fp64_vector3_set_values](vector3/set-values-rus.md) | +| [bgc_fp32_vector3_copy](vector3/copy-rus.md) | [bgc_fp64_vector3_copy](vector3/copy-rus.md) | +| [bgc_fp32_vector3_swap](vector3/swap-rus.md) | [bgc_fp64_vector3_swap](vector3/swap-rus.md) | [Документация](intro-rus.md) diff --git a/docs/vector3/copy-eng.md b/docs/vector3/copy-eng.md index 1288609..74d5e69 100644 --- a/docs/vector3/copy-eng.md +++ b/docs/vector3/copy-eng.md @@ -1,32 +1,39 @@ # Copying -The copy functions allow you to copy the coordinate values of one vector to another vector. +The copy functions allow you to copy the coordinate values of one vector +to another vector. -Function for **BgcVector3FP32**: +Function for **BGC_FP32_Vector3**: ```c -inline void bgc_vector3_copy_fp32(const BgcVector3FP32* from, BgcVector3FP32* to); +inline void bgc_fp32_vector3_copy(BGC_FP32_Vector3* const destination, const BGC_FP32_Vector3* const source); ``` -Function for **BgcVector3FP64**: +Function for **BGC_FP64_Vector3**: ```c -inline void bgc_vector3_copy_fp64(const BgcVector3FP64* from, BgcVector3FP64* to); +inline void bgc_fp64_vector3_copy(BGC_FP64_Vector3* const destination, const BGC_FP64_Vector3* const source); ``` Each of these functions is equivalent to the following lines of code: ```c -to->x1 = from->x1; -to->x2 = from->x2; -to->x3 = from->x3; +destination->x = source->x; +destination->y = source->y; +destination->z = source->z; ``` -The **from** and **to** parameters must not be invalid pointers. The NULL (0) value is also considered invalid. +The **source** and **destination** parameters must not be invalid pointers. +The NULL (0) value is also considered invalid. -The **from** parameter must be a pointer to a three-dimensional vector whose coordinates are to be copied. The coordinates of the **from** vector will not change after the function call. +The **source** parameter must be a pointer to a three-dimensional vector whose +coordinates are to be copied. The coordinates of the **source** vector will +not change after the function call. -The **to** parameter must be a pointer to a three-dimensional vector whose coordinates are to be changed. The coordinates of the **to** vector will become the same as those of the **from** vector after the function call. +The **destination** parameter must be a pointer to a three-dimensional vector +whose coordinates are to be changed. The coordinates of the **destination** +vector will become the same as those of the **source** vector after the function +call. Example of use: @@ -36,13 +43,15 @@ Example of use: int main() { - BgcVector3FP32 my_vector1, my_vector3; + BGC_FP32_Vector3 my_vector1, my_vector2; - bgc_vector3_set_values_fp32(-2, 7, 1, &my_vector1); + my_vector1.x = -2.0f; + my_vector1.y = 7.4f; + my_vector1.z = 1.8f; - bgc_vector3_copy_fp32(&my_vector1, &my_vector3); + bgc_fp32_vector3_copy(&my_vector2, &my_vector1); - printf("x1 = %f, x2 = %f, x3 = %f\n", my_vector3.x1, my_vector3.x2, my_vector3.x3); + printf("x = %f, y = %f, z = %f\n", my_vector2.x, my_vector2.y, my_vector2.z); return 0; } diff --git a/docs/vector3/copy-rus.md b/docs/vector3/copy-rus.md index c9891d1..8598eb2 100644 --- a/docs/vector3/copy-rus.md +++ b/docs/vector3/copy-rus.md @@ -1,32 +1,38 @@ # - . + + . - **BgcVector3FP32**: + **BGC_FP32_Vector3**: ```c -inline void bgc_vector3_copy_fp32(const BgcVector3FP32* from, BgcVector3FP32* to); +inline void bgc_fp32_vector3_copy(BGC_FP32_Vector3* const destination, const BGC_FP32_Vector3* const source); ``` - **BgcVector3FP64**: + **BGC_FP64_Vector3**: ```c -inline void bgc_vector3_copy_fp64(const BgcVector3FP64* from, BgcVector3FP64* to); +inline void bgc_fp64_vector3_copy(BGC_FP64_Vector3* const destination, const BGC_FP64_Vector3* const source); ``` : ```c -to->x1 = from->x1; -to->x2 = from->x2; -to->x3 = from->x3; +destination->x = source->x; +destination->y = source->y; +destination->z = source->z; ``` - **from** **to** . NULL (0) . + **source** **destination** . + NULL (0) . - **from** , . **from** . + **source** , + . **source** + . - **to** , . **to** , **from**. + **destination** , + . **destination** + , **source**. : @@ -36,13 +42,15 @@ to->x3 = from->x3; int main() { - BgcVector3FP32 my_vector1, my_vector3; + BGC_FP32_Vector3 my_vector1, my_vector2; - bgc_vector3_set_values_fp32(-2, 7, 1, &my_vector1); + my_vector1.x = -2.0f; + my_vector1.y = 7.4f; + my_vector1.z = 1.8f; - bgc_vector3_copy_fp32(&my_vector1, &my_vector3); + bgc_fp32_vector3_copy(&my_vector2, &my_vector1); - printf("x1 = %f, x2 = %f, x3 = %f\n", my_vector3.x1, my_vector3.x2, my_vector3.x3); + printf("x = %f, y = %f, z = %f\n", my_vector2.x, my_vector2.y, my_vector2.z); return 0; } diff --git a/docs/vector3/reset-eng.md b/docs/vector3/reset-eng.md index bf9242f..9d0d7f9 100644 --- a/docs/vector3/reset-eng.md +++ b/docs/vector3/reset-eng.md @@ -2,27 +2,30 @@ These functions set all coordinates of 3D vectors to 0. -Function for **BgcVector3FP32**: +Function for **BGC_FP32_Vector3**: ```c -inline void bgc_vector3_reset_fp32(BgcVector3FP32* vector); +inline void bgc_fp32_vector3_reset(BGC_FP32_Vector3* vector); ``` -Function for **BgcVector3FP64**: +Function for **BGC_FP64_Vector3**: ```c -inline void bgc_vector3_reset_fp64(BgcVector3FP64* vector); +inline void bgc_fp64_vector3_reset(BGC_FP64_Vector3* vector); ``` Each of these functions is equivalent to the following lines of code: ```c -vector->x1 = 0; -vector->x2 = 0; -vector->x3 = 0; +vector->x = 0; +vector->y = 0; +vector->z = 0; ``` -You should not pass invalid pointers to these functions. The NULL (0) value is also considered invalid. +You should not pass invalid pointers to these functions. The NULL (0) value is +also considered invalid. + +This function is good for setting up the initial state of a 3D vector. Example of use: @@ -32,11 +35,11 @@ Example of use: int main() { - BgcVector3FP32 my_vector; + BGC_FP32_Vector3 my_vector; - bgc_vector3_reset_fp32(&my_vector); + bgc_fp32_vector3_reset(&my_vector); - printf("x1 = %f, x2 = %f, x3 = %f\n", my_vector.x1, my_vector.x2, my_vector.x3); + printf("x = %f, y = %f, z = %f\n", my_vector.x, my_vector.y, my_vector.z); return 0; } diff --git a/docs/vector3/reset-rus.md b/docs/vector3/reset-rus.md index 952a267..59a2634 100644 --- a/docs/vector3/reset-rus.md +++ b/docs/vector3/reset-rus.md @@ -2,27 +2,30 @@ 0 . - **BgcVector3FP32**: + **BGC_FP32_Vector3**: ```c -inline void bgc_vector3_reset_fp32(BgcVector3FP32* vector); +inline void bgc_fp32_vector3_reset(BGC_FP32_Vector3* vector); ``` - **BgcVector3FP64**: + **BGC_FP64_Vector3**: ```c -inline void bgc_vector3_reset_fp64(BgcVector3FP64* vector); +inline void bgc_fp64_vector3_reset(BGC_FP64_Vector3* vector); ``` : ```c -vector->x1 = 0; -vector->x2 = 0; -vector->x3 = 0; +vector->x = 0; +vector->y = 0; +vector->z = 0; ``` - . NULL (0) . + . NULL (0) + . + + . : @@ -32,11 +35,11 @@ vector->x3 = 0; int main() { - BgcVector3FP32 my_vector; + BGC_FP32_Vector3 my_vector; - bgc_vector3_reset_fp32(&my_vector); + bgc_fp32_vector3_reset(&my_vector); - printf("x1 = %f, x2 = %f, x3 = %f\n", my_vector.x1, my_vector.x2, my_vector.x3); + printf("x = %f, y = %f, z = %f\n", my_vector.x, my_vector.y, my_vector.z); return 0; } diff --git a/docs/vector3/set-values-eng.md b/docs/vector3/set-values-eng.md index 4613173..dd07e0b 100644 --- a/docs/vector3/set-values-eng.md +++ b/docs/vector3/set-values-eng.md @@ -1,28 +1,34 @@ # Setting the coordinates of a three-dimensional vector -You can set the coordinates of vectors either directly or using functions. The functions for setting coordinate values allow you to do this in one line. +You can set the coordinates of vectors either directly or using functions. +The functions for setting coordinate values allow you to do this in one line. -Function for **BgcVector3FP32**: +Function for **BGC_FP32_Vector3**: ```c -inline void bgc_vector3_set_values_fp32(const float x1, const float x2, const float x3, BgcVector3FP32* to); +inline void bgc_fp32_vector3_set_values(BGC_FP32_Vector3* const destination, const float x, const float y, const float z); ``` -Function for **BgcVector3FP32**: +Function for **BGC_FP64_Vector3**: ```c -inline void bgc_vector3_set_values_fp64(const double x1, const double x2, const double x3, BgcVector3FP64* to); +inline void bgc_fp64_vector3_set_values(BGC_FP64_Vector3* const destination, const double x, const double y, const double z); ``` Each of these functions is equivalent to the following lines of code: ```c -to->x1 = x1; -to->x2 = x2; -to->x3 = x3; +destination->x = x; +destination->y = y; +destination->z = z; ``` -Invalid pointers should not be passed in the **to** parameter. The NULL (0) value is also considered invalid. +Invalid pointers should not be passed in the **destination** parameter. +The NULL (0) value is also considered invalid. + +This function is good for setting up the initial values of coordinates with +one-line especially when the values are fixed constants like in the example +below. Example of use: @@ -32,11 +38,11 @@ Example of use: int main() { - BgcVector3FP32 my_vector; + BGC_FP32_Vector3 my_vector; - bgc_vector3_set_values_fp32(-2, 7, 10, &my_vector); + bgc_fp32_vector3_set_values(&my_vector, -2.2f, 7.1f, 10.01f); - printf("x1 = %f, x2 = %f, x3 = %f\n", my_vector.x1, my_vector.x2, my_vector.x3); + printf("x = %f, y = %f, z = %f\n", my_vector.x, my_vector.y, my_vector.z); return 0; } diff --git a/docs/vector3/set-values-rus.md b/docs/vector3/set-values-rus.md index eb803f8..17b3338 100644 --- a/docs/vector3/set-values-rus.md +++ b/docs/vector3/set-values-rus.md @@ -1,28 +1,35 @@ -# +# - , . . + , . + , + . - **BgcVector3FP32**: + **BGC_FP32_Vector3**: ```c -inline void bgc_vector3_set_values_fp32(const float x1, const float x2, const float x3, BgcVector3FP32* to); +inline void bgc_fp32_vector3_set_values(BGC_FP32_Vector3* const destination, const float x, const float y, const float z); ``` - **BgcVector3FP32**: + **BGC_FP64_Vector3**: ```c -inline void bgc_vector3_set_values_fp64(const double x1, const double x2, const double x3, BgcVector3FP64* to); +inline void bgc_fp64_vector3_set_values(BGC_FP64_Vector3* const destination, const double x, const double y, const double z); ``` : ```c -to->x1 = x1; -to->x2 = x2; -to->x3 = x3; +destination->x = x; +destination->y = y; +destination->z = z; ``` - **to** . NULL (0) . + **destination** . + NULL (0) . + + +. + . : @@ -32,11 +39,11 @@ to->x3 = x3; int main() { - BgcVector3FP32 my_vector; + BGC_FP32_Vector3 my_vector; - bgc_vector3_set_values_fp32(-2, 7, 10, &my_vector); + bgc_fp32_vector3_set_values(&my_vector, -2.2f, 7.1f, 10.01f); - printf("x1 = %f, x2 = %f, x3 = %f\n", my_vector.x1, my_vector.x2, my_vector.x3); + printf("x = %f, y = %f, z = %f\n", my_vector.x, my_vector.y, my_vector.z); return 0; } diff --git a/docs/vector3/swap-eng.md b/docs/vector3/swap-eng.md index ed60184..d47b928 100644 --- a/docs/vector3/swap-eng.md +++ b/docs/vector3/swap-eng.md @@ -1,24 +1,28 @@ # Swapping -The exchange functions allow two vectors of the same type to exchange coordinate values. +The exchange functions allow two vectors of the same type to exchange coordinate +values. -Function for **BgcVector3FP32**: +Function for **BGC_FP32_Vector3**: ```c -inline void bgc_vector3_swap_fp32(BgcVector3FP32* vector1, BgcVector3FP32* vector2); +inline void bgc_fp32_vector3_swap(BGC_FP32_Vector3* const vector1, BGC_FP32_Vector3* const vector2); ``` -Function for **BgcVector3FP32**: +Function for **BGC_FP64_Vector3**: ```c -inline void bgc_vector3_swap_fp64(BgcVector3FP64* vector1, BgcVector3FP64* vector2); +inline void bgc_fp64_vector3_swap(BGC_FP64_Vector3* const vector1, BGC_FP64_Vector3* const vector2); ``` -The **vector1** and **vector2** parameters must not be invalid pointers. The NULL (0) value is also considered invalid. +The **vector1** and **vector2** parameters must be valid pointers. +The NULL (0) value is considered invalid. -Vector **vector1** after calling this function will have the coordinate values that vector **vector3** had before calling the function. +Vector **vector1** after calling this function will have the coordinate values +that vector **vector3** had before calling the function. -And vector **vector3** after calling this function will have the same coordinate values that vector **vector1** had before calling the function. +And vector **vector3** after calling this function will have the same coordinate +values that vector **vector1** had before calling the function. Example of use: @@ -28,15 +32,15 @@ Example of use: int main() { - BgcVector3FP32 my_vector1, my_vector2; + BGC_FP32_Vector3 my_vector1, my_vector2; - bgc_vector3_set_values_fp32(-2, 7, 5, &my_vector1); - bgc_vector3_set_values_fp32(10, -1, -3, &my_vector2); + bgc_fp32_vector3_set_values(&my_vector1, -2, 7, 5); + bgc_fp32_vector3_set_values(&my_vector2, 10, -1, -3); - bgc_vector3_swap_fp32(&my_vector1, &my_vector2); + bgc_fp32_vector3_swap(&my_vector1, &my_vector2); - printf("Vector #1: x1 = %f, x2 = %f, x3 = %f\n", my_vector1.x1, my_vector1.x2, my_vector1.x3); - printf("Vector #2: x1 = %f, x2 = %f, x3 = %f\n", my_vector2.x1, my_vector2.x2, my_vector2.x3); + printf("Vector #1: x = %f, y = %f, z = %f\n", my_vector1.x, my_vector1.y, my_vector1.z); + printf("Vector #2: x = %f, y = %f, z = %f\n", my_vector2.x, my_vector2.y, my_vector2.z); return 0; } @@ -45,8 +49,8 @@ int main() Result: ``` -Vector #1: x1 = 10.000000, x2 = -1.000000, x3 = -3.000000 -Vector #2: x1 = -2.000000, x2 = 7.000000, x3 = 5.000000 +Vector #1: x = 10.000000, y = -1.000000, z = -3.000000 +Vector #2: x = -2.000000, y = 7.000000, z = 5.000000 ``` [Documentation](../intro-eng.md) / [3D vectors](../vector3-eng.md) diff --git a/docs/vector3/swap-rus.md b/docs/vector3/swap-rus.md index a95c2e4..347be86 100644 --- a/docs/vector3/swap-rus.md +++ b/docs/vector3/swap-rus.md @@ -1,6 +1,7 @@ -# Обмен +# Обмен значениями -Функции обмена позволяют двум векторам одного типа обменяться значениями координат. +Функции обмена позволяют двум векторам одного типа обменяться значениями +координат. Функция для **BgcVector3FP32**: @@ -14,11 +15,14 @@ inline void bgc_vector3_swap_fp32(BgcVector3FP32* vector1, BgcVector3FP32* vecto inline void bgc_vector3_swap_fp64(BgcVector3FP64* vector1, BgcVector3FP64* vector2); ``` -Параметры **vector1** и **vector2** не должны быть некорректными указателями. Значение NULL (0) также считается некорректным. +Параметры **vector1** и **vector2** не должны быть некорректными указателями. +Значение NULL (0) также считается некорректным. -Вектор **vector1** после вызова данной функции будет иметь значения координат, какие имел вектор **vector2** до вызова функции. +Вектор **vector1** после вызова данной функции будет иметь значения координат, +какие имел вектор **vector2** до вызова функции. -А вектор **vector2** после вызова данной функции будет иметь такие же значения координат, какие имел вектор **vector1** до вызова функции. +А вектор **vector2** после вызова данной функции будет иметь такие же значения +координат, какие имел вектор **vector1** до вызова функции. Пример применения: @@ -28,15 +32,15 @@ inline void bgc_vector3_swap_fp64(BgcVector3FP64* vector1, BgcVector3FP64* vecto int main() { - BgcVector3FP32 my_vector1, my_vector2; + BGC_FP32_Vector3 my_vector1, my_vector2; - bgc_vector3_set_values_fp32(-2, 7, 5, &my_vector1); - bgc_vector3_set_values_fp32(10, -1, -3, &my_vector2); + bgc_fp32_vector3_set_values(&my_vector1, -2, 7, 5); + bgc_fp32_vector3_set_values(&my_vector2, 10, -1, -3); - bgc_vector3_swap_fp32(&my_vector1, &my_vector2); + bgc_fp32_vector3_swap(&my_vector1, &my_vector2); - printf("Vector #1: x1 = %f, x2 = %f, x3 = %f\n", my_vector1.x1, my_vector1.x2, my_vector1.x3); - printf("Vector #2: x1 = %f, x2 = %f, x3 = %f\n", my_vector2.x1, my_vector2.x2, my_vector2.x3); + printf("Vector #1: x = %f, y = %f, z = %f\n", my_vector1.x, my_vector1.y, my_vector1.z); + printf("Vector #2: x = %f, y = %f, z = %f\n", my_vector2.x, my_vector2.y, my_vector2.z); return 0; } @@ -45,8 +49,8 @@ int main() Результат: ``` -Vector #1: x1 = 10.000000, x2 = -1.000000, x3 = -3.000000 -Vector #2: x1 = -2.000000, x2 = 7.000000, x3 = 5.000000 +Vector #1: x = 10.000000, y = -1.000000, z = -3.000000 +Vector #2: x = -2.000000, y = 7.000000, z = 5.000000 ``` [Документация](../intro-rus.md) / [3D векторы](../vector3-rus.md)