Упорядочивание проекта
This commit is contained in:
parent
0dcd9c0d4d
commit
89dfd7644b
32 changed files with 1730 additions and 1719 deletions
|
|
@ -28,11 +28,23 @@ extern inline int bgc_versor_is_identity_fp64(const BgcVersorFP64* versor);
|
|||
extern inline void bgc_versor_convert_fp64_to_fp32(const BgcVersorFP64* source, BgcVersorFP32* destination);
|
||||
extern inline void bgc_versor_convert_fp32_to_fp64(const BgcVersorFP32* source, BgcVersorFP64* destination);
|
||||
|
||||
extern inline void bgc_versor_shorten_fp32(const BgcVersorFP32* versor, BgcVersorFP32* shortened);
|
||||
extern inline void bgc_versor_shorten_fp64(const BgcVersorFP64* versor, BgcVersorFP64* shortened);
|
||||
extern inline void bgc_versor_shorten_fp32(BgcVersorFP32* versor);
|
||||
extern inline void bgc_versor_shorten_fp64(BgcVersorFP64* versor);
|
||||
|
||||
extern inline void bgc_versor_invert_fp32(const BgcVersorFP32* versor, BgcVersorFP32* inverted);
|
||||
extern inline void bgc_versor_invert_fp64(const BgcVersorFP64* versor, BgcVersorFP64* inverted);
|
||||
extern inline void bgc_versor_get_shortened_fp32(const BgcVersorFP32* versor, BgcVersorFP32* shortened);
|
||||
extern inline void bgc_versor_get_shortened_fp64(const BgcVersorFP64* versor, BgcVersorFP64* shortened);
|
||||
|
||||
extern inline void bgc_versor_make_opposite_fp32(BgcVersorFP32* versor);
|
||||
extern inline void bgc_versor_make_opposite_fp64(BgcVersorFP64* versor);
|
||||
|
||||
extern inline void bgc_versor_get_opposite_fp32(const BgcVersorFP32* versor, BgcVersorFP32* opposite);
|
||||
extern inline void bgc_versor_get_opposite_fp64(const BgcVersorFP64* versor, BgcVersorFP64* opposite);
|
||||
|
||||
extern inline void bgc_versor_invert_fp32(BgcVersorFP32* versor);
|
||||
extern inline void bgc_versor_invert_fp64(BgcVersorFP64* versor);
|
||||
|
||||
extern inline void bgc_versor_get_inverse_fp32(const BgcVersorFP32* versor, BgcVersorFP32* inverse);
|
||||
extern inline void bgc_versor_get_inverse_fp64(const BgcVersorFP64* versor, BgcVersorFP64* inverse);
|
||||
|
||||
extern inline void bgc_versor_combine_fp32(const BgcVersorFP32* second, const BgcVersorFP32* first, BgcVersorFP32* result);
|
||||
extern inline void bgc_versor_combine_fp64(const BgcVersorFP64* second, const BgcVersorFP64* first, BgcVersorFP64* result);
|
||||
|
|
@ -49,8 +61,8 @@ extern inline void bgc_versor_get_rotation_matrix_fp64(const BgcVersorFP64* vers
|
|||
extern inline void bgc_versor_get_reverse_matrix_fp32(const BgcVersorFP32* versor, BgcMatrix3x3FP32* matrix);
|
||||
extern inline void bgc_versor_get_reverse_matrix_fp64(const BgcVersorFP64* versor, BgcMatrix3x3FP64* matrix);
|
||||
|
||||
extern inline void bgc_versor_get_both_matrixes_fp32(const BgcVersorFP32* versor, BgcMatrix3x3FP32* rotation, BgcMatrix3x3FP32* reverse);
|
||||
extern inline void bgc_versor_get_both_matrixes_fp64(const BgcVersorFP64* versor, BgcMatrix3x3FP64* rotation, BgcMatrix3x3FP64* reverse);
|
||||
extern inline void bgc_versor_get_both_matrices_fp32(const BgcVersorFP32* versor, BgcMatrix3x3FP32* rotation, BgcMatrix3x3FP32* reverse);
|
||||
extern inline void bgc_versor_get_both_matrices_fp64(const BgcVersorFP64* versor, BgcMatrix3x3FP64* rotation, BgcMatrix3x3FP64* reverse);
|
||||
|
||||
extern inline void bgc_versor_turn_vector_fp32(const BgcVersorFP32* versor, const BgcVector3FP32* vector, BgcVector3FP32* result);
|
||||
extern inline void bgc_versor_turn_vector_fp64(const BgcVersorFP64* versor, const BgcVector3FP64* vector, BgcVector3FP64* result);
|
||||
|
|
@ -63,44 +75,44 @@ extern inline int bgc_versor_are_close_fp64(const BgcVersorFP64* versor1, const
|
|||
|
||||
// ================= Normalize ================== //
|
||||
|
||||
void _bgc_versor_normalize_fp32(const float square_modulus, _BgcDarkTwinVersorFP32* twin)
|
||||
void _bgc_versor_normalize_fp32(const float square_modulus, BgcVersorFP32* versor)
|
||||
{
|
||||
// (square_modulus != square_modulus) is true when square_modulus is NaN
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
twin->s0 = 1.0f;
|
||||
twin->x1 = 0.0f;
|
||||
twin->x2 = 0.0f;
|
||||
twin->x3 = 0.0f;
|
||||
versor->_s0 = 1.0f;
|
||||
versor->_x1 = 0.0f;
|
||||
versor->_x2 = 0.0f;
|
||||
versor->_x3 = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
const float multiplier = sqrtf(1.0f / square_modulus);
|
||||
|
||||
twin->s0 *= multiplier;
|
||||
twin->x1 *= multiplier;
|
||||
twin->x2 *= multiplier;
|
||||
twin->x3 *= multiplier;
|
||||
versor->_s0 *= multiplier;
|
||||
versor->_x1 *= multiplier;
|
||||
versor->_x2 *= multiplier;
|
||||
versor->_x3 *= multiplier;
|
||||
}
|
||||
|
||||
void _bgc_versor_normalize_fp64(const double square_modulus, _BgcDarkTwinVersorFP64* twin)
|
||||
void _bgc_versor_normalize_fp64(const double square_modulus, BgcVersorFP64* versor)
|
||||
{
|
||||
// (square_modulus != square_modulus) is true when square_modulus is NaN
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
twin->s0 = 1.0;
|
||||
twin->x1 = 0.0;
|
||||
twin->x2 = 0.0;
|
||||
twin->x3 = 0.0;
|
||||
versor->_s0 = 1.0;
|
||||
versor->_x1 = 0.0;
|
||||
versor->_x2 = 0.0;
|
||||
versor->_x3 = 0.0;
|
||||
return;
|
||||
}
|
||||
|
||||
const double multiplier = sqrt(1.0 / square_modulus);
|
||||
|
||||
twin->s0 *= multiplier;
|
||||
twin->x1 *= multiplier;
|
||||
twin->x2 *= multiplier;
|
||||
twin->x3 *= multiplier;
|
||||
versor->_s0 *= multiplier;
|
||||
versor->_x1 *= multiplier;
|
||||
versor->_x2 *= multiplier;
|
||||
versor->_x3 *= multiplier;
|
||||
}
|
||||
|
||||
// ================== Set Turn ================== //
|
||||
|
|
@ -249,7 +261,7 @@ inline int _bgc_versor_validate_basis_fp32(const float primary_square_modulus, c
|
|||
return BGC_FAILED;
|
||||
}
|
||||
|
||||
if (orthogonal_square_modulus / (primary_square_modulus * auxiliary_square_modulus) <= BGC_SQUARE_EPSYLON_FP32) {
|
||||
if (orthogonal_square_modulus <= BGC_SQUARE_EPSYLON_FP32 * primary_square_modulus * auxiliary_square_modulus) {
|
||||
//TODO: add error code for: primary_vector and auxiliary_vector are parallel
|
||||
return BGC_FAILED;
|
||||
}
|
||||
|
|
@ -269,7 +281,7 @@ inline int _bgc_versor_validate_basis_fp64(const double primary_square_modulus,
|
|||
return BGC_FAILED;
|
||||
}
|
||||
|
||||
if (orthogonal_square_modulus / (primary_square_modulus * auxiliary_square_modulus) <= BGC_SQUARE_EPSYLON_FP64) {
|
||||
if (orthogonal_square_modulus <= BGC_SQUARE_EPSYLON_FP64 * primary_square_modulus * auxiliary_square_modulus) {
|
||||
//TODO: add error code for: primary_vector and auxiliary_vector are parallel
|
||||
return BGC_FAILED;
|
||||
}
|
||||
|
|
@ -423,7 +435,7 @@ int bgc_versor_make_basis_difference_fp64(
|
|||
|
||||
void bgc_versor_get_exponation_fp32(const BgcVersorFP32* base, const float exponent, BgcVersorFP32* power)
|
||||
{
|
||||
const float square_vector = base->x1 * base->x1 + base->x2 * base->x2 + base->x3 * base->x3;
|
||||
const float square_vector = base->_x1 * base->_x1 + base->_x2 * base->_x2 + base->_x3 * base->_x3;
|
||||
|
||||
if (square_vector <= BGC_SQUARE_EPSYLON_FP32 || square_vector != square_vector) {
|
||||
bgc_versor_reset_fp32(power);
|
||||
|
|
@ -432,16 +444,16 @@ void bgc_versor_get_exponation_fp32(const BgcVersorFP32* base, const float expon
|
|||
|
||||
const float vector_modulus = sqrtf(square_vector);
|
||||
|
||||
const float angle = atan2f(vector_modulus, base->s0) * exponent;
|
||||
const float angle = atan2f(vector_modulus, base->_s0) * exponent;
|
||||
|
||||
const float multiplier = sinf(angle) / vector_modulus;
|
||||
|
||||
bgc_versor_set_values_fp32(cosf(angle), base->x1 * multiplier, base->x2 * multiplier, base->x3 * multiplier, power);
|
||||
bgc_versor_set_values_fp32(cosf(angle), base->_x1 * multiplier, base->_x2 * multiplier, base->_x3 * multiplier, power);
|
||||
}
|
||||
|
||||
void bgc_versor_get_exponation_fp64(const BgcVersorFP64* base, const double exponent, BgcVersorFP64* power)
|
||||
{
|
||||
const double square_vector = base->x1 * base->x1 + base->x2 * base->x2 + base->x3 * base->x3;
|
||||
const double square_vector = base->_x1 * base->_x1 + base->_x2 * base->_x2 + base->_x3 * base->_x3;
|
||||
|
||||
if (square_vector <= BGC_SQUARE_EPSYLON_FP64 || square_vector != square_vector) {
|
||||
bgc_versor_reset_fp64(power);
|
||||
|
|
@ -450,21 +462,21 @@ void bgc_versor_get_exponation_fp64(const BgcVersorFP64* base, const double expo
|
|||
|
||||
const double vector_modulus = sqrt(square_vector);
|
||||
|
||||
const double angle = atan2(vector_modulus, base->s0) * exponent;
|
||||
const double angle = atan2(vector_modulus, base->_s0) * exponent;
|
||||
|
||||
const double multiplier = sin(angle) / vector_modulus;
|
||||
|
||||
bgc_versor_set_values_fp64(cos(angle), base->x1 * multiplier, base->x2 * multiplier, base->x3 * multiplier, power);
|
||||
bgc_versor_set_values_fp64(cos(angle), base->_x1 * multiplier, base->_x2 * multiplier, base->_x3 * multiplier, power);
|
||||
}
|
||||
|
||||
// ============ Sphere Interpolation ============ //
|
||||
|
||||
void bgc_versor_spherically_interpolate_fp32(const BgcVersorFP32* start, const BgcVersorFP32* end, const float phase, BgcVersorFP32* result)
|
||||
{
|
||||
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);
|
||||
const float delta_x2 = (end->x2 * start->s0 + end->x1 * start->x3) - (end->s0 * start->x2 + end->x3 * start->x1);
|
||||
const float delta_x3 = (end->x3 * start->s0 + end->x2 * start->x1) - (end->s0 * start->x3 + end->x1 * start->x2);
|
||||
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);
|
||||
const float delta_x2 = (end->_x2 * start->_s0 + end->_x1 * start->_x3) - (end->_s0 * start->_x2 + end->_x3 * start->_x1);
|
||||
const float delta_x3 = (end->_x3 * start->_s0 + end->_x2 * start->_x1) - (end->_s0 * start->_x3 + end->_x1 * start->_x2);
|
||||
|
||||
const float square_vector = delta_x1 * delta_x1 + delta_x2 * delta_x2 + delta_x3 * delta_x3;
|
||||
|
||||
|
|
@ -486,20 +498,20 @@ void bgc_versor_spherically_interpolate_fp32(const BgcVersorFP32* start, const B
|
|||
|
||||
// Combining of starting orientation with the turning
|
||||
bgc_versor_set_values_fp32(
|
||||
(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),
|
||||
(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
|
||||
);
|
||||
}
|
||||
|
||||
void bgc_versor_spherically_interpolate_fp64(const BgcVersorFP64* start, const BgcVersorFP64* end, const double phase, BgcVersorFP64* result)
|
||||
{
|
||||
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);
|
||||
const double delta_x2 = (end->x2 * start->s0 + end->x1 * start->x3) - (end->s0 * start->x2 + end->x3 * start->x1);
|
||||
const double delta_x3 = (end->x3 * start->s0 + end->x2 * start->x1) - (end->s0 * start->x3 + end->x1 * start->x2);
|
||||
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);
|
||||
const double delta_x2 = (end->_x2 * start->_s0 + end->_x1 * start->_x3) - (end->_s0 * start->_x2 + end->_x3 * start->_x1);
|
||||
const double delta_x3 = (end->_x3 * start->_s0 + end->_x2 * start->_x1) - (end->_s0 * start->_x3 + end->_x1 * start->_x2);
|
||||
|
||||
const double square_vector = delta_x1 * delta_x1 + delta_x2 * delta_x2 + delta_x3 * delta_x3;
|
||||
|
||||
|
|
@ -521,10 +533,10 @@ void bgc_versor_spherically_interpolate_fp64(const BgcVersorFP64* start, const B
|
|||
|
||||
// Combining of starting orientation with the turning
|
||||
bgc_versor_set_values_fp64(
|
||||
(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),
|
||||
(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
|
||||
);
|
||||
}
|
||||
|
|
@ -533,7 +545,7 @@ void bgc_versor_spherically_interpolate_fp64(const BgcVersorFP64* start, const B
|
|||
|
||||
void bgc_versor_get_rotation_fp32(const BgcVersorFP32* versor, BgcRotation3FP32* result)
|
||||
{
|
||||
const float square_modulus = versor->x1 * versor->x1 + versor->x2 * versor->x2 + versor->x3 * versor->x3;
|
||||
const float square_modulus = versor->_x1 * versor->_x1 + versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3;
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32) {
|
||||
bgc_rotation3_reset_fp32(result);
|
||||
|
|
@ -544,16 +556,16 @@ void bgc_versor_get_rotation_fp32(const BgcVersorFP32* versor, BgcRotation3FP32*
|
|||
|
||||
const float multiplier = 1.0f / vector_modulus;
|
||||
|
||||
result->radians = 2.0f * atan2f(vector_modulus, versor->s0);
|
||||
result->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;
|
||||
result->axis.x1 = versor->_x1 * multiplier;
|
||||
result->axis.x2 = versor->_x2 * multiplier;
|
||||
result->axis.x3 = versor->_x3 * multiplier;
|
||||
}
|
||||
|
||||
void bgc_versor_get_rotation_fp64(const BgcVersorFP64* versor, BgcRotation3FP64* result)
|
||||
{
|
||||
const double square_modulus = versor->x1 * versor->x1 + versor->x2 * versor->x2 + versor->x3 * versor->x3;
|
||||
const double square_modulus = versor->_x1 * versor->_x1 + versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3;
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64) {
|
||||
bgc_rotation3_reset_fp64(result);
|
||||
|
|
@ -564,9 +576,9 @@ void bgc_versor_get_rotation_fp64(const BgcVersorFP64* versor, BgcRotation3FP64*
|
|||
|
||||
const double multiplier = 1.0 / vector_modulus;
|
||||
|
||||
result->radians = 2.0 * atan2(vector_modulus, versor->s0);
|
||||
result->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;
|
||||
result->axis.x1 = versor->_x1 * multiplier;
|
||||
result->axis.x2 = versor->_x2 * multiplier;
|
||||
result->axis.x3 = versor->_x3 * multiplier;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue