Добавлено вощведение в степень комплексного числа

This commit is contained in:
Andrey Pokidov 2025-02-25 17:14:21 +07:00
parent 08c1e6d148
commit f547ba69e6
3 changed files with 50 additions and 2 deletions

View file

@ -129,7 +129,7 @@ inline float bgc_tangent_pair_get_angle_fp32(const BgcTangentPairFP32* tangent,
return 0.75f * bgc_angle_get_full_circle_fp32(unit); return 0.75f * bgc_angle_get_full_circle_fp32(unit);
} }
return bgc_radians_to_units_fp32(atan2f(tangent->cos, tangent->sin), unit); return bgc_radians_to_units_fp32(atan2f(tangent->sin, tangent->cos), unit);
} }
inline double bgc_tangent_pair_get_angle_fp64(const BgcTangentPairFP64* tangent, const BgcAngleUnitEnum unit) inline double bgc_tangent_pair_get_angle_fp64(const BgcTangentPairFP64* tangent, const BgcAngleUnitEnum unit)
@ -150,7 +150,7 @@ inline double bgc_tangent_pair_get_angle_fp64(const BgcTangentPairFP64* tangent,
return 0.75 * bgc_angle_get_full_circle_fp64(unit); return 0.75 * bgc_angle_get_full_circle_fp64(unit);
} }
return bgc_radians_to_units_fp64(atan2(tangent->cos, tangent->sin), unit); return bgc_radians_to_units_fp64(atan2(tangent->sin, tangent->cos), unit);
} }
// ==================== Copy ==================== // // ==================== Copy ==================== //

View file

@ -93,6 +93,48 @@ extern inline int bgc_vector2_are_close_enough_fp64(const BgcVector2FP64* vector
extern inline int bgc_vector2_are_close_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2); extern inline int bgc_vector2_are_close_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2);
extern inline int bgc_vector2_are_close_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2); extern inline int bgc_vector2_are_close_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2);
// =============== Complex Power ================ //
void bgc_vector2_get_complex_power_fp32(const BgcVector2FP32* base, const BgcVector2FP32* power, BgcVector2FP32* result)
{
const float base_square_modulus = bgc_vector2_get_square_modulus_fp32(base);
if (base_square_modulus <= BGC_SQUARE_EPSYLON_FP32) {
result->x1 = 0.0f;
result->x2 = 0.0f;
return;
}
const float log_modulus = logf(base_square_modulus) * 0.5f;
const float angle = atan2f(base->x2, base->x1);
const float result_modulus = expf(power->x1 * log_modulus - power->x2 * angle);
const float result_angle = power->x1 * angle + power->x2 * log_modulus;
result->x1 = result_modulus * cosf(result_angle);
result->x2 = result_modulus * sinf(result_angle);
}
void bgc_vector2_get_complex_power_fp64(const BgcVector2FP64* base, const BgcVector2FP64* power, BgcVector2FP64* result)
{
const double base_square_modulus = bgc_vector2_get_square_modulus_fp64(base);
if (base_square_modulus <= BGC_SQUARE_EPSYLON_FP64) {
result->x1 = 0.0;
result->x2 = 0.0;
return;
}
const double log_modulus = log(base_square_modulus) * 0.5;
const double angle = atan2(base->x2, base->x1);
const double result_modulus = exp(power->x1 * log_modulus - power->x2 * angle);
const double result_angle = power->x1 * angle + power->x2 * log_modulus;
result->x1 = result_modulus * cos(result_angle);
result->x2 = result_modulus * sin(result_angle);
}
// =================== Angle ==================== // // =================== Angle ==================== //
float bgc_vector2_get_angle_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const BgcAngleUnitEnum unit) float bgc_vector2_get_angle_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const BgcAngleUnitEnum unit)

View file

@ -458,6 +458,12 @@ inline void bgc_vector2_get_complex_product_fp64(const BgcVector2FP64* vector1,
result->x2 = x2; result->x2 = x2;
} }
// =============== Complex Power ================ //
void bgc_vector2_get_complex_power_fp32(const BgcVector2FP32* base, const BgcVector2FP32* power, BgcVector2FP32* result);
void bgc_vector2_get_complex_power_fp64(const BgcVector2FP64* base, const BgcVector2FP64* power, BgcVector2FP64* result);
// =================== Angle ==================== // // =================== Angle ==================== //
float bgc_vector2_get_angle_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const BgcAngleUnitEnum unit); float bgc_vector2_get_angle_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const BgcAngleUnitEnum unit);