Добавление сферической интерполяции, переход от применения 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_vector3_get_mean_of_two_fp64(const BgcVector3FP64* vector
extern inline void bgc_vector3_get_mean_of_three_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2, const BgcVector3FP32* vector3, BgcVector3FP32* result);
extern inline void bgc_vector3_get_mean_of_three_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2, const BgcVector3FP64* vector3, BgcVector3FP64* result);
extern inline void bgc_vector3_get_linear_interpolation_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2, const float phase, BgcVector3FP32* interpolation);
extern inline void bgc_vector3_get_linear_interpolation_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2, const double phase, BgcVector3FP64* interpolation);
extern inline void bgc_vector3_interpolate_linearly_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2, const float phase, BgcVector3FP32* interpolation);
extern inline void bgc_vector3_interpolate_linearly_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2, const double phase, BgcVector3FP64* interpolation);
extern inline void bgc_vector3_minimize_fp32(const BgcVector3FP32* vector, BgcVector3FP32* minimal);
extern inline void bgc_vector3_minimize_fp64(const BgcVector3FP64* vector, BgcVector3FP64* minimal);
@ -96,52 +96,52 @@ float bgc_vector3_get_angle_fp32(const BgcVector3FP32* vector1, const BgcVector3
{
const float square_modulus1 = bgc_vector3_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_vector3_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_vector3_get_scalar_product_fp32(vector1, vector2) / sqrtf(square_modulus1 * square_modulus2);
BgcVector3FP32 cross_product;
if (cosine >= 1.0f - BGC_EPSYLON_FP32) {
return 0.0f;
}
bgc_vector3_get_cross_product_fp32(vector1, vector2, &cross_product);
if (cosine <= -1.0f + BGC_EPSYLON_FP32) {
return bgc_angle_get_half_circle_fp32(unit);
}
const float scalar = bgc_vector3_get_scalar_product_fp32(vector1, vector2);
return bgc_radians_to_units_fp32(acosf(cosine), unit);
const float cross = bgc_vector3_get_modulus_fp32(&cross_product);
return bgc_radians_to_units_fp32(atan2f(cross, scalar), unit);
}
double bgc_vector3_get_angle_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2, const BgcAngleUnitEnum unit)
{
const double square_modulus1 = bgc_vector3_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_vector3_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_vector3_get_scalar_product_fp64(vector1, vector2) / sqrt(square_modulus1 * square_modulus2);
BgcVector3FP64 cross_product;
if (cosine >= 1.0 - BGC_EPSYLON_FP64) {
return 0.0;
}
bgc_vector3_get_cross_product_fp64(vector1, vector2, &cross_product);
if (cosine <= -1.0 + BGC_EPSYLON_FP64) {
return bgc_angle_get_half_circle_fp64(unit);
}
const double scalar = bgc_vector3_get_scalar_product_fp64(vector1, vector2);
return bgc_radians_to_units_fp64(acos(cosine), unit);
const double cross = bgc_vector3_get_modulus_fp64(&cross_product);
return bgc_radians_to_units_fp64(atan2(cross, scalar), unit);
}