diff --git a/Geometry.workspace.layout b/Geometry.workspace.layout
index 1c395b7..4111ddb 100644
--- a/Geometry.workspace.layout
+++ b/Geometry.workspace.layout
@@ -1,6 +1,6 @@
-
-
+
+
diff --git a/dev/geometry-dev.depend b/dev/geometry-dev.depend
index c469583..3b4ed7f 100644
--- a/dev/geometry-dev.depend
+++ b/dev/geometry-dev.depend
@@ -1,5 +1,5 @@
# depslib dependency file v1.0
-1729764426 source:/home/andrey/Projects/Private/C/Geometry/dev/main.c
+1731995770 source:/home/andrey/Projects/Private/C/Geometry/dev/main.c
@@ -7,34 +7,32 @@
-1729526406 /home/andrey/Projects/Private/C/Geometry/src/geometry.h
+1731906002 /home/andrey/Projects/Private/C/Geometry/src/geometry.h
"basis.h"
"angle.h"
"vector2.h"
"vector3.h"
- "vector4.h"
+ "matrixes.h"
"matrix2x2.h"
+ "matrix2x3.h"
+ "matrix3x2.h"
"matrix3x3.h"
- "matrix4x4.h"
- "tangent.h"
"rotation3.h"
+ "quaternion.h"
"versor.h"
- "affine_map2.h"
- "affine_map3.h"
- "affine_map4.h"
- "position2.h"
- "position3.h"
-1729427506 /home/andrey/Projects/Private/C/Geometry/src/basis.h
+1730476002 /home/andrey/Projects/Private/C/Geometry/src/basis.h
-1729764440 /home/andrey/Projects/Private/C/Geometry/src/angle.h
+1730392488 /home/andrey/Projects/Private/C/Geometry/src/angle.h
+
+ "basis.h"
-1729503050 /home/andrey/Projects/Private/C/Geometry/src/vector2.h
+1731673023 /home/andrey/Projects/Private/C/Geometry/src/vector2.h
"basis.h"
"angle.h"
-1729502950 /home/andrey/Projects/Private/C/Geometry/src/vector3.h
+1731673331 /home/andrey/Projects/Private/C/Geometry/src/vector3.h
"basis.h"
"angle.h"
@@ -44,11 +42,14 @@
"angle.h"
-1729490828 /home/andrey/Projects/Private/C/Geometry/src/matrix2x2.h
+1731673308 /home/andrey/Projects/Private/C/Geometry/src/matrix2x2.h
+ "angle.h"
"vector2.h"
+ "matrixes.h"
-1729612680 /home/andrey/Projects/Private/C/Geometry/src/matrix3x3.h
+1731906002 /home/andrey/Projects/Private/C/Geometry/src/matrix3x3.h
"vector3.h"
+ "matrixes.h"
1729490844 /home/andrey/Projects/Private/C/Geometry/src/matrix4x4.h
"vector4.h"
@@ -60,18 +61,17 @@
"vector2.h"
"matrix2x2.h"
-1729428324 /home/andrey/Projects/Private/C/Geometry/src/rotation3.h
+1730355414 /home/andrey/Projects/Private/C/Geometry/src/rotation3.h
"basis.h"
"angle.h"
"vector3.h"
-1729595110 /home/andrey/Projects/Private/C/Geometry/src/versor.h
+1731995858 /home/andrey/Projects/Private/C/Geometry/src/versor.h
"basis.h"
"vector3.h"
"rotation3.h"
"matrix3x3.h"
- "matrix4x4.h"
1729503008 /home/andrey/Projects/Private/C/Geometry/src/affine_map2.h
"vector2.h"
@@ -107,3 +107,20 @@
"versor.h"
"affine_map3.h"
+1731906002 /home/andrey/Projects/Private/C/Geometry/src/matrixes.h
+
+1731906002 /home/andrey/Projects/Private/C/Geometry/src/matrix2x3.h
+ "vector2.h"
+ "vector3.h"
+ "matrixes.h"
+
+1731906002 /home/andrey/Projects/Private/C/Geometry/src/matrix3x2.h
+ "vector2.h"
+ "vector3.h"
+ "matrixes.h"
+
+1731407834 /home/andrey/Projects/Private/C/Geometry/src/quaternion.h
+
+ "basis.h"
+ "matrix3x3.h"
+
diff --git a/dev/main.c b/dev/main.c
index 1ca7e48..ce80027 100644
--- a/dev/main.c
+++ b/dev/main.c
@@ -50,12 +50,77 @@ SPVersor * make_random_versors(const unsigned int amount)
return list;
}
-void print_versor(const SPVersor * versor)
+void print_versor(const SPVersor* versor)
{
- printf("(%f, %f, %f, %f) / %e\n", versor->_s0, versor->_x1, versor->_x2, versor->_x3, versor->_corrector - 1.0f);
+ printf("(%f, %f, %f, %f)\n", versor->_s0, versor->_x1, versor->_x2, versor->_x3);
}
-/*/
+void print_vector(const SPVector3* vector)
+{
+ printf("(%f, %f, %f) / %f\n", vector->x1, vector->x2, vector->x3, sp_vector3_get_module(vector));
+}
+/*
+int main()
+{
+ const unsigned int amount = 1000000;
+
+#ifdef _WIN64
+ ULONGLONG now;
+ now = GetTickCount64();
+ srand((unsigned int)(now & 0xfffffff));
+#else
+ struct timespec now;
+ clock_gettime(CLOCK_REALTIME, &now);
+ srand((unsigned int)(now.tv_nsec & 0xfffffff));
+#endif // _WIN64
+
+ SPVersor * versors = make_random_versors(amount);
+
+ if (versors == 0) {
+ printf("Cannot allocate memory for versors");
+ return 0;
+ }
+
+ SPVector3 initial, result;
+
+ sp_vector3_set_values(1, 2, 3, &initial);
+ sp_vector3_copy(&initial, &result);
+
+#ifdef _WIN64
+ ULONGLONG start, end;
+ start = GetTickCount64();
+#else
+ struct timespec start, end;
+ clock_gettime(CLOCK_REALTIME, &start);
+#endif // _WIN64
+ for (unsigned int i = 0; i < amount; i++) {
+ sp_versor_turn2(&versors[i], &result, &result);
+ }
+
+ for (unsigned int i = amount; i > 0; i--) {
+ sp_versor_turn_back2(&versors[i - 1], &result, &result);
+ }
+
+#ifdef _WIN64
+ end = GetTickCount64();
+
+ printf("Time: %lld\n", end - start);
+#else
+ clock_gettime(CLOCK_REALTIME, &end);
+
+ printf("Time: %lf\n", (end.tv_sec - start.tv_sec) * 1000.0 + (end.tv_nsec - start.tv_nsec) * 0.000001);
+#endif // _WIN64
+
+
+ print_vector(&initial);
+ print_vector(&result);
+
+ free(versors);
+ return 0;
+}
+*/
+
+
int main()
{
const unsigned int amount = 1000000;
@@ -103,7 +168,7 @@ int main()
#endif // _WIN64
for (int j = 0; j < 1000; j++) {
for (unsigned int i = 0; i < amount; i++) {
- sp_versor_combine2(&versors1[i], &versors2[i], &results[i]);
+ sp_versor_combine(&versors1[i], &versors2[i], &results[i]);
}
}
@@ -127,61 +192,3 @@ int main()
return 0;
}
-/*/
-
-void print_matrix(const DPMatrix3x3* matrix)
-{
- printf("(%lf, %lf, %lf)\n", matrix->r1c1, matrix->r1c2, matrix->r1c3);
- printf("(%lf, %lf, %lf)\n", matrix->r2c1, matrix->r2c2, matrix->r2c3);
- printf("(%lf, %lf, %lf)\n\n", matrix->r3c1, matrix->r3c2, matrix->r3c3);
-}
-/*
-int main()
-{
- DPMatrix3x3 m1, m2, check;
-
- dp_matrix3x3_set_row1(1, 3, 5, &m1);
- dp_matrix3x3_set_row2(2, 2, -1, &m1);
- dp_matrix3x3_set_row3(2, 0, 4, &m1);
-
- printf("Initial matrix:\n");
- print_matrix(&m1);
-
- if (!dp_matrix3x3_make_inverted(&m1, &m2)) {
- printf("Cannot get the inverted matrix.\n");
- return 0;
- }
-
- printf("Inverted matrix:\n");
-
- print_matrix(&m2);
-
- dp_matrix3x3_matrix_product(&m1, &m2, &check);
-
- printf("m1 * m2:\n");
-
- print_matrix(&check);
-
- dp_matrix3x3_matrix_product(&m2, &m1, &check);
-
- printf("m2 * m1:\n");
-
- print_matrix(&check);
-
- return 0;
-}
-*/
-
-int main()
-{
-SPVector2 vector;
-
-sp_vector2_set_values(0, 0, &vector);
-
-printf("SPVector2(%f, %f), module = %d\n",
- vector.x1,
- vector.x2,
- sp_vector2_is_zero(&vector)
-);
- return 0;
-}
diff --git a/src/geometry.layout b/src/geometry.layout
index 8f5c836..fb44107 100644
--- a/src/geometry.layout
+++ b/src/geometry.layout
@@ -2,59 +2,9 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -62,9 +12,19 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+
@@ -72,14 +32,39 @@
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -87,14 +72,24 @@
+
+
+
+
+
-
+
-
+
+
+
+
+
+
@@ -102,6 +97,11 @@
+
+
+
+
+
diff --git a/src/matrixes.c b/src/matrixes.c
index b2cd47e..52921c1 100644
--- a/src/matrixes.c
+++ b/src/matrixes.c
@@ -118,7 +118,7 @@ void dp_matrix_product_2x3_at_3x2(const DPMatrix2x3* matrix1, const DPMatrix3x2*
// ========== Matrix Product 3x2 at 2x3 ========= //
-static inline void sp_matrix_product_3x2_at_2x3(const SPMatrix3x2* matrix1, const SPMatrix2x3* matrix2, SPMatrix2x2* result)
+void sp_matrix_product_3x2_at_2x3(const SPMatrix3x2* matrix1, const SPMatrix2x3* matrix2, SPMatrix2x2* result)
{
result->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
result->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
diff --git a/src/quaternion.c b/src/quaternion.c
index 1e2bd25..c004d3f 100644
--- a/src/quaternion.c
+++ b/src/quaternion.c
@@ -17,17 +17,8 @@ void sp_quaternion_make_matrix(const SPQuaternion* quaternion, SPMatrix3x3* matr
return;
}
- float corrector1;
- float corrector2;
-
- if (1.0f - SP_TWO_EPSYLON <= square_module && square_module <= 1.0f + SP_TWO_EPSYLON) {
- corrector1 = 2.0f - square_module;
- corrector2 = 2.0f * corrector1;
- }
- else {
- corrector1 = 1.0f / square_module;
- corrector2 = 2.0f / square_module;
- }
+ const float corrector1 = 1.0f / square_module;
+ const float corrector2 = 2.0f * corrector1;
const float s0x1 = quaternion->s0 * quaternion->x1;
const float s0x2 = quaternion->s0 * quaternion->x2;
@@ -64,17 +55,8 @@ void dp_quaternion_make_matrix(const DPQuaternion* quaternion, DPMatrix3x3* matr
return;
}
- double corrector1;
- double corrector2;
-
- if (1.0 - DP_TWO_EPSYLON <= square_module && square_module <= 1.0 + DP_TWO_EPSYLON) {
- corrector1 = 2.0 - square_module;
- corrector2 = 2.0 * corrector1;
- }
- else {
- corrector1 = 1.0 / square_module;
- corrector2 = 2.0 / square_module;
- }
+ const double corrector1 = 1.0f / square_module;
+ const double corrector2 = 2.0f * corrector1;
const double s0x1 = quaternion->s0 * quaternion->x1;
const double s0x2 = quaternion->s0 * quaternion->x2;
@@ -113,17 +95,8 @@ void sp_quaternion_make_reverse_matrix(const SPQuaternion* quaternion, SPMatrix3
return;
}
- float corrector1;
- float corrector2;
-
- if (1.0f - SP_TWO_EPSYLON <= square_module && square_module <= 1.0f + SP_TWO_EPSYLON) {
- corrector1 = 2.0f - square_module;
- corrector2 = 2.0f * corrector1;
- }
- else {
- corrector1 = 1.0f / square_module;
- corrector2 = 2.0f / square_module;
- }
+ const float corrector1 = 1.0f / square_module;
+ const float corrector2 = 2.0f * corrector1;
const float s0x1 = quaternion->s0 * quaternion->x1;
const float s0x2 = quaternion->s0 * quaternion->x2;
@@ -160,17 +133,8 @@ void dp_quaternion_make_reverse_matrix(const DPQuaternion* quaternion, DPMatrix3
return;
}
- double corrector1;
- double corrector2;
-
- if (1.0 - DP_TWO_EPSYLON <= square_module && square_module <= 1.0 + DP_TWO_EPSYLON) {
- corrector1 = 2.0 - square_module;
- corrector2 = 2.0 * corrector1;
- }
- else {
- corrector1 = 1.0 / square_module;
- corrector2 = 2.0 / square_module;
- }
+ const double corrector1 = 1.0f / square_module;
+ const double corrector2 = 2.0f * corrector1;
const double s0x1 = quaternion->s0 * quaternion->x1;
const double s0x2 = quaternion->s0 * quaternion->x2;
diff --git a/src/versor.c b/src/versor.c
index 14e106b..d30a2ec 100644
--- a/src/versor.c
+++ b/src/versor.c
@@ -3,11 +3,9 @@
#include "angle.h"
#include "versor.h"
-const uint16_t GEOMETRY_VERSOR_COUNTER_LIMIT = 64;
+const SPVersor SP_IDLE_VERSOR = { 1.0f, 0.0f, 0.0f, 0.0f };
-const SPVersor SP_IDLE_VERSOR = { 1.0f, 1.0f, 0.0f, 0.0f, 0.0f };
-
-const DPVersor DP_IDLE_VERSOR = { 1.0, 1.0, 0.0, 0.0, 0.0 };
+const DPVersor DP_IDLE_VERSOR = { 1.0, 0.0, 0.0, 0.0 };
void __sp_versor_normalize(const float square_module, SPVersor* versor)
{
@@ -27,8 +25,6 @@ void __sp_versor_normalize(const float square_module, SPVersor* versor)
versor->_x1 /= module;
versor->_x2 /= module;
versor->_x3 /= module;
-
- versor->_corrector = 2.0f - (versor->_s0 * versor->_s0 + versor->_x1 * versor->_x1) - (versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3);
}
void __dp_versor_normalize(const double square_module, DPVersor* versor)
@@ -51,8 +47,6 @@ void __dp_versor_normalize(const double square_module, DPVersor* versor)
versor->_x1 /= module;
versor->_x2 /= module;
versor->_x3 /= module;
-
- versor->_corrector = 2.0 - (versor->_s0 * versor->_s0 + versor->_x1 * versor->_x1) - (versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3);
}
// ==================== Make ==================== //
diff --git a/src/versor.h b/src/versor.h
index fa7361e..1130c14 100644
--- a/src/versor.h
+++ b/src/versor.h
@@ -9,11 +9,11 @@
#include "matrix3x3.h"
typedef struct {
- float _corrector, _s0, _x1, _x2, _x3;
+ float _s0, _x1, _x2, _x3;
} SPVersor;
typedef struct {
- double _corrector, _s0, _x1, _x2, _x3;
+ double _s0, _x1, _x2, _x3;
} DPVersor;
extern const SPVersor SP_IDLE_VERSOR;
@@ -23,7 +23,6 @@ extern const DPVersor DP_IDLE_VERSOR;
static inline void sp_versor_reset(SPVersor* versor)
{
- versor->_corrector = 1.0f;
versor->_s0 = 1.0f;
versor->_x1 = 0.0f;
versor->_x2 = 0.0f;
@@ -32,7 +31,6 @@ static inline void sp_versor_reset(SPVersor* versor)
static inline void dp_versor_reset(DPVersor* versor)
{
- versor->_corrector = 1.0;
versor->_s0 = 1.0;
versor->_x1 = 0.0;
versor->_x2 = 0.0;
@@ -104,18 +102,6 @@ static inline double dp_get_x3(const DPVersor* versor)
return versor->_x3;
}
-// ================ Get Corrector =============== //
-
-static inline float sp_get_corrector(const SPVersor* versor)
-{
- return versor->_corrector;
-}
-
-static inline double dp_get_corrector(const DPVersor* versor)
-{
- return versor->_corrector;
-}
-
// ==================== Set ===================== //
void __sp_versor_normalize(const float square_module, SPVersor* versor);
@@ -131,17 +117,16 @@ static inline void sp_versor_set(const float s0, const float x1, const float x2,
const float square_module = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
- if (square_module < 1.0f - SP_TWO_EPSYLON || 1.0f + SP_TWO_EPSYLON < square_module) {
- __sp_versor_normalize(square_module, result);
+ if (1.0f - SP_TWO_EPSYLON <= square_module && square_module <= 1.0f + SP_TWO_EPSYLON) {
+ if (s0 > -1.0f + SP_EPSYLON) {
+ return;
+ }
+
+ sp_versor_reset(result);
return;
}
- if (-1.0f + SP_EPSYLON < s0 && s0 < 1.0f - SP_EPSYLON) {
- result->_corrector = 2.0f - square_module;
- return;
- }
-
- sp_versor_reset(result);
+ __sp_versor_normalize(square_module, result);
}
static inline void dp_versor_set(const double s0, const double x1, const double x2, const double x3, DPVersor* result)
@@ -153,24 +138,22 @@ static inline void dp_versor_set(const double s0, const double x1, const double
const double square_module = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
- if (square_module < 1.0 - DP_TWO_EPSYLON || 1.0 + DP_TWO_EPSYLON < square_module) {
- __dp_versor_normalize(square_module, result);
- return;
- }
+ if (1.0 - DP_TWO_EPSYLON <= square_module && square_module <= 1.0 + DP_TWO_EPSYLON) {
+ if (s0 > -1.0 + DP_EPSYLON) {
+ return;
+ }
- if (s0 < -1.0 + DP_EPSYLON || 1.0 - DP_EPSYLON < s0) {
dp_versor_reset(result);
return;
}
- result->_corrector = 2.0 - square_module;
+ __sp_versor_normalize(square_module, result);
}
// ==================== Copy ==================== //
static inline void sp_versor_copy(const SPVersor* from, SPVersor* to)
{
- to->_corrector = from->_corrector;
to->_s0 = from->_s0;
to->_x1 = from->_x1;
to->_x2 = from->_x2;
@@ -179,7 +162,6 @@ static inline void sp_versor_copy(const SPVersor* from, SPVersor* to)
static inline void dp_versor_copy(const DPVersor* from, DPVersor* to)
{
- to->_corrector = from->_corrector;
to->_s0 = from->_s0;
to->_x1 = from->_x1;
to->_x2 = from->_x2;
@@ -268,7 +250,6 @@ static inline void dp_versor_invert(DPVersor* versor)
static inline void sp_versor_make_inverted(const SPVersor* versor, SPVersor* result)
{
- result->_corrector = versor->_corrector;
result->_s0 = versor->_s0;
result->_x1 = -versor->_x1;
result->_x2 = -versor->_x2;
@@ -277,7 +258,6 @@ static inline void sp_versor_make_inverted(const SPVersor* versor, SPVersor* res
static inline void dp_versor_make_inverted(const DPVersor* versor, DPVersor* result)
{
- result->_corrector = versor->_corrector;
result->_s0 = versor->_s0;
result->_x1 = -versor->_x1;
result->_x2 = -versor->_x2;
@@ -288,52 +268,11 @@ static inline void dp_versor_make_inverted(const DPVersor* versor, DPVersor* res
static inline void sp_versor_combine(const SPVersor* second, const SPVersor* first, SPVersor* result)
{
- const float s0s0 = second->_s0 * first->_s0;
- const float x1s0 = second->_x1 * first->_s0;
- const float x2s0 = second->_x2 * first->_s0;
- const float x3s0 = second->_x3 * first->_s0;
-
- const float s0x1 = second->_s0 * first->_x1;
- const float x1x1 = second->_x1 * first->_x1;
- const float x2x1 = second->_x2 * first->_x1;
- const float x3x1 = second->_x3 * first->_x1;
-
- const float s0x2 = second->_s0 * first->_x2;
- const float x1x2 = second->_x1 * first->_x2;
- const float x2x2 = second->_x2 * first->_x2;
- const float x3x2 = second->_x3 * first->_x2;
-
- const float s0x3 = second->_s0 * first->_x3;
- const float x1x3 = second->_x1 * first->_x3;
- const float x2x3 = second->_x2 * first->_x3;
- const float x3x3 = second->_x3 * first->_x3;
-
- const float s0b = (x2x2 + x3x3);
- const float x1a = (x1s0 + s0x1);
- const float x2a = (x2s0 + s0x2);
- const float x3a = (x3s0 + s0x3);
-
- const float s0a = (s0s0 - x1x1);
- const float x1b = (x3x2 - x2x3);
- const float x2b = (x1x3 - x3x1);
- const float x3b = (x2x1 - x1x2);
-
sp_versor_set(
- s0a - s0b,
- x1a - x1b,
- x2a - x2b,
- x3a - x3b,
- result
- );
-}
-
-static inline void sp_versor_combine2(const SPVersor* second, const SPVersor* first, SPVersor* result)
-{
- sp_versor_set(
- ((second->_s0 * first->_s0 - second->_x1 * first->_x1) - (second->_x2 * first->_x2 + second->_x3 * first->_x3)),
- ((second->_x1 * first->_s0 + second->_s0 * first->_x1) - (second->_x3 * first->_x2 - second->_x2 * first->_x3)),
- ((second->_x2 * first->_s0 + second->_s0 * first->_x2) - (second->_x1 * first->_x3 - second->_x3 * first->_x1)),
- ((second->_x3 * first->_s0 + second->_s0 * first->_x3) - (second->_x2 * first->_x1 - second->_x1 * first->_x2)),
+ (second->_s0 * first->_s0 - second->_x1 * first->_x1) - (second->_x2 * first->_x2 + second->_x3 * first->_x3),
+ (second->_x1 * first->_s0 + second->_s0 * first->_x1) - (second->_x3 * first->_x2 - second->_x2 * first->_x3),
+ (second->_x2 * first->_s0 + second->_s0 * first->_x2) - (second->_x1 * first->_x3 - second->_x3 * first->_x1),
+ (second->_x3 * first->_s0 + second->_s0 * first->_x3) - (second->_x2 * first->_x1 - second->_x1 * first->_x2),
result
);
}
@@ -364,27 +303,25 @@ static inline void sp_versor_make_matrix(const SPVersor* versor, SPMatrix3x3* ma
const float x2x2 = versor->_x2 * versor->_x2;
const float x3x3 = versor->_x3 * versor->_x3;
- const float s0x1 = versor->_s0 * versor->_x1;
- const float s0x2 = versor->_s0 * versor->_x2;
- const float s0x3 = versor->_s0 * versor->_x3;
+ const float s0x1 = 2.0f * versor->_s0 * versor->_x1;
+ const float s0x2 = 2.0f * versor->_s0 * versor->_x2;
+ const float s0x3 = 2.0f * versor->_s0 * versor->_x3;
- const float x1x2 = versor->_x1 * versor->_x2;
- const float x1x3 = versor->_x1 * versor->_x3;
- const float x2x3 = versor->_x2 * versor->_x3;
+ const float x1x2 = 2.0f * versor->_x1 * versor->_x2;
+ const float x1x3 = 2.0f * versor->_x1 * versor->_x3;
+ const float x2x3 = 2.0f * versor->_x2 * versor->_x3;
- const float corrector2 = 2.0f * versor->_corrector;
+ matrix->r1c1 = (s0s0 + x1x1) - (x2x2 + x3x3);
+ matrix->r2c2 = (s0s0 + x2x2) - (x1x1 + x3x3);
+ matrix->r3c3 = (s0s0 + x3x3) - (x1x1 + x2x2);
- matrix->r1c1 = versor->_corrector * ((s0s0 + x1x1) - (x2x2 + x3x3));
- matrix->r2c2 = versor->_corrector * ((s0s0 + x2x2) - (x1x1 + x3x3));
- matrix->r3c3 = versor->_corrector * ((s0s0 + x3x3) - (x1x1 + x2x2));
+ matrix->r1c2 = x1x2 - s0x3;
+ matrix->r2c3 = x2x3 - s0x1;
+ matrix->r3c1 = x1x3 - s0x2;
- matrix->r1c2 = corrector2 * (x1x2 - s0x3);
- matrix->r2c3 = corrector2 * (x2x3 - s0x1);
- matrix->r3c1 = corrector2 * (x1x3 - s0x2);
-
- matrix->r2c1 = corrector2 * (x1x2 + s0x3);
- matrix->r3c2 = corrector2 * (x2x3 + s0x1);
- matrix->r1c3 = corrector2 * (x1x3 + s0x2);
+ matrix->r2c1 = x1x2 + s0x3;
+ matrix->r3c2 = x2x3 + s0x1;
+ matrix->r1c3 = x1x3 + s0x2;
}
static inline void dp_versor_make_matrix(const DPVersor* versor, DPMatrix3x3* matrix)
@@ -394,27 +331,25 @@ static inline void dp_versor_make_matrix(const DPVersor* versor, DPMatrix3x3* ma
const double x2x2 = versor->_x2 * versor->_x2;
const double x3x3 = versor->_x3 * versor->_x3;
- const double s0x1 = versor->_s0 * versor->_x1;
- const double s0x2 = versor->_s0 * versor->_x2;
- const double s0x3 = versor->_s0 * versor->_x3;
+ const double s0x1 = 2.0 * versor->_s0 * versor->_x1;
+ const double s0x2 = 2.0 * versor->_s0 * versor->_x2;
+ const double s0x3 = 2.0 * versor->_s0 * versor->_x3;
- const double x1x2 = versor->_x1 * versor->_x2;
- const double x1x3 = versor->_x1 * versor->_x3;
- const double x2x3 = versor->_x2 * versor->_x3;
+ const double x1x2 = 2.0 * versor->_x1 * versor->_x2;
+ const double x1x3 = 2.0 * versor->_x1 * versor->_x3;
+ const double x2x3 = 2.0 * versor->_x2 * versor->_x3;
- const double corrector2 = 2.0 * versor->_corrector;
+ matrix->r1c1 = (s0s0 + x1x1) - (x2x2 + x3x3);
+ matrix->r2c2 = (s0s0 + x2x2) - (x1x1 + x3x3);
+ matrix->r3c3 = (s0s0 + x3x3) - (x1x1 + x2x2);
- matrix->r1c1 = versor->_corrector * ((s0s0 + x1x1) - (x2x2 + x3x3));
- matrix->r2c2 = versor->_corrector * ((s0s0 + x2x2) - (x1x1 + x3x3));
- matrix->r3c3 = versor->_corrector * ((s0s0 + x3x3) - (x1x1 + x2x2));
+ matrix->r1c2 = x1x2 - s0x3;
+ matrix->r2c3 = x2x3 - s0x1;
+ matrix->r3c1 = x1x3 - s0x2;
- matrix->r1c2 = corrector2 * (x1x2 - s0x3);
- matrix->r2c3 = corrector2 * (x2x3 - s0x1);
- matrix->r3c1 = corrector2 * (x1x3 - s0x2);
-
- matrix->r2c1 = corrector2 * (x1x2 + s0x3);
- matrix->r3c2 = corrector2 * (x2x3 + s0x1);
- matrix->r1c3 = corrector2 * (x1x3 + s0x2);
+ matrix->r2c1 = x1x2 + s0x3;
+ matrix->r3c2 = x2x3 + s0x1;
+ matrix->r1c3 = x1x3 + s0x2;
}
// =========== Make Reverse Matrix3x3 =========== //
@@ -426,27 +361,25 @@ static inline void sp_versor_make_reverse_matrix(const SPVersor* versor, SPMatri
const float x2x2 = versor->_x2 * versor->_x2;
const float x3x3 = versor->_x3 * versor->_x3;
- const float s0x1 = versor->_s0 * versor->_x1;
- const float s0x2 = versor->_s0 * versor->_x2;
- const float s0x3 = versor->_s0 * versor->_x3;
+ const float s0x1 = 2.0f * versor->_s0 * versor->_x1;
+ const float s0x2 = 2.0f * versor->_s0 * versor->_x2;
+ const float s0x3 = 2.0f * versor->_s0 * versor->_x3;
- const float x1x2 = versor->_x1 * versor->_x2;
- const float x1x3 = versor->_x1 * versor->_x3;
- const float x2x3 = versor->_x2 * versor->_x3;
+ const float x1x2 = 2.0f * versor->_x1 * versor->_x2;
+ const float x1x3 = 2.0f * versor->_x1 * versor->_x3;
+ const float x2x3 = 2.0f * versor->_x2 * versor->_x3;
- const float corrector2 = 2.0f * versor->_corrector;
+ matrix->r1c1 = (s0s0 + x1x1) - (x2x2 + x3x3);
+ matrix->r2c2 = (s0s0 + x2x2) - (x1x1 + x3x3);
+ matrix->r3c3 = (s0s0 + x3x3) - (x1x1 + x2x2);
- matrix->r1c1 = versor->_corrector * ((s0s0 + x1x1) - (x2x2 + x3x3));
- matrix->r2c2 = versor->_corrector * ((s0s0 + x2x2) - (x1x1 + x3x3));
- matrix->r3c3 = versor->_corrector * ((s0s0 + x3x3) - (x1x1 + x2x2));
+ matrix->r1c2 = x1x2 + s0x3;
+ matrix->r2c3 = x2x3 + s0x1;
+ matrix->r3c1 = x1x3 + s0x2;
- matrix->r1c2 = corrector2 * (x1x2 + s0x3);
- matrix->r2c3 = corrector2 * (x2x3 + s0x1);
- matrix->r3c1 = corrector2 * (x1x3 + s0x2);
-
- matrix->r2c1 = corrector2 * (x1x2 - s0x3);
- matrix->r3c2 = corrector2 * (x2x3 - s0x1);
- matrix->r1c3 = corrector2 * (x1x3 - s0x2);
+ matrix->r2c1 = x1x2 - s0x3;
+ matrix->r3c2 = x2x3 - s0x1;
+ matrix->r1c3 = x1x3 - s0x2;
}
static inline void dp_versor_make_reverse_matrix(const DPVersor* versor, DPMatrix3x3* matrix)
@@ -456,37 +389,34 @@ static inline void dp_versor_make_reverse_matrix(const DPVersor* versor, DPMatri
const double x2x2 = versor->_x2 * versor->_x2;
const double x3x3 = versor->_x3 * versor->_x3;
- const double s0x1 = versor->_s0 * versor->_x1;
- const double s0x2 = versor->_s0 * versor->_x2;
- const double s0x3 = versor->_s0 * versor->_x3;
+ const double s0x1 = 2.0 * versor->_s0 * versor->_x1;
+ const double s0x2 = 2.0 * versor->_s0 * versor->_x2;
+ const double s0x3 = 2.0 * versor->_s0 * versor->_x3;
- const double x1x2 = versor->_x1 * versor->_x2;
- const double x1x3 = versor->_x1 * versor->_x3;
- const double x2x3 = versor->_x2 * versor->_x3;
+ const double x1x2 = 2.0 * versor->_x1 * versor->_x2;
+ const double x1x3 = 2.0 * versor->_x1 * versor->_x3;
+ const double x2x3 = 2.0 * versor->_x2 * versor->_x3;
- const double corrector2 = 2.0 * versor->_corrector;
+ matrix->r1c1 = (s0s0 + x1x1) - (x2x2 + x3x3);
+ matrix->r2c2 = (s0s0 + x2x2) - (x1x1 + x3x3);
+ matrix->r3c3 = (s0s0 + x3x3) - (x1x1 + x2x2);
- matrix->r1c1 = versor->_corrector * ((s0s0 + x1x1) - (x2x2 + x3x3));
- matrix->r2c2 = versor->_corrector * ((s0s0 + x2x2) - (x1x1 + x3x3));
- matrix->r3c3 = versor->_corrector * ((s0s0 + x3x3) - (x1x1 + x2x2));
+ matrix->r1c2 = x1x2 + s0x3;
+ matrix->r2c3 = x2x3 + s0x1;
+ matrix->r3c1 = x1x3 + s0x2;
- matrix->r1c2 = corrector2 * (x1x2 + s0x3);
- matrix->r2c3 = corrector2 * (x2x3 + s0x1);
- matrix->r3c1 = corrector2 * (x1x3 + s0x2);
-
- matrix->r2c1 = corrector2 * (x1x2 - s0x3);
- matrix->r3c2 = corrector2 * (x2x3 - s0x1);
- matrix->r1c3 = corrector2 * (x1x3 - s0x2);
+ matrix->r2c1 = x1x2 - s0x3;
+ matrix->r3c2 = x2x3 - s0x1;
+ matrix->r1c3 = x1x3 - s0x2;
}
// ================ Turn Vector ================= //
static inline void sp_versor_turn(const SPVersor* versor, const SPVector3* vector, SPVector3* result)
{
- const float multiplier = 2.0f * versor->_corrector;
- const float tx1 = multiplier * (versor->_x2 * vector->x3 - versor->_x3 * vector->x2);
- const float tx2 = multiplier * (versor->_x3 * vector->x1 - versor->_x1 * vector->x3);
- const float tx3 = multiplier * (versor->_x1 * vector->x2 - versor->_x2 * vector->x1);
+ const float tx1 = 2.0f * (versor->_x2 * vector->x3 - versor->_x3 * vector->x2);
+ const float tx2 = 2.0f * (versor->_x3 * vector->x1 - versor->_x1 * vector->x3);
+ const float tx3 = 2.0f * (versor->_x1 * vector->x2 - versor->_x2 * vector->x1);
const float x1 = (vector->x1 + tx1 * versor->_s0) + (versor->_x2 * tx3 - versor->_x3 * tx2);
const float x2 = (vector->x2 + tx2 * versor->_s0) + (versor->_x3 * tx1 - versor->_x1 * tx3);
@@ -499,10 +429,9 @@ static inline void sp_versor_turn(const SPVersor* versor, const SPVector3* vecto
static inline void dp_versor_turn(const DPVersor* versor, const DPVector3* vector, DPVector3* result)
{
- const double multiplier = 2.0 * versor->_corrector;
- const double tx1 = multiplier * (versor->_x2 * vector->x3 - versor->_x3 * vector->x2);
- const double tx2 = multiplier * (versor->_x3 * vector->x1 - versor->_x1 * vector->x3);
- const double tx3 = multiplier * (versor->_x1 * vector->x2 - versor->_x2 * vector->x1);
+ const double tx1 = 2.0 * (versor->_x2 * vector->x3 - versor->_x3 * vector->x2);
+ const double tx2 = 2.0 * (versor->_x3 * vector->x1 - versor->_x1 * vector->x3);
+ const double tx3 = 2.0 * (versor->_x1 * vector->x2 - versor->_x2 * vector->x1);
const double x1 = (vector->x1 + tx1 * versor->_s0) + (versor->_x2 * tx3 - versor->_x3 * tx2);
const double x2 = (vector->x2 + tx2 * versor->_s0) + (versor->_x3 * tx1 - versor->_x1 * tx3);
@@ -513,14 +442,87 @@ static inline void dp_versor_turn(const DPVersor* versor, const DPVector3* vecto
result->x3 = x3;
}
+// ================ Turn2 Vector ================ //
+
+static inline void sp_versor_turn2(const SPVersor* versor, const SPVector3* vector, SPVector3* result)
+{
+ 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 s0x1 = 2.0f * versor->_s0 * versor->_x1;
+ const float s0x2 = 2.0f * versor->_s0 * versor->_x2;
+ const float s0x3 = 2.0f * versor->_s0 * versor->_x3;
+
+ const float x1x2 = 2.0f * versor->_x1 * versor->_x2;
+ const float x1x3 = 2.0f * versor->_x1 * versor->_x3;
+ const float x2x3 = 2.0f * versor->_x2 * versor->_x3;
+
+ const float r2c1 = x1x2 + s0x3;
+ const float r3c2 = x2x3 + s0x1;
+ const float r1c3 = x1x3 + s0x2;
+
+ const float r1c1 = (s0s0 + x1x1) - (x2x2 + x3x3);
+ const float r2c2 = (s0s0 + x2x2) - (x1x1 + x3x3);
+ const float r3c3 = (s0s0 + x3x3) - (x1x1 + x2x2);
+
+ const float r1c2 = x1x2 - s0x3;
+ const float r2c3 = x2x3 - s0x1;
+ const float r3c1 = x1x3 - s0x2;
+
+ const float x1 = r1c1 * vector->x1 + r1c2 * vector->x2 + r1c3 * vector->x3;
+ const float x2 = r2c1 * vector->x1 + r2c2 * vector->x2 + r2c3 * vector->x3;
+ const float x3 = r3c1 * vector->x1 + r3c2 * vector->x2 + r3c3 * vector->x3;
+
+ result->x1 = x1;
+ result->x2 = x2;
+ result->x3 = x3;
+}
+
+static inline void dp_versor_turn2(const DPVersor* versor, const DPVector3* vector, DPVector3* result)
+{
+ 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 s0x1 = 2.0f * versor->_s0 * versor->_x1;
+ const double s0x2 = 2.0f * versor->_s0 * versor->_x2;
+ const double s0x3 = 2.0f * versor->_s0 * versor->_x3;
+
+ const double x1x2 = 2.0f * versor->_x1 * versor->_x2;
+ const double x1x3 = 2.0f * versor->_x1 * versor->_x3;
+ const double x2x3 = 2.0f * versor->_x2 * versor->_x3;
+
+ const double r2c1 = x1x2 + s0x3;
+ const double r3c2 = x2x3 + s0x1;
+ const double r1c3 = x1x3 + s0x2;
+
+ const double r1c1 = (s0s0 + x1x1) - (x2x2 + x3x3);
+ const double r2c2 = (s0s0 + x2x2) - (x1x1 + x3x3);
+ const double r3c3 = (s0s0 + x3x3) - (x1x1 + x2x2);
+
+ const double r1c2 = x1x2 - s0x3;
+ const double r2c3 = x2x3 - s0x1;
+ const double r3c1 = x1x3 - s0x2;
+
+ const double x1 = r1c1 * vector->x1 + r1c2 * vector->x2 + r1c3 * vector->x3;
+ const double x2 = r2c1 * vector->x1 + r2c2 * vector->x2 + r2c3 * vector->x3;
+ const double x3 = r3c1 * vector->x1 + r3c2 * vector->x2 + r3c3 * vector->x3;
+
+ result->x1 = x1;
+ result->x2 = x2;
+ result->x3 = x3;
+}
+
// ============== Turn Vector Back ============== //
static inline void sp_versor_turn_back(const SPVersor* versor, const SPVector3* vector, SPVector3* result)
{
- const float multiplier = 2.0f * versor->_corrector;
- const float tx1 = multiplier * (versor->_x2 * vector->x3 - versor->_x3 * vector->x2);
- const float tx2 = multiplier * (versor->_x3 * vector->x1 - versor->_x1 * vector->x3);
- const float tx3 = multiplier * (versor->_x1 * vector->x2 - versor->_x2 * vector->x1);
+ const float tx1 = 2.0f * (versor->_x2 * vector->x3 - versor->_x3 * vector->x2);
+ const float tx2 = 2.0f * (versor->_x3 * vector->x1 - versor->_x1 * vector->x3);
+ const float tx3 = 2.0f * (versor->_x1 * vector->x2 - versor->_x2 * vector->x1);
const float x1 = (vector->x1 - tx1 * versor->_s0) + (versor->_x2 * tx3 - versor->_x3 * tx2);
const float x2 = (vector->x2 - tx2 * versor->_s0) + (versor->_x3 * tx1 - versor->_x1 * tx3);
@@ -533,10 +535,9 @@ static inline void sp_versor_turn_back(const SPVersor* versor, const SPVector3*
static inline void dp_versor_turn_back(const DPVersor* versor, const DPVector3* vector, DPVector3* result)
{
- const double multiplier = 2.0 * versor->_corrector;
- const double tx1 = multiplier * (versor->_x2 * vector->x3 - versor->_x3 * vector->x2);
- const double tx2 = multiplier * (versor->_x3 * vector->x1 - versor->_x1 * vector->x3);
- const double tx3 = multiplier * (versor->_x1 * vector->x2 - versor->_x2 * vector->x1);
+ const double tx1 = 2.0 * (versor->_x2 * vector->x3 - versor->_x3 * vector->x2);
+ const double tx2 = 2.0 * (versor->_x3 * vector->x1 - versor->_x1 * vector->x3);
+ const double tx3 = 2.0 * (versor->_x1 * vector->x2 - versor->_x2 * vector->x1);
const double x1 = (vector->x1 - tx1 * versor->_s0) + (versor->_x2 * tx3 - versor->_x3 * tx2);
const double x2 = (vector->x2 - tx2 * versor->_s0) + (versor->_x3 * tx1 - versor->_x1 * tx3);
@@ -547,4 +548,78 @@ static inline void dp_versor_turn_back(const DPVersor* versor, const DPVector3*
result->x3 = x3;
}
+// ============== Turn Vector Back2 ============= //
+
+static inline void sp_versor_turn_back2(const SPVersor* versor, const SPVector3* vector, SPVector3* result)
+{
+ 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 s0x1 = 2.0f * versor->_s0 * versor->_x1;
+ const float s0x2 = 2.0f * versor->_s0 * versor->_x2;
+ const float s0x3 = 2.0f * versor->_s0 * versor->_x3;
+
+ const float x1x2 = 2.0f * versor->_x1 * versor->_x2;
+ const float x1x3 = 2.0f * versor->_x1 * versor->_x3;
+ const float x2x3 = 2.0f * versor->_x2 * versor->_x3;
+
+ const float r1c2 = x1x2 + s0x3;
+ const float r2c3 = x2x3 + s0x1;
+ const float r3c1 = x1x3 + s0x2;
+
+ const float r1c1 = (s0s0 + x1x1) - (x2x2 + x3x3);
+ const float r2c2 = (s0s0 + x2x2) - (x1x1 + x3x3);
+ const float r3c3 = (s0s0 + x3x3) - (x1x1 + x2x2);
+
+ const float r2c1 = x1x2 - s0x3;
+ const float r3c2 = x2x3 - s0x1;
+ const float r1c3 = x1x3 - s0x2;
+
+ const float x1 = r1c1 * vector->x1 + r1c2 * vector->x2 + r1c3 * vector->x3;
+ const float x2 = r2c1 * vector->x1 + r2c2 * vector->x2 + r2c3 * vector->x3;
+ const float x3 = r3c1 * vector->x1 + r3c2 * vector->x2 + r3c3 * vector->x3;
+
+ result->x1 = x1;
+ result->x2 = x2;
+ result->x3 = x3;
+}
+
+static inline void dp_versor_turn_back2(const DPVersor* versor, const DPVector3* vector, DPVector3* result)
+{
+ 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 s0x1 = 2.0f * versor->_s0 * versor->_x1;
+ const double s0x2 = 2.0f * versor->_s0 * versor->_x2;
+ const double s0x3 = 2.0f * versor->_s0 * versor->_x3;
+
+ const double x1x2 = 2.0f * versor->_x1 * versor->_x2;
+ const double x1x3 = 2.0f * versor->_x1 * versor->_x3;
+ const double x2x3 = 2.0f * versor->_x2 * versor->_x3;
+
+ const double r1c2 = x1x2 + s0x3;
+ const double r2c3 = x2x3 + s0x1;
+ const double r3c1 = x1x3 + s0x2;
+
+ const double r1c1 = (s0s0 + x1x1) - (x2x2 + x3x3);
+ const double r2c2 = (s0s0 + x2x2) - (x1x1 + x3x3);
+ const double r3c3 = (s0s0 + x3x3) - (x1x1 + x2x2);
+
+ const double r2c1 = x1x2 - s0x3;
+ const double r3c2 = x2x3 - s0x1;
+ const double r1c3 = x1x3 - s0x2;
+
+ const double x1 = r1c1 * vector->x1 + r1c2 * vector->x2 + r1c3 * vector->x3;
+ const double x2 = r2c1 * vector->x1 + r2c2 * vector->x2 + r2c3 * vector->x3;
+ const double x3 = r3c1 * vector->x1 + r3c2 * vector->x2 + r3c3 * vector->x3;
+
+ result->x1 = x1;
+ result->x2 = x2;
+ result->x3 = x3;
+}
+
#endif
diff --git a/test/geometry-test.layout b/test/geometry-test.layout
index 856595e..ff89a45 100644
--- a/test/geometry-test.layout
+++ b/test/geometry-test.layout
@@ -2,6 +2,11 @@
+
+
+
+
+
@@ -12,9 +17,4 @@
-
-
-
-
-