#ifndef _BGC_VERSOR_H_ #define _BGC_VERSOR_H_ #include #include "utilities.h" #include "angle.h" #include "vector3.h" #include "rotation3.h" #include "matrix3x3.h" #include "quaternion.h" #define BGC_SOME_TURN 1 #define BGC_ZERO_TURN 0 #define BGC_OPPOSITE -1 #define BGC_ERROR_PRIMARY_DIRECTION_UNKNOWN -3001 #define BGC_ERROR_PRIMARY_VECTOR_IS_ZERO -3002 #define BGC_ERROR_AUXILIARY_DIRECTION_UNKNOWN -3011 #define BGC_ERROR_AUXILIARY_VECTOR_IS_ZERO -3012 #define BGC_ERROR_DIRECTIONS_PARALLEL -3021 #define BGC_ERROR_VECTORS_PARALLEL -3022 // =================== Types ==================== // typedef struct { float _s0, _x1, _x2, _x3; } BGC_FP32_Versor; typedef struct { double _s0, _x1, _x2, _x3; } BGC_FP64_Versor; // ================= Constants ================== // extern const BGC_FP32_Versor BGC_FP32_IDLE_VERSOR; extern const BGC_FP64_Versor BGC_FP64_IDLE_VERSOR; // =================== Reset ==================== // inline void bgc_fp32_versor_reset(BGC_FP32_Versor* versor) { versor->_s0 = 1.0f; versor->_x1 = 0.0f; versor->_x2 = 0.0f; versor->_x3 = 0.0f; } inline void bgc_fp64_versor_reset(BGC_FP64_Versor* versor) { versor->_s0 = 1.0; versor->_x1 = 0.0; versor->_x2 = 0.0; versor->_x3 = 0.0; } // ==================== Set ===================== // void _bgc_fp32_versor_normalize(BGC_FP32_Versor* twin); void _bgc_fp64_versor_normalize(BGC_FP64_Versor* twin); inline void bgc_fp32_versor_make(BGC_FP32_Versor* versor, const float s0, const float x1, const float x2, const float x3) { versor->_s0 = s0; versor->_x1 = x1; versor->_x2 = x2; versor->_x3 = x3; const float square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3); if (!bgc_fp32_is_square_unit(square_modulus)) { _bgc_fp32_versor_normalize(versor); } } inline void bgc_fp64_versor_make(BGC_FP64_Versor* versor, const double s0, const double x1, const double x2, const double x3) { versor->_s0 = s0; versor->_x1 = x1; versor->_x2 = x2; versor->_x3 = x3; const double square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3); if (!bgc_fp64_is_square_unit(square_modulus)) { _bgc_fp64_versor_normalize(versor); } } // ================== Set Turn ================== // void bgc_fp32_versor_make_for_turn(BGC_FP32_Versor* versor, const float x1, const float x2, const float x3, const float angle, const int unit); void bgc_fp64_versor_make_for_turn(BGC_FP64_Versor* versor, const double x1, const double x2, const double x3, const double angle, const int unit); // ================ Set Rotation ================ // inline void bgc_fp32_versor_make_for_rotation(BGC_FP32_Versor* versor, const BGC_FP32_Rotation3* rotation) { bgc_fp32_versor_make_for_turn(versor, rotation->axis.x1, rotation->axis.x2, rotation->axis.x3, rotation->radians, BGC_ANGLE_UNIT_RADIANS); } inline void bgc_fp64_versor_make_for_rotation(BGC_FP64_Versor* versor, const BGC_FP64_Rotation3* rotation) { bgc_fp64_versor_make_for_turn(versor, rotation->axis.x1, rotation->axis.x2, rotation->axis.x3, rotation->radians, BGC_ANGLE_UNIT_RADIANS); } // ========= Make Direction Difference ========== // int bgc_fp32_versor_make_direction_difference(BGC_FP32_Versor* difference, const BGC_FP32_Vector3* start, const BGC_FP32_Vector3* end); int bgc_fp64_versor_make_direction_difference(BGC_FP64_Versor* difference, const BGC_FP64_Vector3* start, const BGC_FP64_Vector3* end); // =============== Set Directions =============== // int bgc_fp32_versor_make_basis_difference( BGC_FP32_Versor* versor, const BGC_FP32_Vector3* initial_primary_direction, const BGC_FP32_Vector3* initial_auxiliary_direction, const BGC_FP32_Vector3* final_primary_direction, const BGC_FP32_Vector3* final_auxiliary_direction ); int bgc_fp64_versor_make_basis_difference( BGC_FP64_Versor* versor, const BGC_FP64_Vector3* initial_primary_direction, const BGC_FP64_Vector3* initial_auxiliary_direction, const BGC_FP64_Vector3* final_primary_direction, const BGC_FP64_Vector3* final_auxiliary_direction ); // ==================== Copy ==================== // inline void bgc_fp32_versor_copy(BGC_FP32_Versor* destination, const BGC_FP32_Versor* source) { destination->_s0 = source->_s0; destination->_x1 = source->_x1; destination->_x2 = source->_x2; destination->_x3 = source->_x3; } inline void bgc_fp64_versor_copy(BGC_FP64_Versor* destination, const BGC_FP64_Versor* source) { destination->_s0 = source->_s0; destination->_x1 = source->_x1; destination->_x2 = source->_x2; destination->_x3 = source->_x3; } // ==================== Swap ==================== // inline void bgc_fp32_versor_swap(BGC_FP32_Versor* versor1, BGC_FP32_Versor* versor2) { const float s0 = versor1->_s0; const float x1 = versor1->_x1; const float x2 = versor1->_x2; const float x3 = versor1->_x3; versor1->_s0 = versor2->_s0; versor1->_x1 = versor2->_x1; versor1->_x2 = versor2->_x2; versor1->_x3 = versor2->_x3; versor2->_s0 = s0; versor2->_x1 = x1; versor2->_x2 = x2; versor2->_x3 = x3; } inline void bgc_fp64_versor_swap(BGC_FP64_Versor* versor1, BGC_FP64_Versor* versor2) { const double s0 = versor1->_s0; const double x1 = versor1->_x1; const double x2 = versor1->_x2; const double x3 = versor1->_x3; versor1->_s0 = versor2->_s0; versor1->_x1 = versor2->_x1; versor1->_x2 = versor2->_x2; versor1->_x3 = versor2->_x3; versor2->_s0 = s0; versor2->_x1 = x1; versor2->_x2 = x2; versor2->_x3 = x3; } // ================= Comparison ================= // inline int bgc_fp32_versor_is_idle(const BGC_FP32_Versor* versor) { return versor->_x1 * versor->_x1 + versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3 <= BGC_FP32_SQUARE_EPSILON; } inline int bgc_fp64_versor_is_idle(const BGC_FP64_Versor* versor) { return versor->_x1 * versor->_x1 + versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3 <= BGC_FP64_SQUARE_EPSILON; } // ================== Convert =================== // inline void bgc_fp32_versor_convert_to_fp64(BGC_FP64_Versor* destination, const BGC_FP32_Versor* source) { bgc_fp64_versor_make( destination, source->_s0, source->_x1, source->_x2, source->_x3 ); } inline void bgc_fp64_versor_convert_to_fp32(BGC_FP32_Versor* destination, const BGC_FP64_Versor* source) { bgc_fp32_versor_make( destination, (float)source->_s0, (float)source->_x1, (float)source->_x2, (float)source->_x3 ); } // ================== Shorten =================== // inline void bgc_fp32_versor_shorten(BGC_FP32_Versor* versor) { if (versor->_s0 < 0.0f) { versor->_s0 = -versor->_s0; versor->_x1 = -versor->_x1; versor->_x2 = -versor->_x2; versor->_x3 = -versor->_x3; } } inline void bgc_fp64_versor_shorten(BGC_FP64_Versor* versor) { if (versor->_s0 < 0.0) { versor->_s0 = -versor->_s0; versor->_x1 = -versor->_x1; versor->_x2 = -versor->_x2; versor->_x3 = -versor->_x3; } } inline void bgc_fp32_versor_get_shortened(BGC_FP32_Versor* shortened, const BGC_FP32_Versor* versor) { if (versor->_s0 >= 0.0f) { shortened->_s0 = versor->_s0; shortened->_x1 = versor->_x1; shortened->_x2 = versor->_x2; shortened->_x3 = versor->_x3; return; } shortened->_s0 = -versor->_s0; shortened->_x1 = -versor->_x1; shortened->_x2 = -versor->_x2; shortened->_x3 = -versor->_x3; } inline void bgc_fp64_versor_get_shortened(BGC_FP64_Versor* shortened, const BGC_FP64_Versor* versor) { if (versor->_s0 >= 0.0) { shortened->_s0 = versor->_s0; shortened->_x1 = versor->_x1; shortened->_x2 = versor->_x2; shortened->_x3 = versor->_x3; return; } shortened->_s0 = -versor->_s0; shortened->_x1 = -versor->_x1; shortened->_x2 = -versor->_x2; shortened->_x3 = -versor->_x3; } // ================== Negative ================== // inline void bgc_fp32_versor_alternate(BGC_FP32_Versor* versor) { versor->_s0 = -versor->_s0; versor->_x1 = -versor->_x1; versor->_x2 = -versor->_x2; versor->_x3 = -versor->_x3; } inline void bgc_fp64_versor_alternate(BGC_FP64_Versor* versor) { versor->_s0 = -versor->_s0; versor->_x1 = -versor->_x1; versor->_x2 = -versor->_x2; versor->_x3 = -versor->_x3; } inline void bgc_fp32_versor_get_alternative(BGC_FP32_Versor* alternative, const BGC_FP32_Versor* versor) { alternative->_s0 = -versor->_s0; alternative->_x1 = -versor->_x1; alternative->_x2 = -versor->_x2; alternative->_x3 = -versor->_x3; } inline void bgc_fp64_versor_get_alternative(BGC_FP64_Versor* alternative, const BGC_FP64_Versor* versor) { alternative->_s0 = -versor->_s0; alternative->_x1 = -versor->_x1; alternative->_x2 = -versor->_x2; alternative->_x3 = -versor->_x3; } // =================== Invert =================== // inline void bgc_fp32_versor_revert(BGC_FP32_Versor* versor) { versor->_x1 = -versor->_x1; versor->_x2 = -versor->_x2; versor->_x3 = -versor->_x3; } inline void bgc_fp64_versor_revert(BGC_FP64_Versor* versor) { versor->_x1 = -versor->_x1; versor->_x2 = -versor->_x2; versor->_x3 = -versor->_x3; } inline void bgc_fp32_versor_get_reverse(BGC_FP32_Versor* inverse, const BGC_FP32_Versor* versor) { inverse->_s0 = versor->_s0; inverse->_x1 = -versor->_x1; inverse->_x2 = -versor->_x2; inverse->_x3 = -versor->_x3; } inline void bgc_fp64_versor_get_reverse(BGC_FP64_Versor* inverse, const BGC_FP64_Versor* versor) { inverse->_s0 = versor->_s0; inverse->_x1 = -versor->_x1; inverse->_x2 = -versor->_x2; inverse->_x3 = -versor->_x3; } // =============== Get Exponation =============== // void bgc_fp32_versor_get_exponation(BGC_FP32_Versor* power, const BGC_FP32_Versor* base, const float exponent); void bgc_fp64_versor_get_exponation(BGC_FP64_Versor* power, const BGC_FP64_Versor* base, const double exponent); // ================ Combination ================= // inline void bgc_fp32_versor_combine(BGC_FP32_Versor* combination, const BGC_FP32_Versor* first, const BGC_FP32_Versor* second) { bgc_fp32_versor_make( combination, (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) ); } inline void bgc_fp64_versor_combine(BGC_FP64_Versor* combination, const BGC_FP64_Versor* first, const BGC_FP64_Versor* second) { bgc_fp64_versor_make( combination, (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) ); } // ============ Combination of three ============ // inline void bgc_fp32_versor_combine3(BGC_FP32_Versor* combination, const BGC_FP32_Versor* first, const BGC_FP32_Versor* second, const BGC_FP32_Versor* third) { const float s0 = (second->_s0 * first->_s0 - second->_x1 * first->_x1) - (second->_x2 * first->_x2 + second->_x3 * first->_x3); const float x1 = (second->_x1 * first->_s0 + second->_s0 * first->_x1) - (second->_x3 * first->_x2 - second->_x2 * first->_x3); const float x2 = (second->_x2 * first->_s0 + second->_s0 * first->_x2) - (second->_x1 * first->_x3 - second->_x3 * first->_x1); const float x3 = (second->_x3 * first->_s0 + second->_s0 * first->_x3) - (second->_x2 * first->_x1 - second->_x1 * first->_x2); bgc_fp32_versor_make( combination, (third->_s0 * s0 - third->_x1 * x1) - (third->_x2 * x2 + third->_x3 * x3), (third->_x1 * s0 + third->_s0 * x1) - (third->_x3 * x2 - third->_x2 * x3), (third->_x2 * s0 + third->_s0 * x2) - (third->_x1 * x3 - third->_x3 * x1), (third->_x3 * s0 + third->_s0 * x3) - (third->_x2 * x1 - third->_x1 * x2) ); } inline void bgc_fp64_versor_combine3(BGC_FP64_Versor* combination, const BGC_FP64_Versor* first, const BGC_FP64_Versor* second, const BGC_FP64_Versor* third) { const double s0 = (second->_s0 * first->_s0 - second->_x1 * first->_x1) - (second->_x2 * first->_x2 + second->_x3 * first->_x3); const double x1 = (second->_x1 * first->_s0 + second->_s0 * first->_x1) - (second->_x3 * first->_x2 - second->_x2 * first->_x3); const double x2 = (second->_x2 * first->_s0 + second->_s0 * first->_x2) - (second->_x1 * first->_x3 - second->_x3 * first->_x1); const double x3 = (second->_x3 * first->_s0 + second->_s0 * first->_x3) - (second->_x2 * first->_x1 - second->_x1 * first->_x2); bgc_fp64_versor_make( combination, (third->_s0 * s0 - third->_x1 * x1) - (third->_x2 * x2 + third->_x3 * x3), (third->_x1 * s0 + third->_s0 * x1) - (third->_x3 * x2 - third->_x2 * x3), (third->_x2 * s0 + third->_s0 * x2) - (third->_x1 * x3 - third->_x3 * x1), (third->_x3 * s0 + third->_s0 * x3) - (third->_x2 * x1 - third->_x1 * x2) ); } // ================= Exclusion ================== // inline void bgc_fp32_versor_exclude(BGC_FP32_Versor* difference, const BGC_FP32_Versor* base, const BGC_FP32_Versor* excludant) { bgc_fp32_versor_make( difference, (base->_s0 * excludant->_s0 + base->_x1 * excludant->_x1) + (base->_x2 * excludant->_x2 + base->_x3 * excludant->_x3), (base->_x1 * excludant->_s0 + base->_x3 * excludant->_x2) - (base->_s0 * excludant->_x1 + base->_x2 * excludant->_x3), (base->_x2 * excludant->_s0 + base->_x1 * excludant->_x3) - (base->_s0 * excludant->_x2 + base->_x3 * excludant->_x1), (base->_x3 * excludant->_s0 + base->_x2 * excludant->_x1) - (base->_s0 * excludant->_x3 + base->_x1 * excludant->_x2) ); } inline void bgc_fp64_versor_exclude(BGC_FP64_Versor* difference, const BGC_FP64_Versor* base, const BGC_FP64_Versor* excludant) { bgc_fp64_versor_make( difference, (base->_s0 * excludant->_s0 + base->_x1 * excludant->_x1) + (base->_x2 * excludant->_x2 + base->_x3 * excludant->_x3), (base->_x1 * excludant->_s0 + base->_x3 * excludant->_x2) - (base->_s0 * excludant->_x1 + base->_x2 * excludant->_x3), (base->_x2 * excludant->_s0 + base->_x1 * excludant->_x3) - (base->_s0 * excludant->_x2 + base->_x3 * excludant->_x1), (base->_x3 * excludant->_s0 + base->_x2 * excludant->_x1) - (base->_s0 * excludant->_x3 + base->_x1 * excludant->_x2) ); } // ============ Sphere Interpolation ============ // void bgc_fp32_versor_spherically_interpolate(BGC_FP32_Versor* interpolation, const BGC_FP32_Versor* start, const BGC_FP32_Versor* end, const float phase); void bgc_fp64_versor_spherically_interpolate(BGC_FP64_Versor* interpolation, const BGC_FP64_Versor* start, const BGC_FP64_Versor* end, const double phase); // ================ Get Rotation ================ // void bgc_fp32_versor_get_rotation(BGC_FP32_Rotation3* rotation, const BGC_FP32_Versor* versor); void bgc_fp64_versor_get_rotation(BGC_FP64_Rotation3* rotation, const BGC_FP64_Versor* versor); // ============ Get Rotation Matrix ============= // inline void bgc_fp32_versor_get_rotation_matrix(BGC_FP32_Matrix3x3* matrix, const BGC_FP32_Versor* 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 s0x1 = versor->_s0 * versor->_x1; const float s0x2 = versor->_s0 * versor->_x2; const float s0x3 = 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; matrix->r1c1 = (s0s0 + x1x1) - (x2x2 + x3x3); matrix->r2c2 = (s0s0 + x2x2) - (x1x1 + x3x3); matrix->r3c3 = (s0s0 + x3x3) - (x1x1 + x2x2); matrix->r1c2 = 2.0f * (x1x2 - s0x3); matrix->r2c3 = 2.0f * (x2x3 - s0x1); matrix->r3c1 = 2.0f * (x1x3 - s0x2); matrix->r2c1 = 2.0f * (x1x2 + s0x3); matrix->r3c2 = 2.0f * (x2x3 + s0x1); matrix->r1c3 = 2.0f * (x1x3 + s0x2); } inline void bgc_fp64_versor_get_rotation_matrix(BGC_FP64_Matrix3x3* matrix, const BGC_FP64_Versor* 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 s0x1 = versor->_s0 * versor->_x1; const double s0x2 = versor->_s0 * versor->_x2; const double s0x3 = 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; matrix->r1c1 = (s0s0 + x1x1) - (x2x2 + x3x3); matrix->r2c2 = (s0s0 + x2x2) - (x1x1 + x3x3); matrix->r3c3 = (s0s0 + x3x3) - (x1x1 + x2x2); matrix->r1c2 = 2.0 * (x1x2 - s0x3); matrix->r2c3 = 2.0 * (x2x3 - s0x1); matrix->r3c1 = 2.0 * (x1x3 - s0x2); matrix->r2c1 = 2.0 * (x1x2 + s0x3); matrix->r3c2 = 2.0 * (x2x3 + s0x1); matrix->r1c3 = 2.0 * (x1x3 + s0x2); } // ============= Get Reverse Matrix ============= // inline void bgc_fp32_versor_get_reverse_matrix(BGC_FP32_Matrix3x3* matrix, const BGC_FP32_Versor* 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 s0x1 = versor->_s0 * versor->_x1; const float s0x2 = versor->_s0 * versor->_x2; const float s0x3 = 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; matrix->r1c1 = (s0s0 + x1x1) - (x2x2 + x3x3); matrix->r2c2 = (s0s0 + x2x2) - (x1x1 + x3x3); matrix->r3c3 = (s0s0 + x3x3) - (x1x1 + x2x2); matrix->r1c2 = 2.0f * (x1x2 + s0x3); matrix->r2c3 = 2.0f * (x2x3 + s0x1); matrix->r3c1 = 2.0f * (x1x3 + s0x2); matrix->r2c1 = 2.0f * (x1x2 - s0x3); matrix->r3c2 = 2.0f * (x2x3 - s0x1); matrix->r1c3 = 2.0f * (x1x3 - s0x2); } inline void bgc_fp64_versor_get_reverse_matrix(BGC_FP64_Matrix3x3* matrix, const BGC_FP64_Versor* 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 s0x1 = versor->_s0 * versor->_x1; const double s0x2 = versor->_s0 * versor->_x2; const double s0x3 = 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; matrix->r1c1 = (s0s0 + x1x1) - (x2x2 + x3x3); matrix->r2c2 = (s0s0 + x2x2) - (x1x1 + x3x3); matrix->r3c3 = (s0s0 + x3x3) - (x1x1 + x2x2); matrix->r1c2 = 2.0 * (x1x2 + s0x3); matrix->r2c3 = 2.0 * (x2x3 + s0x1); matrix->r3c1 = 2.0 * (x1x3 + s0x2); matrix->r2c1 = 2.0 * (x1x2 - s0x3); matrix->r3c2 = 2.0 * (x2x3 - s0x1); matrix->r1c3 = 2.0 * (x1x3 - s0x2); } // ============= Get Both Matrixes ============== // inline void bgc_fp32_versor_get_both_matrices(BGC_FP32_Matrix3x3* rotation, BGC_FP32_Matrix3x3* reverse, const BGC_FP32_Versor* versor) { bgc_fp32_versor_get_reverse_matrix(reverse, versor); bgc_fp32_matrix3x3_get_transposed(rotation, reverse); } inline void bgc_fp64_versor_get_both_matrices(BGC_FP64_Matrix3x3* rotation, BGC_FP64_Matrix3x3* reverse, const BGC_FP64_Versor* versor) { bgc_fp64_versor_get_reverse_matrix(reverse, versor); bgc_fp64_matrix3x3_get_transposed(rotation, reverse); } // ================ Turn Vector ================= // inline void bgc_fp32_versor_turn_vector(BGC_FP32_Vector3* turned_vector, const BGC_FP32_Versor* versor, const BGC_FP32_Vector3* vector) { 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); const float x3 = (vector->x3 + tx3 * versor->_s0) + (versor->_x1 * tx2 - versor->_x2 * tx1); turned_vector->x1 = x1; turned_vector->x2 = x2; turned_vector->x3 = x3; } inline void bgc_fp64_versor_turn_vector(BGC_FP64_Vector3* turned_vector, const BGC_FP64_Versor* versor, const BGC_FP64_Vector3* vector) { 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); const double x3 = (vector->x3 + tx3 * versor->_s0) + (versor->_x1 * tx2 - versor->_x2 * tx1); turned_vector->x1 = x1; turned_vector->x2 = x2; turned_vector->x3 = x3; } // ============== Turn Vector Back ============== // inline void bgc_fp32_versor_turn_vector_back(BGC_FP32_Vector3* turned_vector, const BGC_FP32_Versor* versor, const BGC_FP32_Vector3* vector) { 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); const float x3 = (vector->x3 - tx3 * versor->_s0) + (versor->_x1 * tx2 - versor->_x2 * tx1); turned_vector->x1 = x1; turned_vector->x2 = x2; turned_vector->x3 = x3; } inline void bgc_fp64_versor_turn_vector_back(BGC_FP64_Vector3* turned_vector, const BGC_FP64_Versor* versor, const BGC_FP64_Vector3* vector) { 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); const double x3 = (vector->x3 - tx3 * versor->_s0) + (versor->_x1 * tx2 - versor->_x2 * tx1); turned_vector->x1 = x1; turned_vector->x2 = x2; turned_vector->x3 = x3; } // ================== Are Close ================= // inline int bgc_fp32_versor_are_close(const BGC_FP32_Versor* versor1, const BGC_FP32_Versor* versor2) { const float ds0 = versor1->_s0 - versor2->_s0; const float dx1 = versor1->_x1 - versor2->_x1; const float dx2 = versor1->_x2 - versor2->_x2; const float dx3 = versor1->_x3 - versor2->_x3; return (ds0 * ds0 + dx1 * dx1) + (dx2 * dx2 + dx3 * dx3) <= BGC_FP32_SQUARE_EPSILON; } inline int bgc_fp64_versor_are_close(const BGC_FP64_Versor* versor1, const BGC_FP64_Versor* versor2) { const double ds0 = versor1->_s0 - versor2->_s0; const double dx1 = versor1->_x1 - versor2->_x1; const double dx2 = versor1->_x2 - versor2->_x2; const double dx3 = versor1->_x3 - versor2->_x3; return (ds0 * ds0 + dx1 * dx1) + (dx2 * dx2 + dx3 * dx3) <= BGC_FP64_SQUARE_EPSILON; } #endif