Переименование tangent pair в числа Котса, выделение комплексных чисел из двумерных векторов, добавление возведения в спебень для веросорв и чисел Котса

This commit is contained in:
Andrey Pokidov 2025-02-26 16:27:33 +07:00
parent 34ee460873
commit 74be89f1f8
17 changed files with 1233 additions and 646 deletions

View file

@ -79,7 +79,7 @@ void list_work(const uint_fast32_t amount, structure_fp32_t* list)
}
}
}
/*
int main()
{
const unsigned int amount = 1000000;
@ -121,3 +121,34 @@ int main()
return 0;
}
*/
/*
int main() {
BgcComplexFP32 complex, exponent, result;
bgc_complex_set_values_fp32(0, 1, &complex);
bgc_complex_set_values_fp32(4, 0, &exponent);
bgc_complex_get_exponation_fp32(&complex, exponent.real, exponent.imaginary, &result);
printf("(%f, %f) ^ (%f, %f) = (%f, %f)\n", complex.real, complex.imaginary, exponent.real, exponent.imaginary, result.real, result.imaginary);
return 0;
}
*/
int main() {
const float exponent = 2.0f;
BgcVersorFP32 turn, result;
bgc_versor_set_turn_fp32(0, 0, 1, 120, BGC_ANGLE_UNIT_DEGREES, &turn);
bgc_versor_get_exponation_fp32(&turn, exponent, &result);
printf("(%f, %f, %f, %f) ^ %f = (%f, %f, %f, %f)\n", turn.s0, turn.x1, turn.x2, turn.x3, exponent, result.s0, result.x1, result.x2, result.x3);
return 0;
}

View file

@ -48,6 +48,14 @@
</Unit>
<Unit filename="angle.h" />
<Unit filename="basic-geometry.h" />
<Unit filename="complex.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="complex.h" />
<Unit filename="cotes-number.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="cotes-number.h" />
<Unit filename="matrix2x2.c">
<Option compilerVar="CC" />
</Unit>
@ -76,10 +84,6 @@
<Option compilerVar="CC" />
</Unit>
<Unit filename="rotation3.h" />
<Unit filename="tangent-pair.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="tangent-pair.h" />
<Unit filename="utilities.c">
<Option compilerVar="CC" />
</Unit>

View file

@ -1,24 +1,25 @@
#ifndef _BGC_H_
#define _BGC_H_
#include "utilities.h"
#include "./utilities.h"
#include "angle.h"
#include "./angle.h"
#include "vector2.h"
#include "vector3.h"
#include "./vector2.h"
#include "./vector3.h"
#include "matrixes.h"
#include "matrix2x2.h"
#include "matrix2x3.h"
#include "matrix3x2.h"
#include "matrix3x3.h"
#include "./matrixes.h"
#include "./matrix2x2.h"
#include "./matrix2x3.h"
#include "./matrix3x2.h"
#include "./matrix3x3.h"
#include "./complex.h"
#include "./cotes-number.h"
#include "tangent-pair.h"
#include "./rotation3.h"
#include "rotation3.h"
#include "quaternion.h"
#include "versor.h"
#include "./quaternion.h"
#include "./versor.h"
#endif

View file

@ -21,6 +21,8 @@
<ItemGroup>
<ClInclude Include="angle.h" />
<ClInclude Include="basic-geometry.h" />
<ClInclude Include="complex.h" />
<ClInclude Include="cotes-number.h" />
<ClInclude Include="matrix2x2.h" />
<ClInclude Include="matrix2x3.h" />
<ClInclude Include="matrix3x2.h" />
@ -28,7 +30,6 @@
<ClInclude Include="matrixes.h" />
<ClInclude Include="quaternion.h" />
<ClInclude Include="rotation3.h" />
<ClInclude Include="tangent-pair.h" />
<ClInclude Include="utilities.h" />
<ClInclude Include="versor.h" />
<ClInclude Include="vector2.h" />
@ -36,6 +37,8 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="angle.c" />
<ClInclude Include="complex.c" />
<ClInclude Include="cotes-number.c" />
<ClCompile Include="utilities.c" />
<ClCompile Include="matrix2x2.c" />
<ClCompile Include="matrix2x3.c" />
@ -44,7 +47,7 @@
<ClCompile Include="matrixes.c" />
<ClCompile Include="quaternion.c" />
<ClCompile Include="rotation3.c" />
<ClCompile Include="tangent-pair.c" />
<ClCompile Include="cotes-number.c" />
<ClCompile Include="versor.c" />
<ClCompile Include="vector2.c" />
<ClCompile Include="vector3.c" />

View file

@ -18,6 +18,12 @@
<ClInclude Include="angle.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
<ClInclude Include="complex.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
<ClInclude Include="cotes-number.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
<ClInclude Include="utilities.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
@ -54,14 +60,17 @@
<ClInclude Include="matrixes.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
<ClInclude Include="tangent-pair.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="angle.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="complex.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="cotes-number.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="utilities.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
@ -95,8 +104,5 @@
<ClCompile Include="matrix3x2.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="tangent-pair.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
</ItemGroup>
</Project>

124
basic-geometry/complex.c Normal file
View file

@ -0,0 +1,124 @@
#include "./complex.h"
extern inline void bgc_complex_reset_fp32(BgcComplexFP32* complex);
extern inline void bgc_complex_reset_fp64(BgcComplexFP64* complex);
extern inline void bgc_complex_set_values_fp32(const float real, const float imaginary, BgcComplexFP32* destination);
extern inline void bgc_complex_set_values_fp64(const double real, const double imaginary, BgcComplexFP64* destination);
extern inline float bgc_complex_get_square_modulus_fp32(const BgcComplexFP32* number);
extern inline double bgc_complex_get_square_modulus_fp64(const BgcComplexFP64* number);
extern inline float bgc_complex_get_modulus_fp32(const BgcComplexFP32* number);
extern inline double bgc_complex_get_modulus_fp64(const BgcComplexFP64* number);
extern inline int bgc_complex_is_zero_fp32(const BgcComplexFP32* number);
extern inline int bgc_complex_is_zero_fp64(const BgcComplexFP64* number);
extern inline int bgc_complex_is_unit_fp32(const BgcComplexFP32* number);
extern inline int bgc_complex_is_unit_fp64(const BgcComplexFP64* number);
extern inline void bgc_complex_copy_fp32(const BgcComplexFP32* source, BgcComplexFP32* destination);
extern inline void bgc_complex_copy_fp64(const BgcComplexFP64* source, BgcComplexFP64* destination);
extern inline void bgc_complex_swap_fp32(BgcComplexFP32* number1, BgcComplexFP32* number2);
extern inline void bgc_complex_swap_fp64(BgcComplexFP64* number1, BgcComplexFP64* number2);
extern inline void bgc_complex_convert_fp64_to_fp32(const BgcComplexFP64* source, BgcComplexFP32* destination);
extern inline void bgc_complex_convert_fp32_to_fp64(const BgcComplexFP32* source, BgcComplexFP64* destination);
extern inline void bgc_complex_reverse_fp32(const BgcComplexFP32* number, BgcComplexFP32* reverse);
extern inline void bgc_complex_reverse_fp64(const BgcComplexFP64* number, BgcComplexFP64* reverse);
extern inline int bgc_complex_normalize_fp32(const BgcComplexFP32* number, BgcComplexFP32* normalized);
extern inline int bgc_complex_normalize_fp64(const BgcComplexFP64* number, BgcComplexFP64* normalized);
extern inline void bgc_complex_conjugate_fp32(const BgcComplexFP32* number, BgcComplexFP32* conjugate);
extern inline void bgc_complex_conjugate_fp64(const BgcComplexFP64* number, BgcComplexFP64* conjugate);
extern inline int bgc_complex_invert_fp32(const BgcComplexFP32* number, BgcComplexFP32* inverted);
extern inline int bgc_complex_invert_fp64(const BgcComplexFP64* number, BgcComplexFP64* inverted);
extern inline void bgc_complex_get_product_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, BgcComplexFP32* result);
extern inline void bgc_complex_get_product_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, BgcComplexFP64* result);
extern inline int bgc_complex_get_ratio_fp32(const BgcComplexFP32* divident, const BgcComplexFP32* divisor, BgcComplexFP32* quotient);
extern inline int bgc_complex_get_ratio_fp64(const BgcComplexFP64* divident, const BgcComplexFP64* divisor, BgcComplexFP64* quotient);
extern inline void bgc_complex_add_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, BgcComplexFP32* sum);
extern inline void bgc_complex_add_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, BgcComplexFP64* sum);
extern inline void bgc_complex_add_scaled_fp32(const BgcComplexFP32* basic_number, const BgcComplexFP32* scalable_number, const float scale, BgcComplexFP32* sum);
extern inline void bgc_complex_add_scaled_fp64(const BgcComplexFP64* basic_number, const BgcComplexFP64* scalable_number, const double scale, BgcComplexFP64* sum);
extern inline void bgc_complex_subtract_fp32(const BgcComplexFP32* minuend, const BgcComplexFP32* subtrahend, BgcComplexFP32* difference);
extern inline void bgc_complex_subtract_fp64(const BgcComplexFP64* minuend, const BgcComplexFP64* subtrahend, BgcComplexFP64* difference);
extern inline void bgc_complex_subtract_scaled_fp32(const BgcComplexFP32* basic_number, const BgcComplexFP32* scalable_number, const float scale, BgcComplexFP32* difference);
extern inline void bgc_complex_subtract_scaled_fp64(const BgcComplexFP64* basic_number, const BgcComplexFP64* scalable_number, const double scale, BgcComplexFP64* difference);
extern inline void bgc_complex_multiply_fp32(const BgcComplexFP32* multiplicand, const float multiplier, BgcComplexFP32* product);
extern inline void bgc_complex_multiply_fp64(const BgcComplexFP64* multiplicand, const double multiplier, BgcComplexFP64* product);
extern inline void bgc_complex_divide_fp32(const BgcComplexFP32* dividend, const float divisor, BgcComplexFP32* quotient);
extern inline void bgc_complex_divide_fp64(const BgcComplexFP64* dividend, const double divisor, BgcComplexFP64* quotient);
extern inline void bgc_complex_get_mean_of_two_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, BgcComplexFP32* mean);
extern inline void bgc_complex_get_mean_of_two_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, BgcComplexFP64* mean);
extern inline void bgc_complex_get_mean_of_three_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, const BgcComplexFP32* number3, BgcComplexFP32* mean);
extern inline void bgc_complex_get_mean_of_three_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, const BgcComplexFP64* number3, BgcComplexFP64* mean);
extern inline void bgc_complex_get_linear_interpolation_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, const float phase, BgcComplexFP32* interpolation);
extern inline void bgc_complex_get_linear_interpolation_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, const double phase, BgcComplexFP64* interpolation);
extern inline void bgc_complex_minimize_fp32(const BgcComplexFP32* number, BgcComplexFP32* minimal);
extern inline void bgc_complex_minimize_fp64(const BgcComplexFP64* number, BgcComplexFP64* minimal);
extern inline void bgc_complex_maximize_fp32(const BgcComplexFP32* number, BgcComplexFP32* maximal);
extern inline void bgc_complex_maximize_fp64(const BgcComplexFP64* number, BgcComplexFP64* maximal);
extern inline int bgc_complex_are_close_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2);
extern inline int bgc_complex_are_close_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2);
// =============== Get Exponation =============== //
void bgc_complex_get_exponation_fp32(const BgcComplexFP32* base, const float real_exponent, const float imaginary_exponent, BgcComplexFP32* power)
{
const float square_modulus = bgc_complex_get_square_modulus_fp32(base);
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32) {
power->real = 0.0f;
power->imaginary = 0.0f;
return;
}
const float log_modulus = logf(square_modulus) * 0.5f;
const float angle = atan2f(base->imaginary, base->real);
const float power_modulus = expf(real_exponent * log_modulus - imaginary_exponent * angle);
const float power_angle = real_exponent * angle + imaginary_exponent * log_modulus;
power->real = power_modulus * cosf(power_angle);
power->imaginary = power_modulus * sinf(power_angle);
}
void bgc_complex_get_exponation_fp64(const BgcComplexFP64* base, const double real_exponent, const double imaginary_exponent, BgcComplexFP64* power)
{
const double square_modulus = bgc_complex_get_square_modulus_fp64(base);
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64) {
power->real = 0.0;
power->imaginary = 0.0;
return;
}
const double log_modulus = log(square_modulus) * 0.5;
const double angle = atan2(base->imaginary, base->real);
const double power_modulus = exp(real_exponent * log_modulus - imaginary_exponent * angle);
const double power_angle = real_exponent * angle + imaginary_exponent * log_modulus;
power->real = power_modulus * cos(power_angle);
power->imaginary = power_modulus * sin(power_angle);
}

531
basic-geometry/complex.h Normal file
View file

Internal server error - Personal Git Server: Beyond coding. We Forge.

500

Internal server error

Forgejo version: 11.0.1+gitea-1.22.0

@ -0,0 +1,531 @@
#ifndef _BGC_COMPLEX_H_
#define _BGC_COMPLEX_H_
#include "utilities.h"
#include "angle.h"
#include <math.h>
typedef struct
{
float real, imaginary;
} BgcComplexFP32;
typedef struct
{
double real, imaginary;
} BgcComplexFP64;
// =================== Reset ==================== //
inline void bgc_complex_reset_fp32(BgcComplexFP32* complex)
{
complex->real = 0.0f;
complex->imaginary = 0.0f;
}
inline void bgc_complex_reset_fp64(BgcComplexFP64* complex)
{
complex->real = 0.0;
complex->imaginary = 0.0;
}
// ==================== Set ===================== //