Задача 0000001: отказ от использования корректоров в версорах / Task 0000001: declining of usage of correctors in versors

This commit is contained in:
Andrey Pokidov 2024-11-19 14:21:01 +07:00
parent 07c1330858
commit 791557fb94
9 changed files with 421 additions and 364 deletions

View file

@ -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