Исправление функции, которая находит трёхмерных поворот между двумя парами векторов

This commit is contained in:
Andrey Pokidov 2026-02-06 20:33:37 +07:00
parent 57280ac3f3
commit 2ce4b64ca3
7 changed files with 705 additions and 467 deletions

View file

@ -13,6 +13,20 @@
#define BGC_ZERO_TURN 0
#define BGC_OPPOSITE -1
#define _BGC_ERROR_TURN3_FIRST_PAIR 3000
#define _BGC_ERROR_TURN3_SECOND_PAIR 3010
#define _BGC_ERROR_TURN3_EMPTY_MAIN 1
#define _BGC_ERROR_TURN3_EMPTY_BRANCH 2
#define _BGC_ERROR_TURN3_PAIR_PARALLEL 3
#define BGC_ERROR_TURN3_FIRST_PAIR_EMPTY_MAIN 3001
#define BGC_ERROR_TURN3_FIRST_PAIR_EMPTY_BRANCH 3002
#define BGC_ERROR_TURN3_FIRST_PAIR_PARALLEL 3003
#define BGC_ERROR_TURN3_SECOND_PAIR_EMPTY_MAIN 3011
#define BGC_ERROR_TURN3_SECOND_PAIR_EMPTY_BRANCH 3012
#define BGC_ERROR_TURN3_SECOND_PAIR_PARALLEL 3013
#define BGC_ERROR_PRIMARY_DIRECTION_UNKNOWN -3001
#define BGC_ERROR_PRIMARY_VECTOR_IS_ZERO -3002
@ -133,22 +147,22 @@ int bgc_fp32_turn3_find_direction_difference(BGC_FP32_Turn3* difference, const B
int bgc_fp64_turn3_find_direction_difference(BGC_FP64_Turn3* difference, const BGC_FP64_Vector3* start, const BGC_FP64_Vector3* end);
// =============== Set Directions =============== //
// ======= Find Direction Pair Difference ======= //
int bgc_fp32_turn3_make_basis_difference(
int bgc_fp32_turn3_find_pair_difference(
BGC_FP32_Turn3* turn,
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
const BGC_FP32_Vector3* first_pair_main,
const BGC_FP32_Vector3* first_pair_branch,
const BGC_FP32_Vector3* second_pair_main,
const BGC_FP32_Vector3* second_pair_branch
);
int bgc_fp64_turn3_make_basis_difference(
int bgc_fp64_turn3_find_pair_difference(
BGC_FP64_Turn3* turn,
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
const BGC_FP64_Vector3* first_pair_main,
const BGC_FP64_Vector3* first_pair_branch,
const BGC_FP64_Vector3* second_pair_main,
const BGC_FP64_Vector3* second_pair_branch
);
// ==================== Copy ==================== //
@ -301,7 +315,7 @@ void bgc_fp64_turn3_get_exponation(BGC_FP64_Turn3* power, const BGC_FP64_Turn3*
inline void bgc_fp32_turn3_combine(BGC_FP32_Turn3* combination, const BGC_FP32_Turn3* first, const BGC_FP32_Turn3* second)
{
bgc_fp32_quaternion_get_product(&combination->_versor, &second->_versor, &first->_versor);
bgc_fp32_quaternion_multiply_by_quaternion(&combination->_versor, &second->_versor, &first->_versor);
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(&combination->_versor);
@ -312,7 +326,7 @@ inline void bgc_fp32_turn3_combine(BGC_FP32_Turn3* combination, const BGC_FP32_T
inline void bgc_fp64_turn3_combine(BGC_FP64_Turn3* combination, const BGC_FP64_Turn3* first, const BGC_FP64_Turn3* second)
{
bgc_fp64_quaternion_get_product(&combination->_versor, &second->_versor, &first->_versor);
bgc_fp64_quaternion_multiply_by_quaternion(&combination->_versor, &second->_versor, &first->_versor);
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(&combination->_versor);
@ -327,9 +341,9 @@ inline void bgc_fp32_turn3_combine3(BGC_FP32_Turn3* combination, const BGC_FP32_
{
BGC_FP32_Quaternion product;
bgc_fp32_quaternion_get_product(&product, &second->_versor, &first->_versor);
bgc_fp32_quaternion_multiply_by_quaternion(&product, &second->_versor, &first->_versor);
bgc_fp32_quaternion_get_product(&combination->_versor, &third->_versor, &product);
bgc_fp32_quaternion_multiply_by_quaternion(&combination->_versor, &third->_versor, &product);
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(&combination->_versor);
@ -342,9 +356,9 @@ inline void bgc_fp64_turn3_combine3(BGC_FP64_Turn3* combination, const BGC_FP64_
{
BGC_FP64_Quaternion product;
bgc_fp64_quaternion_get_product(&product, &second->_versor, &first->_versor);
bgc_fp64_quaternion_multiply_by_quaternion(&product, &second->_versor, &first->_versor);
bgc_fp64_quaternion_get_product(&combination->_versor, &third->_versor, &product);
bgc_fp64_quaternion_multiply_by_quaternion(&combination->_versor, &third->_versor, &product);
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(&combination->_versor);
@ -357,7 +371,7 @@ inline void bgc_fp64_turn3_combine3(BGC_FP64_Turn3* combination, const BGC_FP64_
inline void bgc_fp32_turn3_exclude(BGC_FP32_Turn3* difference, const BGC_FP32_Turn3* base, const BGC_FP32_Turn3* excludant)
{
bgc_fp32_quaternion_get_product_by_conjugate(&difference->_versor, &base->_versor, &excludant->_versor);
bgc_fp32_quaternion_multiply_by_conjugate(&difference->_versor, &base->_versor, &excludant->_versor);
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(&difference->_versor);
@ -368,7 +382,7 @@ inline void bgc_fp32_turn3_exclude(BGC_FP32_Turn3* difference, const BGC_FP32_Tu
inline void bgc_fp64_turn3_exclude(BGC_FP64_Turn3* difference, const BGC_FP64_Turn3* base, const BGC_FP64_Turn3* excludant)
{
bgc_fp64_quaternion_get_product_by_conjugate(&difference->_versor, &base->_versor, &excludant->_versor);
bgc_fp64_quaternion_multiply_by_conjugate(&difference->_versor, &base->_versor, &excludant->_versor);
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(&difference->_versor);
@ -421,66 +435,26 @@ inline void bgc_fp64_turn3_get_both_matrices(BGC_FP64_Matrix3x3* rotation, BGC_F
// ================ Turn Vector ================= //
inline void bgc_fp32_turn3_vector(BGC_FP32_Vector3* turned_vector, const BGC_FP32_Turn3* versor, const BGC_FP32_Vector3* vector)
inline void bgc_fp32_turn3_vector(BGC_FP32_Vector3* turned_vector, const BGC_FP32_Turn3* turn, const BGC_FP32_Vector3* original_vector)
{
const float tx1 = 2.0f * (versor->_versor.x2 * vector->x3 - versor->_versor.x3 * vector->x2);
const float tx2 = 2.0f * (versor->_versor.x3 * vector->x1 - versor->_versor.x1 * vector->x3);
const float tx3 = 2.0f * (versor->_versor.x1 * vector->x2 - versor->_versor.x2 * vector->x1);
const float x1 = (vector->x1 + tx1 * versor->_versor.s0) + (versor->_versor.x2 * tx3 - versor->_versor.x3 * tx2);
const float x2 = (vector->x2 + tx2 * versor->_versor.s0) + (versor->_versor.x3 * tx1 - versor->_versor.x1 * tx3);
const float x3 = (vector->x3 + tx3 * versor->_versor.s0) + (versor->_versor.x1 * tx2 - versor->_versor.x2 * tx1);
turned_vector->x1 = x1;
turned_vector->x2 = x2;
turned_vector->x3 = x3;
_bgc_fp32_quaternion_turn_vector_roughly(turned_vector, &turn->_versor, original_vector);
}
inline void bgc_fp64_turn3_vector(BGC_FP64_Vector3* turned_vector, const BGC_FP64_Turn3* turn, const BGC_FP64_Vector3* vector)
inline void bgc_fp64_turn3_vector(BGC_FP64_Vector3* turned_vector, const BGC_FP64_Turn3* turn, const BGC_FP64_Vector3* original_vector)
{
const double tx1 = 2.0 * (turn->_versor.x2 * vector->x3 - turn->_versor.x3 * vector->x2);
const double tx2 = 2.0 * (turn->_versor.x3 * vector->x1 - turn->_versor.x1 * vector->x3);
const double tx3 = 2.0 * (turn->_versor.x1 * vector->x2 - turn->_versor.x2 * vector->x1);
const double x1 = (vector->x1 + tx1 * turn->_versor.s0) + (turn->_versor.x2 * tx3 - turn->_versor.x3 * tx2);
const double x2 = (vector->x2 + tx2 * turn->_versor.s0) + (turn->_versor.x3 * tx1 - turn->_versor.x1 * tx3);
const double x3 = (vector->x3 + tx3 * turn->_versor.s0) + (turn->_versor.x1 * tx2 - turn->_versor.x2 * tx1);
turned_vector->x1 = x1;
turned_vector->x2 = x2;
turned_vector->x3 = x3;
_bgc_fp64_quaternion_turn_vector_roughly(turned_vector, &turn->_versor, original_vector);
}
// ============== Turn Vector Back ============== //
inline void bgc_fp32_turn3_vector_back(BGC_FP32_Vector3* turned_vector, const BGC_FP32_Turn3* turn, const BGC_FP32_Vector3* vector)
inline void bgc_fp32_turn3_vector_back(BGC_FP32_Vector3* turned_vector, const BGC_FP32_Turn3* turn, const BGC_FP32_Vector3* original_vector)
{
const float tx1 = 2.0f * (turn->_versor.x2 * vector->x3 - turn->_versor.x3 * vector->x2);
const float tx2 = 2.0f * (turn->_versor.x3 * vector->x1 - turn->_versor.x1 * vector->x3);
const float tx3 = 2.0f * (turn->_versor.x1 * vector->x2 - turn->_versor.x2 * vector->x1);
const float x1 = (vector->x1 - tx1 * turn->_versor.s0) + (turn->_versor.x2 * tx3 - turn->_versor.x3 * tx2);
const float x2 = (vector->x2 - tx2 * turn->_versor.s0) + (turn->_versor.x3 * tx1 - turn->_versor.x1 * tx3);
const float x3 = (vector->x3 - tx3 * turn->_versor.s0) + (turn->_versor.x1 * tx2 - turn->_versor.x2 * tx1);
turned_vector->x1 = x1;
turned_vector->x2 = x2;
turned_vector->x3 = x3;
_bgc_fp32_quaternion_turn_vector_back_roughly(turned_vector, &turn->_versor, original_vector);
}
inline void bgc_fp64_turn3_vector_back(BGC_FP64_Vector3* turned_vector, const BGC_FP64_Turn3* turn, const BGC_FP64_Vector3* vector)
inline void bgc_fp64_turn3_vector_back(BGC_FP64_Vector3* turned_vector, const BGC_FP64_Turn3* turn, const BGC_FP64_Vector3* original_vector)
{
const double tx1 = 2.0 * (turn->_versor.x2 * vector->x3 - turn->_versor.x3 * vector->x2);
const double tx2 = 2.0 * (turn->_versor.x3 * vector->x1 - turn->_versor.x1 * vector->x3);
const double tx3 = 2.0 * (turn->_versor.x1 * vector->x2 - turn->_versor.x2 * vector->x1);
const double x1 = (vector->x1 - tx1 * turn->_versor.s0) + (turn->_versor.x2 * tx3 - turn->_versor.x3 * tx2);
const double x2 = (vector->x2 - tx2 * turn->_versor.s0) + (turn->_versor.x3 * tx1 - turn->_versor.x1 * tx3);
const double x3 = (vector->x3 - tx3 * turn->_versor.s0) + (turn->_versor.x1 * tx2 - turn->_versor.x2 * tx1);
turned_vector->x1 = x1;
turned_vector->x2 = x2;
turned_vector->x3 = x3;
_bgc_fp64_quaternion_turn_vector_back_roughly(turned_vector, &turn->_versor, original_vector);
}
// ================== Are Close ================= //