From f547ba69e6b152f07e4d68fd3e9c90181fbb548b Mon Sep 17 00:00:00 2001 From: Andrey Pokidov <9942846+Morgend@users.noreply.github.com> Date: Tue, 25 Feb 2025 17:14:21 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=B2=D0=BE=D1=89=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B2=20=D1=81=D1=82=D0=B5=D0=BF=D0=B5=D0=BD?= =?UTF-8?q?=D1=8C=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BB=D0=B5=D0=BA=D1=81=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D1=87=D0=B8=D1=81=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- basic-geometry/tangent-pair.h | 4 ++-- basic-geometry/vector2.c | 42 +++++++++++++++++++++++++++++++++++ basic-geometry/vector2.h | 6 +++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/basic-geometry/tangent-pair.h b/basic-geometry/tangent-pair.h index 0375771..8305fbf 100644 --- a/basic-geometry/tangent-pair.h +++ b/basic-geometry/tangent-pair.h @@ -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 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) @@ -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 bgc_radians_to_units_fp64(atan2(tangent->cos, tangent->sin), unit); + return bgc_radians_to_units_fp64(atan2(tangent->sin, tangent->cos), unit); } // ==================== Copy ==================== // diff --git a/basic-geometry/vector2.c b/basic-geometry/vector2.c index 62d261e..c2aeece 100644 --- a/basic-geometry/vector2.c +++ b/basic-geometry/vector2.c @@ -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_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 ==================== // float bgc_vector2_get_angle_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const BgcAngleUnitEnum unit) diff --git a/basic-geometry/vector2.h b/basic-geometry/vector2.h index 3347351..1db1291 100644 --- a/basic-geometry/vector2.h +++ b/basic-geometry/vector2.h @@ -458,6 +458,12 @@ inline void bgc_vector2_get_complex_product_fp64(const BgcVector2FP64* vector1, 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 ==================== // float bgc_vector2_get_angle_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const BgcAngleUnitEnum unit);