Добавление сферической интерполяции, переход от применения acos к применению atan2, исправление ошибок

This commit is contained in:
Andrey Pokidov 2025-03-17 09:56:56 +07:00
parent f06b35ae34
commit 9d7011e81e
17 changed files with 558 additions and 134 deletions

View file

@ -57,8 +57,8 @@ extern inline void bgc_vector2_get_mean_of_two_fp64(const BgcVector2FP64* vector
extern inline void bgc_vector2_get_mean_of_three_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const BgcVector2FP32* vector3, BgcVector2FP32* mean);
extern inline void bgc_vector2_get_mean_of_three_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, const BgcVector2FP64* vector3, BgcVector2FP64* mean);
extern inline void bgc_vector2_get_linear_interpolation_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const float phase, BgcVector2FP32* interpolation);
extern inline void bgc_vector2_get_linear_interpolation_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, const double phase, BgcVector2FP64* interpolation);
extern inline void bgc_vector2_interpolate_linearly_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const float phase, BgcVector2FP32* interpolation);
extern inline void bgc_vector2_interpolate_linearly_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, const double phase, BgcVector2FP64* interpolation);
extern inline void bgc_vector2_minimize_fp32(const BgcVector2FP32* vector, BgcVector2FP32* minimal);
extern inline void bgc_vector2_minimize_fp64(const BgcVector2FP64* vector, BgcVector2FP64* minimal);
@ -90,52 +90,44 @@ float bgc_vector2_get_angle_fp32(const BgcVector2FP32* vector1, const BgcVector2
{
const float square_modulus1 = bgc_vector2_get_square_modulus_fp32(vector1);
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP32) {
// square_modulus1 != square_modulus1 is check for NaN value at square_modulus1
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP32 || square_modulus1 != square_modulus1) {
return 0.0f;
}
const float square_modulus2 = bgc_vector2_get_square_modulus_fp32(vector2);
if (square_modulus2 <= BGC_SQUARE_EPSYLON_FP32) {
// square_modulus2 != square_modulus2 is check for NaN value at square_modulus2
if (square_modulus2 <= BGC_SQUARE_EPSYLON_FP32 || square_modulus2 != square_modulus2) {
return 0.0f;
}
const float cosine = bgc_vector2_get_scalar_product_fp32(vector1, vector2) / sqrtf(square_modulus1 * square_modulus2);
const float scalar = bgc_vector2_get_scalar_product_fp32(vector1, vector2);
if (cosine >= 1.0f - BGC_EPSYLON_FP32) {
return 0.0f;
}
const float cross = bgc_vector2_get_cross_product_fp32(vector1, vector2);
if (cosine <= -1.0f + BGC_EPSYLON_FP32) {
return bgc_angle_get_half_circle_fp32(unit);
}
return bgc_radians_to_units_fp32(acosf(cosine), unit);
return bgc_radians_to_units_fp32(atan2f(cross >= 0 ? cross : -cross, scalar), unit);
}
double bgc_vector2_get_angle_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, const BgcAngleUnitEnum unit)
{
const double square_modulus1 = bgc_vector2_get_square_modulus_fp64(vector1);
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP64) {
// square_modulus1 != square_modulus1 is check for NaN value at square_modulus1
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP64 || square_modulus1 != square_modulus1) {
return 0.0;
}
const double square_modulus2 = bgc_vector2_get_square_modulus_fp64(vector2);
if (square_modulus2 <= BGC_SQUARE_EPSYLON_FP64) {
// square_modulus2 != square_modulus2 is check for NaN value at square_modulus2
if (square_modulus2 <= BGC_SQUARE_EPSYLON_FP64 || square_modulus2 != square_modulus2) {
return 0.0;
}
const double cosine = bgc_vector2_get_scalar_product_fp64(vector1, vector2) / sqrt(square_modulus1 * square_modulus2);
const double scalar = bgc_vector2_get_scalar_product_fp64(vector1, vector2);
if (cosine >= 1.0 - BGC_EPSYLON_FP64) {
return 0.0;
}
const double cross = bgc_vector2_get_cross_product_fp64(vector1, vector2);
if (cosine <= -1.0 + BGC_EPSYLON_FP64) {
return bgc_angle_get_half_circle_fp64(unit);
}
return bgc_radians_to_units_fp64(acos(cosine), unit);
return bgc_radians_to_units_fp64(atan2(cross >= 0 ? cross : -cross, scalar), unit);
}