Переход на парадигму Destination first в порядке параметров функий

This commit is contained in:
Andrey Pokidov 2026-02-01 23:42:51 +07:00
parent f7e41645fe
commit 03627f4401
41 changed files with 1570 additions and 1978 deletions

View file

@ -10,14 +10,14 @@ const BGC_FP64_Versor BGC_FP64_IDLE_VERSOR = { 1.0, 0.0, 0.0, 0.0 };
extern inline void bgc_fp32_versor_reset(BGC_FP32_Versor* versor);
extern inline void bgc_fp64_versor_reset(BGC_FP64_Versor* versor);
extern inline void bgc_fp32_versor_make(const float s0, const float x1, const float x2, const float x3, BGC_FP32_Versor* versor);
extern inline void bgc_fp64_versor_make(const double s0, const double x1, const double x2, const double x3, BGC_FP64_Versor* versor);
extern inline void bgc_fp32_versor_make(BGC_FP32_Versor* versor, const float s0, const float x1, const float x2, const float x3);
extern inline void bgc_fp64_versor_make(BGC_FP64_Versor* versor, const double s0, const double x1, const double x2, const double x3);
extern inline void bgc_fp32_versor_make_for_rotation(const BGC_FP32_Rotation3* rotation, BGC_FP32_Versor* result);
extern inline void bgc_fp64_versor_make_for_rotation(const BGC_FP64_Rotation3* rotation, BGC_FP64_Versor* result);
extern inline void bgc_fp32_versor_make_for_rotation(BGC_FP32_Versor* versor, const BGC_FP32_Rotation3* rotation);
extern inline void bgc_fp64_versor_make_for_rotation(BGC_FP64_Versor* versor, const BGC_FP64_Rotation3* rotation);
extern inline void bgc_fp32_versor_copy(const BGC_FP32_Versor* source, BGC_FP32_Versor* destination);
extern inline void bgc_fp64_versor_copy(const BGC_FP64_Versor* source, BGC_FP64_Versor* destination);
extern inline void bgc_fp32_versor_copy(BGC_FP32_Versor* destination, const BGC_FP32_Versor* source);
extern inline void bgc_fp64_versor_copy(BGC_FP64_Versor* destination, const BGC_FP64_Versor* source);
extern inline void bgc_fp32_versor_swap(BGC_FP32_Versor* versor1, BGC_FP32_Versor* versor2);
extern inline void bgc_fp64_versor_swap(BGC_FP64_Versor* versor1, BGC_FP64_Versor* versor2);
@ -25,50 +25,50 @@ extern inline void bgc_fp64_versor_swap(BGC_FP64_Versor* versor1, BGC_FP64_Verso
extern inline int bgc_fp32_versor_is_idle(const BGC_FP32_Versor* versor);
extern inline int bgc_fp64_versor_is_idle(const BGC_FP64_Versor* versor);
extern inline void bgc_fp64_versor_convert_to_fp32(const BGC_FP64_Versor* source, BGC_FP32_Versor* destination);
extern inline void bgc_fp32_versor_convert_to_fp64(const BGC_FP32_Versor* source, BGC_FP64_Versor* destination);
extern inline void bgc_fp32_versor_convert_to_fp64(BGC_FP64_Versor* destination, const BGC_FP32_Versor* source);
extern inline void bgc_fp64_versor_convert_to_fp32(BGC_FP32_Versor* destination, const BGC_FP64_Versor* source);
extern inline void bgc_fp32_versor_shorten(BGC_FP32_Versor* versor);
extern inline void bgc_fp64_versor_shorten(BGC_FP64_Versor* versor);
extern inline void bgc_fp32_versor_get_shortened(const BGC_FP32_Versor* versor, BGC_FP32_Versor* shortened);
extern inline void bgc_fp64_versor_get_shortened(const BGC_FP64_Versor* versor, BGC_FP64_Versor* shortened);
extern inline void bgc_fp32_versor_get_shortened(BGC_FP32_Versor* shortened, const BGC_FP32_Versor* versor);
extern inline void bgc_fp64_versor_get_shortened(BGC_FP64_Versor* shortened, const BGC_FP64_Versor* versor);
extern inline void bgc_fp32_versor_alternate(BGC_FP32_Versor* versor);
extern inline void bgc_fp64_versor_alternate(BGC_FP64_Versor* versor);
extern inline void bgc_fp32_versor_get_alternative(const BGC_FP32_Versor* versor, BGC_FP32_Versor* opposite);
extern inline void bgc_fp64_versor_get_alternative(const BGC_FP64_Versor* versor, BGC_FP64_Versor* opposite);
extern inline void bgc_fp32_versor_get_alternative(BGC_FP32_Versor* alternative, const BGC_FP32_Versor* versor);
extern inline void bgc_fp64_versor_get_alternative(BGC_FP64_Versor* alternative, const BGC_FP64_Versor* versor);
extern inline void bgc_fp32_versor_revert(BGC_FP32_Versor* versor);
extern inline void bgc_fp64_versor_revert(BGC_FP64_Versor* versor);
extern inline void bgc_fp32_versor_get_reverse(const BGC_FP32_Versor* versor, BGC_FP32_Versor* inverse);
extern inline void bgc_fp64_versor_get_reverse(const BGC_FP64_Versor* versor, BGC_FP64_Versor* inverse);
extern inline void bgc_fp32_versor_get_reverse(BGC_FP32_Versor* inverse, const BGC_FP32_Versor* versor);
extern inline void bgc_fp64_versor_get_reverse(BGC_FP64_Versor* inverse, const BGC_FP64_Versor* versor);
extern inline void bgc_fp32_versor_combine(const BGC_FP32_Versor* first, const BGC_FP32_Versor* second, BGC_FP32_Versor* result);
extern inline void bgc_fp64_versor_combine(const BGC_FP64_Versor* first, const BGC_FP64_Versor* second, BGC_FP64_Versor* result);
extern inline void bgc_fp32_versor_combine(BGC_FP32_Versor* combination, const BGC_FP32_Versor* first, const BGC_FP32_Versor* second);
extern inline void bgc_fp64_versor_combine(BGC_FP64_Versor* combination, const BGC_FP64_Versor* first, const BGC_FP64_Versor* second);
extern inline void bgc_fp32_versor_combine3(const BGC_FP32_Versor* first, const BGC_FP32_Versor* second, const BGC_FP32_Versor* third, BGC_FP32_Versor* result);
extern inline void bgc_fp64_versor_combine3(const BGC_FP64_Versor* first, const BGC_FP64_Versor* second, const BGC_FP64_Versor* third, BGC_FP64_Versor* result);
extern 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);
extern 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);
extern inline void bgc_fp32_versor_exclude(const BGC_FP32_Versor* base, const BGC_FP32_Versor* excludant, BGC_FP32_Versor* difference);
extern inline void bgc_fp64_versor_exclude(const BGC_FP64_Versor* base, const BGC_FP64_Versor* excludant, BGC_FP64_Versor* difference);
extern inline void bgc_fp32_versor_exclude(BGC_FP32_Versor* difference, const BGC_FP32_Versor* base, const BGC_FP32_Versor* excludant);
extern inline void bgc_fp64_versor_exclude(BGC_FP64_Versor* difference, const BGC_FP64_Versor* base, const BGC_FP64_Versor* excludant);
extern inline void bgc_fp32_versor_get_rotation_matrix(const BGC_FP32_Versor* versor, BGC_FP32_Matrix3x3* matrix);
extern inline void bgc_fp64_versor_get_rotation_matrix(const BGC_FP64_Versor* versor, BGC_FP64_Matrix3x3* matrix);
extern inline void bgc_fp32_versor_get_rotation_matrix(BGC_FP32_Matrix3x3* matrix, const BGC_FP32_Versor* versor);
extern inline void bgc_fp64_versor_get_rotation_matrix(BGC_FP64_Matrix3x3* matrix, const BGC_FP64_Versor* versor);
extern inline void bgc_fp32_versor_get_reverse_matrix(const BGC_FP32_Versor* versor, BGC_FP32_Matrix3x3* matrix);
extern inline void bgc_fp64_versor_get_reverse_matrix(const BGC_FP64_Versor* versor, BGC_FP64_Matrix3x3* matrix);
extern inline void bgc_fp32_versor_get_reverse_matrix(BGC_FP32_Matrix3x3* matrix, const BGC_FP32_Versor* versor);
extern inline void bgc_fp64_versor_get_reverse_matrix(BGC_FP64_Matrix3x3* matrix, const BGC_FP64_Versor* versor);
extern inline void bgc_fp32_versor_get_both_matrices(const BGC_FP32_Versor* versor, BGC_FP32_Matrix3x3* rotation, BGC_FP32_Matrix3x3* reverse);
extern inline void bgc_fp64_versor_get_both_matrices(const BGC_FP64_Versor* versor, BGC_FP64_Matrix3x3* rotation, BGC_FP64_Matrix3x3* reverse);
extern inline void bgc_fp32_versor_get_both_matrices(BGC_FP32_Matrix3x3* rotation, BGC_FP32_Matrix3x3* reverse, const BGC_FP32_Versor* versor);
extern inline void bgc_fp64_versor_get_both_matrices(BGC_FP64_Matrix3x3* rotation, BGC_FP64_Matrix3x3* reverse, const BGC_FP64_Versor* versor);
extern inline void bgc_fp32_versor_turn_vector(const BGC_FP32_Versor* versor, const BGC_FP32_Vector3* vector, BGC_FP32_Vector3* result);
extern inline void bgc_fp64_versor_turn_vector(const BGC_FP64_Versor* versor, const BGC_FP64_Vector3* vector, BGC_FP64_Vector3* result);
extern inline void bgc_fp32_versor_turn_vector(BGC_FP32_Vector3* turned_vector, const BGC_FP32_Versor* versor, const BGC_FP32_Vector3* vector);
extern inline void bgc_fp64_versor_turn_vector(BGC_FP64_Vector3* turned_vector, const BGC_FP64_Versor* versor, const BGC_FP64_Vector3* vector);
extern inline void bgc_fp32_versor_turn_vector_back(const BGC_FP32_Versor* versor, const BGC_FP32_Vector3* vector, BGC_FP32_Vector3* result);
extern inline void bgc_fp64_versor_turn_vector_back(const BGC_FP64_Versor* versor, const BGC_FP64_Vector3* vector, BGC_FP64_Vector3* result);
extern inline void bgc_fp32_versor_turn_vector_back(BGC_FP32_Vector3* turned_vector, const BGC_FP32_Versor* versor, const BGC_FP32_Vector3* vector);
extern inline void bgc_fp64_versor_turn_vector_back(BGC_FP64_Vector3* turned_vector, const BGC_FP64_Versor* versor, const BGC_FP64_Vector3* vector);
extern inline int bgc_fp32_versor_are_close(const BGC_FP32_Versor* versor1, const BGC_FP32_Versor* versor2);
extern inline int bgc_fp64_versor_are_close(const BGC_FP64_Versor* versor1, const BGC_FP64_Versor* versor2);
@ -117,12 +117,12 @@ void _bgc_fp64_versor_normalize(BGC_FP64_Versor* versor)
// ================== Set Turn ================== //
void bgc_fp32_versor_make_for_turn(const float x1, const float x2, const float x3, const float angle, const int unit, BGC_FP32_Versor* result)
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)
{
const float square_vector = x1 * x1 + x2 * x2 + x3 * x3;
if (square_vector <= BGC_FP32_SQUARE_EPSYLON) {
bgc_fp32_versor_reset(result);
bgc_fp32_versor_reset(versor);
return;
}
@ -131,21 +131,21 @@ void bgc_fp32_versor_make_for_turn(const float x1, const float x2, const float x
const float sine = sinf(half_angle);
if (bgc_fp32_is_zero(sine)) {
bgc_fp32_versor_reset(result);
bgc_fp32_versor_reset(versor);
return;
}
const float multiplier = sine / sqrtf(square_vector);
bgc_fp32_versor_make(cosf(half_angle), x1 * multiplier, x2 * multiplier, x3 * multiplier, result);
bgc_fp32_versor_make(versor, cosf(half_angle), x1 * multiplier, x2 * multiplier, x3 * multiplier);
}
void bgc_fp64_versor_make_for_turn(const double x1, const double x2, const double x3, const double angle, const int unit, BGC_FP64_Versor* result)
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)
{
const double square_vector = x1 * x1 + x2 * x2 + x3 * x3;
if (square_vector <= BGC_FP64_SQUARE_EPSYLON) {
bgc_fp64_versor_reset(result);
bgc_fp64_versor_reset(versor);
return;
}
@ -154,22 +154,22 @@ void bgc_fp64_versor_make_for_turn(const double x1, const double x2, const doubl
const double sine = sin(half_angle);
if (bgc_fp64_is_zero(sine)) {
bgc_fp64_versor_reset(result);
bgc_fp64_versor_reset(versor);
return;
}
const double multiplier = sine / sqrt(square_vector);
bgc_fp64_versor_make(cos(half_angle), x1 * multiplier, x2 * multiplier, x3 * multiplier, result);
bgc_fp64_versor_make(versor, cos(half_angle), x1 * multiplier, x2 * multiplier, x3 * multiplier);
}
// ========= Make Direction Difference ========== //
static int _bgc_fp32_versor_make_direction_turn(const BGC_FP32_Vector3* start, const BGC_FP32_Vector3* end, const float square_modulus_product, BGC_FP32_Versor* result)
static int _bgc_fp32_versor_make_direction_turn(BGC_FP32_Versor* versor, const BGC_FP32_Vector3* start, const BGC_FP32_Vector3* end, const float square_modulus_product)
{
BGC_FP32_Vector3 orthogonal_axis;
bgc_fp32_vector3_get_cross_product(start, end, &orthogonal_axis);
bgc_fp32_vector3_get_cross_product(&orthogonal_axis, start, end);
const float scalar_product = bgc_fp32_vector3_get_dot_product(start, end);
const float square_modulus = bgc_fp32_vector3_get_square_modulus(&orthogonal_axis);
@ -181,7 +181,7 @@ static int _bgc_fp32_versor_make_direction_turn(const BGC_FP32_Vector3* start, c
const float multiplier = sinf(angle) * sqrtf(1.0f / square_modulus);
bgc_fp32_versor_make(cosf(angle), orthogonal_axis.x1 * multiplier, orthogonal_axis.x2 * multiplier, orthogonal_axis.x3 * multiplier, result);
bgc_fp32_versor_make(versor, cosf(angle), orthogonal_axis.x1 * multiplier, orthogonal_axis.x2 * multiplier, orthogonal_axis.x3 * multiplier);
return BGC_SOME_TURN;
}
@ -189,15 +189,15 @@ static int _bgc_fp32_versor_make_direction_turn(const BGC_FP32_Vector3* start, c
return BGC_OPPOSITE;
}
bgc_fp32_versor_reset(result);
bgc_fp32_versor_reset(versor);
return BGC_ZERO_TURN;
}
static int _bgc_fp64_versor_make_direction_turn(const BGC_FP64_Vector3* start, const BGC_FP64_Vector3* end, const double square_modulus_product, BGC_FP64_Versor* result)
static int _bgc_fp64_versor_make_direction_turn(BGC_FP64_Versor* versor, const BGC_FP64_Vector3* start, const BGC_FP64_Vector3* end, const double square_modulus_product)
{
BGC_FP64_Vector3 orthogonal_axis;
bgc_fp64_vector3_get_cross_product(start, end, &orthogonal_axis);
bgc_fp64_vector3_get_cross_product(&orthogonal_axis, start, end);
const double scalar_product = bgc_fp64_vector3_get_dot_product(start, end);
const double square_modulus = bgc_fp64_vector3_get_square_modulus(&orthogonal_axis);
@ -209,7 +209,7 @@ static int _bgc_fp64_versor_make_direction_turn(const BGC_FP64_Vector3* start, c
const double multiplier = sin(angle) * sqrt(1.0f / square_modulus);
bgc_fp64_versor_make(cos(angle), orthogonal_axis.x1 * multiplier, orthogonal_axis.x2 * multiplier, orthogonal_axis.x3 * multiplier, result);
bgc_fp64_versor_make(versor, cos(angle), orthogonal_axis.x1 * multiplier, orthogonal_axis.x2 * multiplier, orthogonal_axis.x3 * multiplier);
return BGC_SOME_TURN;
}
@ -217,34 +217,34 @@ static int _bgc_fp64_versor_make_direction_turn(const BGC_FP64_Vector3* start, c
return BGC_OPPOSITE;
}
bgc_fp64_versor_reset(result);
bgc_fp64_versor_reset(versor);
return BGC_ZERO_TURN;
}
int bgc_fp32_versor_make_direction_difference(const BGC_FP32_Vector3* start, const BGC_FP32_Vector3* end, BGC_FP32_Versor* result)
int bgc_fp32_versor_make_direction_difference(BGC_FP32_Versor* versor, const BGC_FP32_Vector3* start, const BGC_FP32_Vector3* end)
{
const float start_square_modulus = bgc_fp32_vector3_get_square_modulus(start);
const float end_square_modulus = bgc_fp32_vector3_get_square_modulus(end);
if (start_square_modulus <= BGC_FP32_SQUARE_EPSYLON || end_square_modulus <= BGC_FP32_SQUARE_EPSYLON) {
bgc_fp32_versor_reset(result);
bgc_fp32_versor_reset(versor);
return BGC_ZERO_TURN;
}
return _bgc_fp32_versor_make_direction_turn(start, end, start_square_modulus * end_square_modulus, result);
return _bgc_fp32_versor_make_direction_turn(versor, start, end, start_square_modulus * end_square_modulus);
}
int bgc_fp64_versor_make_direction_difference(const BGC_FP64_Vector3* start, const BGC_FP64_Vector3* end, BGC_FP64_Versor* result)
int bgc_fp64_versor_make_direction_difference(BGC_FP64_Versor* versor, const BGC_FP64_Vector3* start, const BGC_FP64_Vector3* end)
{
const double start_square_modulus = bgc_fp64_vector3_get_square_modulus(start);
const double end_square_modulus = bgc_fp64_vector3_get_square_modulus(end);
if (start_square_modulus <= BGC_FP64_SQUARE_EPSYLON || end_square_modulus <= BGC_FP64_SQUARE_EPSYLON) {
bgc_fp64_versor_reset(result);
bgc_fp64_versor_reset(versor);
return BGC_ZERO_TURN;
}
return _bgc_fp64_versor_make_direction_turn(start, end, start_square_modulus * end_square_modulus, result);
return _bgc_fp64_versor_make_direction_turn(versor, start, end, start_square_modulus * end_square_modulus);
}
// =============== Set Directions =============== //
@ -290,17 +290,17 @@ static int _bgc_fp64_versor_validate_basis(const double primary_square_modulus,
}
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,
BGC_FP32_Versor* result
const BGC_FP32_Vector3* final_auxiliary_direction
)
{
BGC_FP32_Vector3 initial_orthogonal_direction, turned_orthogonal_direction, final_orthogonal_direction;
// Step 1: Validate initial basis:
bgc_fp32_vector3_get_cross_product(initial_primary_direction, initial_auxiliary_direction, &initial_orthogonal_direction);
bgc_fp32_vector3_get_cross_product(&initial_orthogonal_direction, initial_primary_direction, initial_auxiliary_direction);
const float initial_primary_square_modulus = bgc_fp32_vector3_get_square_modulus(initial_primary_direction);
const float initial_auxiliary_square_modulus = bgc_fp32_vector3_get_square_modulus(initial_auxiliary_direction);
@ -313,7 +313,7 @@ int bgc_fp32_versor_make_basis_difference(
}
// Step 1: Validate final basis:
bgc_fp32_vector3_get_cross_product(final_primary_direction, final_auxiliary_direction, &final_orthogonal_direction);
bgc_fp32_vector3_get_cross_product(&final_orthogonal_direction, final_primary_direction, final_auxiliary_direction);
const float final_primary_square_modulus = bgc_fp32_vector3_get_square_modulus(final_primary_direction);
const float final_auxiliary_square_modulus = bgc_fp32_vector3_get_square_modulus(final_auxiliary_direction);
@ -326,52 +326,52 @@ int bgc_fp32_versor_make_basis_difference(
}
// Step 3: Validate normalize orthogonal vectors:
bgc_fp32_vector3_divide(&initial_orthogonal_direction, sqrtf(initial_orthogonal_square_modulus), &initial_orthogonal_direction);
bgc_fp32_vector3_divide(&final_orthogonal_direction, sqrtf(final_orthogonal_square_modulus), &final_orthogonal_direction);
bgc_fp32_vector3_divide(&initial_orthogonal_direction, &initial_orthogonal_direction, sqrtf(initial_orthogonal_square_modulus));
bgc_fp32_vector3_divide(&final_orthogonal_direction, &final_orthogonal_direction, sqrtf(final_orthogonal_square_modulus));
BGC_FP32_Versor turn1, turn2;
// Step 4: Find turn1
int turn1_code = _bgc_fp32_versor_make_direction_turn(initial_primary_direction, final_primary_direction, initial_primary_square_modulus * final_primary_square_modulus, &turn1);
int turn1_code = _bgc_fp32_versor_make_direction_turn(&turn1, initial_primary_direction, final_primary_direction, initial_primary_square_modulus * final_primary_square_modulus);
if (turn1_code == BGC_OPPOSITE) {
bgc_fp32_versor_make(0.0f, initial_orthogonal_direction.x1, initial_orthogonal_direction.x2, initial_orthogonal_direction.x3, &turn1);
bgc_fp32_versor_make(&turn1, 0.0f, initial_orthogonal_direction.x1, initial_orthogonal_direction.x2, initial_orthogonal_direction.x3);
}
bgc_fp32_versor_turn_vector(&turn1, &initial_orthogonal_direction, &turned_orthogonal_direction);
bgc_fp32_versor_turn_vector(&turned_orthogonal_direction, &turn1, &initial_orthogonal_direction);
// Step 5: Find turn2:
int turn2_code = _bgc_fp32_versor_make_direction_turn(&turned_orthogonal_direction, &final_orthogonal_direction, 1.0f, &turn2);
int turn2_code = _bgc_fp32_versor_make_direction_turn(&turn2, &turned_orthogonal_direction, &final_orthogonal_direction, 1.0f);
if (turn2_code == BGC_OPPOSITE) {
const float turn2_multiplier = sqrtf(1.0f / final_primary_square_modulus);
bgc_fp32_versor_make(0.0f,
bgc_fp32_versor_make(&turn2,
0.0f,
final_primary_direction->x1 * turn2_multiplier,
final_primary_direction->x2 * turn2_multiplier,
final_primary_direction->x3 * turn2_multiplier,
&turn2
final_primary_direction->x3 * turn2_multiplier
);
}
// Step 6: Combine turn1 and turn2:
bgc_fp32_versor_combine(&turn1, &turn2, result);
bgc_fp32_versor_combine(versor, &turn1, &turn2);
return BGC_SUCCESS;
}
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,
BGC_FP64_Versor* result
const BGC_FP64_Vector3* final_auxiliary_direction
)
{
BGC_FP64_Vector3 initial_orthogonal_direction, turned_orthogonal_direction, final_orthogonal_direction;
// Step 1: Validate initial basis:
bgc_fp64_vector3_get_cross_product(initial_primary_direction, initial_auxiliary_direction, &initial_orthogonal_direction);
bgc_fp64_vector3_get_cross_product(&initial_orthogonal_direction, initial_primary_direction, initial_auxiliary_direction);
const double initial_primary_square_modulus = bgc_fp64_vector3_get_square_modulus(initial_primary_direction);
const double initial_auxiliary_square_modulus = bgc_fp64_vector3_get_square_modulus(initial_auxiliary_direction);
@ -384,7 +384,7 @@ int bgc_fp64_versor_make_basis_difference(
}
// Step 1: Validate final basis:
bgc_fp64_vector3_get_cross_product(final_primary_direction, final_auxiliary_direction, &final_orthogonal_direction);
bgc_fp64_vector3_get_cross_product(&final_orthogonal_direction, final_primary_direction, final_auxiliary_direction);
const double final_primary_square_modulus = bgc_fp64_vector3_get_square_modulus(final_primary_direction);
const double final_auxiliary_square_modulus = bgc_fp64_vector3_get_square_modulus(final_auxiliary_direction);
@ -397,43 +397,43 @@ int bgc_fp64_versor_make_basis_difference(
}
// Step 3: Validate normalize orthogonal vectors:
bgc_fp64_vector3_divide(&initial_orthogonal_direction, sqrt(initial_orthogonal_square_modulus), &initial_orthogonal_direction);
bgc_fp64_vector3_divide(&final_orthogonal_direction, sqrt(final_orthogonal_square_modulus), &final_orthogonal_direction);
bgc_fp64_vector3_divide(&initial_orthogonal_direction, &initial_orthogonal_direction, sqrt(initial_orthogonal_square_modulus));
bgc_fp64_vector3_divide(&final_orthogonal_direction, &final_orthogonal_direction, sqrt(final_orthogonal_square_modulus));
BGC_FP64_Versor turn1, turn2;
// Step 4: Find turn1
int turn1_code = _bgc_fp64_versor_make_direction_turn(initial_primary_direction, final_primary_direction, initial_primary_square_modulus * final_primary_square_modulus, &turn1);
int turn1_code = _bgc_fp64_versor_make_direction_turn(&turn1, initial_primary_direction, final_primary_direction, initial_primary_square_modulus * final_primary_square_modulus);
if (turn1_code == BGC_OPPOSITE) {
bgc_fp64_versor_make(0.0, initial_orthogonal_direction.x1, initial_orthogonal_direction.x2, initial_orthogonal_direction.x3, &turn1);
bgc_fp64_versor_make(&turn1, 0.0, initial_orthogonal_direction.x1, initial_orthogonal_direction.x2, initial_orthogonal_direction.x3);
}
bgc_fp64_versor_turn_vector(&turn1, &initial_orthogonal_direction, &turned_orthogonal_direction);
bgc_fp64_versor_turn_vector(&turned_orthogonal_direction, &turn1, &initial_orthogonal_direction);
// Step 5: Find turn2:
int turn2_code = _bgc_fp64_versor_make_direction_turn(&turned_orthogonal_direction, &final_orthogonal_direction, 1.0f, &turn2);
int turn2_code = _bgc_fp64_versor_make_direction_turn(&turn2, &turned_orthogonal_direction, &final_orthogonal_direction, 1.0f);
if (turn2_code == BGC_OPPOSITE) {
const double turn2_multiplier = sqrt(1.0 / final_primary_square_modulus);
bgc_fp64_versor_make(0.0,
bgc_fp64_versor_make(&turn2,
0.0,
final_primary_direction->x1 * turn2_multiplier,
final_primary_direction->x2 * turn2_multiplier,
final_primary_direction->x3 * turn2_multiplier,
&turn2
final_primary_direction->x3 * turn2_multiplier
);
}
// Step 6: Combine turn1 and turn2:
bgc_fp64_versor_combine(&turn1, &turn2, result);
bgc_fp64_versor_combine(versor, &turn1, &turn2);
return BGC_SUCCESS;
}
// =============== Get Exponation =============== //
void bgc_fp32_versor_get_exponation(const BGC_FP32_Versor* base, const float exponent, BGC_FP32_Versor* power)
void bgc_fp32_versor_get_exponation(BGC_FP32_Versor* power, const BGC_FP32_Versor* base, const float exponent)
{
const float square_vector = base->_x1 * base->_x1 + base->_x2 * base->_x2 + base->_x3 * base->_x3;
@ -448,10 +448,10 @@ void bgc_fp32_versor_get_exponation(const BGC_FP32_Versor* base, const float exp
const float multiplier = sinf(angle) / vector_modulus;
bgc_fp32_versor_make(cosf(angle), base->_x1 * multiplier, base->_x2 * multiplier, base->_x3 * multiplier, power);
bgc_fp32_versor_make(power, cosf(angle), base->_x1 * multiplier, base->_x2 * multiplier, base->_x3 * multiplier);
}
void bgc_fp64_versor_get_exponation(const BGC_FP64_Versor* base, const double exponent, BGC_FP64_Versor* power)
void bgc_fp64_versor_get_exponation(BGC_FP64_Versor* power, const BGC_FP64_Versor* base, const double exponent)
{
const double square_vector = base->_x1 * base->_x1 + base->_x2 * base->_x2 + base->_x3 * base->_x3;
@ -466,12 +466,12 @@ void bgc_fp64_versor_get_exponation(const BGC_FP64_Versor* base, const double ex
const double multiplier = sin(angle) / vector_modulus;
bgc_fp64_versor_make(cos(angle), base->_x1 * multiplier, base->_x2 * multiplier, base->_x3 * multiplier, power);
bgc_fp64_versor_make(power, cos(angle), base->_x1 * multiplier, base->_x2 * multiplier, base->_x3 * multiplier);
}
// ============ Sphere Interpolation ============ //
void bgc_fp32_versor_spherically_interpolate(const BGC_FP32_Versor* start, const BGC_FP32_Versor* end, const float phase, BGC_FP32_Versor* result)
void bgc_fp32_versor_spherically_interpolate(BGC_FP32_Versor* interpolation, const BGC_FP32_Versor* start, const BGC_FP32_Versor* end, const float phase)
{
const float delta_s0 = (end->_s0 * start->_s0 + end->_x1 * start->_x1) + (end->_x2 * start->_x2 + end->_x3 * start->_x3);
const float delta_x1 = (end->_x1 * start->_s0 + end->_x3 * start->_x2) - (end->_s0 * start->_x1 + end->_x2 * start->_x3);
@ -481,8 +481,8 @@ void bgc_fp32_versor_spherically_interpolate(const BGC_FP32_Versor* start, const
const float square_vector = delta_x1 * delta_x1 + delta_x2 * delta_x2 + delta_x3 * delta_x3;
// square_vector != square_vector means checking for NaN value at square_vector
if (square_vector <= BGC_FP32_SQUARE_EPSYLON || square_vector != square_vector) {
bgc_fp32_versor_copy(end, result);
if (square_vector <= BGC_FP32_SQUARE_EPSYLON || isnan(square_vector)) {
bgc_fp32_versor_copy(interpolation, end);
return;
}
@ -498,15 +498,15 @@ void bgc_fp32_versor_spherically_interpolate(const BGC_FP32_Versor* start, const
// Combining of starting orientation with the turning
bgc_fp32_versor_make(
interpolation,
(turn_s0 * start->_s0 - turn_x1 * start->_x1) - (turn_x2 * start->_x2 + turn_x3 * start->_x3),
(turn_x1 * start->_s0 + turn_s0 * start->_x1) - (turn_x3 * start->_x2 - turn_x2 * start->_x3),
(turn_x2 * start->_s0 + turn_s0 * start->_x2) - (turn_x1 * start->_x3 - turn_x3 * start->_x1),
(turn_x3 * start->_s0 + turn_s0 * start->_x3) - (turn_x2 * start->_x1 - turn_x1 * start->_x2),
result
(turn_x3 * start->_s0 + turn_s0 * start->_x3) - (turn_x2 * start->_x1 - turn_x1 * start->_x2)
);
}
void bgc_fp64_versor_spherically_interpolate(const BGC_FP64_Versor* start, const BGC_FP64_Versor* end, const double phase, BGC_FP64_Versor* result)
void bgc_fp64_versor_spherically_interpolate(BGC_FP64_Versor* interpolation, const BGC_FP64_Versor* start, const BGC_FP64_Versor* end, const double phase)
{
const double delta_s0 = (end->_s0 * start->_s0 + end->_x1 * start->_x1) + (end->_x2 * start->_x2 + end->_x3 * start->_x3);
const double delta_x1 = (end->_x1 * start->_s0 + end->_x3 * start->_x2) - (end->_s0 * start->_x1 + end->_x2 * start->_x3);
@ -516,8 +516,8 @@ void bgc_fp64_versor_spherically_interpolate(const BGC_FP64_Versor* start, const
const double square_vector = delta_x1 * delta_x1 + delta_x2 * delta_x2 + delta_x3 * delta_x3;
// square_vector != square_vector means checking for NaN value at square_vector
if (square_vector <= BGC_FP64_SQUARE_EPSYLON || square_vector != square_vector) {
bgc_fp64_versor_copy(end, result);
if (square_vector <= BGC_FP64_SQUARE_EPSYLON || isnan(square_vector)) {
bgc_fp64_versor_copy(interpolation, end);
return;
}
@ -533,22 +533,22 @@ void bgc_fp64_versor_spherically_interpolate(const BGC_FP64_Versor* start, const
// Combining of starting orientation with the turning
bgc_fp64_versor_make(
interpolation,
(turn_s0 * start->_s0 - turn_x1 * start->_x1) - (turn_x2 * start->_x2 + turn_x3 * start->_x3),
(turn_x1 * start->_s0 + turn_s0 * start->_x1) - (turn_x3 * start->_x2 - turn_x2 * start->_x3),
(turn_x2 * start->_s0 + turn_s0 * start->_x2) - (turn_x1 * start->_x3 - turn_x3 * start->_x1),
(turn_x3 * start->_s0 + turn_s0 * start->_x3) - (turn_x2 * start->_x1 - turn_x1 * start->_x2),
result
(turn_x3 * start->_s0 + turn_s0 * start->_x3) - (turn_x2 * start->_x1 - turn_x1 * start->_x2)
);
}
// ================ Get Rotation ================ //
void bgc_fp32_versor_get_rotation(const BGC_FP32_Versor* versor, BGC_FP32_Rotation3* result)
void bgc_fp32_versor_get_rotation(BGC_FP32_Rotation3* rotation, const BGC_FP32_Versor* versor)
{
const float square_modulus = versor->_x1 * versor->_x1 + versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3;
if (square_modulus <= BGC_FP32_SQUARE_EPSYLON) {
bgc_fp32_rotation3_reset(result);
bgc_fp32_rotation3_reset(rotation);
return;
}
@ -556,19 +556,19 @@ void bgc_fp32_versor_get_rotation(const BGC_FP32_Versor* versor, BGC_FP32_Rotati
const float multiplier = 1.0f / vector_modulus;
result->radians = 2.0f * atan2f(vector_modulus, versor->_s0);
rotation->radians = 2.0f * atan2f(vector_modulus, versor->_s0);
result->axis.x1 = versor->_x1 * multiplier;
result->axis.x2 = versor->_x2 * multiplier;
result->axis.x3 = versor->_x3 * multiplier;
rotation->axis.x1 = versor->_x1 * multiplier;
rotation->axis.x2 = versor->_x2 * multiplier;
rotation->axis.x3 = versor->_x3 * multiplier;
}
void bgc_fp64_versor_get_rotation(const BGC_FP64_Versor* versor, BGC_FP64_Rotation3* result)
void bgc_fp64_versor_get_rotation(BGC_FP64_Rotation3* rotation, const BGC_FP64_Versor* versor)
{
const double square_modulus = versor->_x1 * versor->_x1 + versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3;
if (square_modulus <= BGC_FP64_SQUARE_EPSYLON) {
bgc_fp64_rotation3_reset(result);
bgc_fp64_rotation3_reset(rotation);
return;
}
@ -576,9 +576,9 @@ void bgc_fp64_versor_get_rotation(const BGC_FP64_Versor* versor, BGC_FP64_Rotati
const double multiplier = 1.0 / vector_modulus;
result->radians = 2.0 * atan2(vector_modulus, versor->_s0);
rotation->radians = 2.0 * atan2(vector_modulus, versor->_s0);
result->axis.x1 = versor->_x1 * multiplier;
result->axis.x2 = versor->_x2 * multiplier;
result->axis.x3 = versor->_x3 * multiplier;
rotation->axis.x1 = versor->_x1 * multiplier;
rotation->axis.x2 = versor->_x2 * multiplier;
rotation->axis.x3 = versor->_x3 * multiplier;
}