Упорядочивание проекта
This commit is contained in:
parent
0dcd9c0d4d
commit
89dfd7644b
32 changed files with 1730 additions and 1719 deletions
|
|
@ -30,6 +30,7 @@
|
|||
<ClInclude Include="matrixes.h" />
|
||||
<ClInclude Include="quaternion.h" />
|
||||
<ClInclude Include="rotation3.h" />
|
||||
<ClInclude Include="types.h" />
|
||||
<ClInclude Include="utilities.h" />
|
||||
<ClInclude Include="slerp.h" />
|
||||
<ClInclude Include="versor.h" />
|
||||
|
|
|
|||
|
|
@ -69,6 +69,9 @@
|
|||
<ClInclude Include="slerp.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="types.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="angle.c">
|
||||
|
|
|
|||
|
|
@ -27,23 +27,35 @@ extern inline void bgc_complex_swap_fp64(BgcComplexFP64* number1, BgcComplexFP64
|
|||
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 void bgc_complex_make_opposite_fp32(BgcComplexFP32* number);
|
||||
extern inline void bgc_complex_make_opposite_fp64(BgcComplexFP64* number);
|
||||
|
||||
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_get_opposite_fp32(const BgcComplexFP32* number, BgcComplexFP32* opposite);
|
||||
extern inline void bgc_complex_get_opposite_fp64(const BgcComplexFP64* number, BgcComplexFP64* opposite);
|
||||
|
||||
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_normalize_fp32(BgcComplexFP32* number);
|
||||
extern inline int bgc_complex_normalize_fp64(BgcComplexFP64* number);
|
||||
|
||||
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 int bgc_complex_get_normalized_fp32(const BgcComplexFP32* number, BgcComplexFP32* normalized);
|
||||
extern inline int bgc_complex_get_normalized_fp64(const BgcComplexFP64* number, BgcComplexFP64* normalized);
|
||||
|
||||
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 void bgc_complex_conjugate_fp32(BgcComplexFP32* number);
|
||||
extern inline void bgc_complex_conjugate_fp64(BgcComplexFP64* number);
|
||||
|
||||
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_get_conjugate_fp32(const BgcComplexFP32* number, BgcComplexFP32* conjugate);
|
||||
extern inline void bgc_complex_get_conjugate_fp64(const BgcComplexFP64* number, BgcComplexFP64* conjugate);
|
||||
|
||||
extern inline int bgc_complex_invert_fp32(BgcComplexFP32* number);
|
||||
extern inline int bgc_complex_invert_fp64(BgcComplexFP64* number);
|
||||
|
||||
extern inline int bgc_complex_get_inverse_fp32(const BgcComplexFP32* number, BgcComplexFP32* inverse);
|
||||
extern inline int bgc_complex_get_inverse_fp64(const BgcComplexFP64* number, BgcComplexFP64* inverse);
|
||||
|
||||
extern inline void bgc_complex_multiply_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, BgcComplexFP32* result);
|
||||
extern inline void bgc_complex_multiply_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, BgcComplexFP64* result);
|
||||
|
||||
extern inline int bgc_complex_devide_fp32(const BgcComplexFP32* divident, const BgcComplexFP32* divisor, BgcComplexFP32* quotient);
|
||||
extern inline int bgc_complex_devide_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);
|
||||
|
|
@ -54,13 +66,10 @@ extern inline void bgc_complex_add_scaled_fp64(const BgcComplexFP64* basic_numbe
|
|||
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_by_number_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_by_number_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);
|
||||
|
|
@ -69,14 +78,8 @@ extern inline void bgc_complex_get_mean_of_two_fp64(const BgcComplexFP64* number
|
|||
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_interpolate_linearly_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, const float phase, BgcComplexFP32* interpolation);
|
||||
extern inline void bgc_complex_interpolate_linearly_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 void bgc_complex_interpolate_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, const float phase, BgcComplexFP32* interpolation);
|
||||
extern inline void bgc_complex_interpolate_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, const double phase, BgcComplexFP64* interpolation);
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -142,23 +142,75 @@ inline void bgc_complex_convert_fp32_to_fp64(const BgcComplexFP32* source, BgcCo
|
|||
destination->imaginary = source->imaginary;
|
||||
}
|
||||
|
||||
// ================== Reverse =================== //
|
||||
// ================== Negative ================== //
|
||||
|
||||
inline void bgc_complex_reverse_fp32(const BgcComplexFP32* number, BgcComplexFP32* reverse)
|
||||
inline void bgc_complex_make_opposite_fp32(BgcComplexFP32* number)
|
||||
{
|
||||
reverse->real = -number->real;
|
||||
reverse->imaginary = -number->imaginary;
|
||||
number->real = -number->real;
|
||||
number->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_reverse_fp64(const BgcComplexFP64* number, BgcComplexFP64* reverse)
|
||||
inline void bgc_complex_make_opposite_fp64(BgcComplexFP64* number)
|
||||
{
|
||||
reverse->real = -number->real;
|
||||
reverse->imaginary = -number->imaginary;
|
||||
number->real = -number->real;
|
||||
number->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_get_opposite_fp32(const BgcComplexFP32* number, BgcComplexFP32* opposite)
|
||||
{
|
||||
opposite->real = -number->real;
|
||||
opposite->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_get_opposite_fp64(const BgcComplexFP64* number, BgcComplexFP64* opposite)
|
||||
{
|
||||
opposite->real = -number->real;
|
||||
opposite->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
// ================= Normalize ================== //
|
||||
|
||||
inline int bgc_complex_normalize_fp32(const BgcComplexFP32* number, BgcComplexFP32* normalized)
|
||||
inline int bgc_complex_normalize_fp32(BgcComplexFP32* number)
|
||||
{
|
||||
const float square_modulus = bgc_complex_get_square_modulus_fp32(number);
|
||||
|
||||
if (bgc_is_sqare_unit_fp32(square_modulus)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float multiplicand = sqrtf(1.0f / square_modulus);
|
||||
|
||||
number->real *= multiplicand;
|
||||
number->imaginary *= multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_complex_normalize_fp64(BgcComplexFP64* number)
|
||||
{
|
||||
const double square_modulus = bgc_complex_get_square_modulus_fp64(number);
|
||||
|
||||
if (bgc_is_sqare_unit_fp64(square_modulus)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double multiplicand = sqrt(1.0 / square_modulus);
|
||||
|
||||
number->real *= multiplicand;
|
||||
number->imaginary *= multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_complex_get_normalized_fp32(const BgcComplexFP32* number, BgcComplexFP32* normalized)
|
||||
{
|
||||
const float square_modulus = bgc_complex_get_square_modulus_fp32(number);
|
||||
|
||||
|
|
@ -169,6 +221,8 @@ inline int bgc_complex_normalize_fp32(const BgcComplexFP32* number, BgcComplexFP
|
|||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
normalized->real = 0.0f;
|
||||
normalized->imaginary = 0.0f;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -180,7 +234,7 @@ inline int bgc_complex_normalize_fp32(const BgcComplexFP32* number, BgcComplexFP
|
|||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_complex_normalize_fp64(const BgcComplexFP64* number, BgcComplexFP64* normalized)
|
||||
inline int bgc_complex_get_normalized_fp64(const BgcComplexFP64* number, BgcComplexFP64* normalized)
|
||||
{
|
||||
const double square_modulus = bgc_complex_get_square_modulus_fp64(number);
|
||||
|
||||
|
|
@ -191,6 +245,8 @@ inline int bgc_complex_normalize_fp64(const BgcComplexFP64* number, BgcComplexFP
|
|||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
normalized->real = 0.0;
|
||||
normalized->imaginary = 0.0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -204,13 +260,23 @@ inline int bgc_complex_normalize_fp64(const BgcComplexFP64* number, BgcComplexFP
|
|||
|
||||
// ================= Conjugate ================== //
|
||||
|
||||
inline void bgc_complex_conjugate_fp32(const BgcComplexFP32* number, BgcComplexFP32* conjugate)
|
||||
inline void bgc_complex_conjugate_fp32(BgcComplexFP32* number)
|
||||
{
|
||||
number->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_conjugate_fp64(BgcComplexFP64* number)
|
||||
{
|
||||
number->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_get_conjugate_fp32(const BgcComplexFP32* number, BgcComplexFP32* conjugate)
|
||||
{
|
||||
conjugate->real = number->real;
|
||||
conjugate->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_conjugate_fp64(const BgcComplexFP64* number, BgcComplexFP64* conjugate)
|
||||
inline void bgc_complex_get_conjugate_fp64(const BgcComplexFP64* number, BgcComplexFP64* conjugate)
|
||||
{
|
||||
conjugate->real = number->real;
|
||||
conjugate->imaginary = -number->imaginary;
|
||||
|
|
@ -218,7 +284,7 @@ inline void bgc_complex_conjugate_fp64(const BgcComplexFP64* number, BgcComplexF
|
|||
|
||||
// =================== Invert =================== //
|
||||
|
||||
inline int bgc_complex_invert_fp32(const BgcComplexFP32* number, BgcComplexFP32* inverted)
|
||||
inline int bgc_complex_get_inverse_fp32(const BgcComplexFP32* number, BgcComplexFP32* inverse)
|
||||
{
|
||||
const float square_modulus = bgc_complex_get_square_modulus_fp32(number);
|
||||
|
||||
|
|
@ -228,13 +294,13 @@ inline int bgc_complex_invert_fp32(const BgcComplexFP32* number, BgcComplexFP32*
|
|||
|
||||
const float multiplicand = 1.0f / square_modulus;
|
||||
|
||||
inverted->real = number->real * multiplicand;
|
||||
inverted->imaginary = -number->imaginary * multiplicand;
|
||||
inverse->real = number->real * multiplicand;
|
||||
inverse->imaginary = -number->imaginary * multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_complex_invert_fp64(const BgcComplexFP64* number, BgcComplexFP64* inverted)
|
||||
inline int bgc_complex_get_inverse_fp64(const BgcComplexFP64* number, BgcComplexFP64* inverse)
|
||||
{
|
||||
const double square_modulus = bgc_complex_get_square_modulus_fp64(number);
|
||||
|
||||
|
|
@ -244,70 +310,20 @@ inline int bgc_complex_invert_fp64(const BgcComplexFP64* number, BgcComplexFP64*
|
|||
|
||||
const double multiplicand = 1.0 / square_modulus;
|
||||
|
||||
inverted->real = number->real * multiplicand;
|
||||
inverted->imaginary = -number->imaginary * multiplicand;
|
||||
inverse->real = number->real * multiplicand;
|
||||
inverse->imaginary = -number->imaginary * multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ================ Get Product ================= //
|
||||
|
||||
inline void bgc_complex_get_product_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, BgcComplexFP32* result)
|
||||
inline int bgc_complex_invert_fp32(BgcComplexFP32* number)
|
||||
{
|
||||
const float real = number1->real * number2->real - number1->imaginary * number2->imaginary;
|
||||
const float imaginary = number1->real * number2->imaginary + number1->imaginary * number2->real;
|
||||
|
||||
result->real = real;
|
||||
result->imaginary = imaginary;
|
||||
return bgc_complex_get_inverse_fp32(number, number);
|
||||
}
|
||||
|
||||
inline void bgc_complex_get_product_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, BgcComplexFP64* result)
|
||||
inline int bgc_complex_invert_fp64(BgcComplexFP64* number)
|
||||
{
|
||||
const double real = number1->real * number2->real - number1->imaginary * number2->imaginary;
|
||||
const double imaginary = number1->real * number2->imaginary + number1->imaginary * number2->real;
|
||||
|
||||
result->real = real;
|
||||
result->imaginary = imaginary;
|
||||
}
|
||||
|
||||
// ================= Get Ratio ================== //
|
||||
|
||||
inline int bgc_complex_get_ratio_fp32(const BgcComplexFP32* divident, const BgcComplexFP32* divisor, BgcComplexFP32* quotient)
|
||||
{
|
||||
const float square_modulus = bgc_complex_get_square_modulus_fp32(divisor);
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float real = divident->real * divisor->real + divident->imaginary * divisor->imaginary;
|
||||
const float imaginary = divident->imaginary * divisor->real - divident->real * divisor->imaginary;
|
||||
|
||||
const float multiplier = 1.0f / square_modulus;
|
||||
|
||||
quotient->real = real * multiplier;
|
||||
quotient->imaginary = imaginary * multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_complex_get_ratio_fp64(const BgcComplexFP64* divident, const BgcComplexFP64* divisor, BgcComplexFP64* quotient)
|
||||
{
|
||||
const double square_modulus = bgc_complex_get_square_modulus_fp64(divisor);
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double real = divident->real * divisor->real + divident->imaginary * divisor->imaginary;
|
||||
const double imaginary = divident->imaginary * divisor->real - divident->real * divisor->imaginary;
|
||||
|
||||
const double multiplier = 1.0 / square_modulus;
|
||||
|
||||
quotient->real = real * multiplier;
|
||||
quotient->imaginary = imaginary * multiplier;
|
||||
|
||||
return 1;
|
||||
return bgc_complex_get_inverse_fp64(number, number);
|
||||
}
|
||||
|
||||
// =============== Get Exponation =============== //
|
||||
|
|
@ -358,29 +374,35 @@ inline void bgc_complex_subtract_fp64(const BgcComplexFP64* minuend, const BgcCo
|
|||
difference->imaginary = minuend->imaginary - subtrahend->imaginary;
|
||||
}
|
||||
|
||||
// ============== Subtract scaled =============== //
|
||||
|
||||
inline void bgc_complex_subtract_scaled_fp32(const BgcComplexFP32* basic_number, const BgcComplexFP32* scalable_number, const float scale, BgcComplexFP32* difference)
|
||||
{
|
||||
difference->real = basic_number->real - scalable_number->real * scale;
|
||||
difference->imaginary = basic_number->imaginary - scalable_number->imaginary * scale;
|
||||
}
|
||||
|
||||
inline void bgc_complex_subtract_scaled_fp64(const BgcComplexFP64* basic_number, const BgcComplexFP64* scalable_number, const double scale, BgcComplexFP64* difference)
|
||||
{
|
||||
difference->real = basic_number->real - scalable_number->real * scale;
|
||||
difference->imaginary = basic_number->imaginary - scalable_number->imaginary * scale;
|
||||
}
|
||||
|
||||
// ================== Multiply ================== //
|
||||
|
||||
inline void bgc_complex_multiply_fp32(const BgcComplexFP32* multiplicand, const float multiplier, BgcComplexFP32* product)
|
||||
inline void bgc_complex_multiply_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, BgcComplexFP32* product)
|
||||
{
|
||||
const float real = number1->real * number2->real - number1->imaginary * number2->imaginary;
|
||||
const float imaginary = number1->real * number2->imaginary + number1->imaginary * number2->real;
|
||||
|
||||
product->real = real;
|
||||
product->imaginary = imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_multiply_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, BgcComplexFP64* product)
|
||||
{
|
||||
const double real = number1->real * number2->real - number1->imaginary * number2->imaginary;
|
||||
const double imaginary = number1->real * number2->imaginary + number1->imaginary * number2->real;
|
||||
|
||||
product->real = real;
|
||||
product->imaginary = imaginary;
|
||||
}
|
||||
|
||||
// ============= Multiply By Number ============= //
|
||||
|
||||
inline void bgc_complex_multiply_by_number_fp32(const BgcComplexFP32* multiplicand, const float multiplier, BgcComplexFP32* product)
|
||||
{
|
||||
product->real = multiplicand->real * multiplier;
|
||||
product->imaginary = multiplicand->imaginary * multiplier;
|
||||
}
|
||||
|
||||
inline void bgc_complex_multiply_fp64(const BgcComplexFP64* multiplicand, const double multiplier, BgcComplexFP64* product)
|
||||
inline void bgc_complex_multiply_by_number_fp64(const BgcComplexFP64* multiplicand, const double multiplier, BgcComplexFP64* product)
|
||||
{
|
||||
product->real = multiplicand->real * multiplier;
|
||||
product->imaginary = multiplicand->imaginary * multiplier;
|
||||
|
|
@ -388,14 +410,54 @@ inline void bgc_complex_multiply_fp64(const BgcComplexFP64* multiplicand, const
|
|||
|
||||
// =================== Divide =================== //
|
||||
|
||||
inline void bgc_complex_divide_fp32(const BgcComplexFP32* dividend, const float divisor, BgcComplexFP32* quotient)
|
||||
inline int bgc_complex_devide_fp32(const BgcComplexFP32* divident, const BgcComplexFP32* divisor, BgcComplexFP32* quotient)
|
||||
{
|
||||
bgc_complex_multiply_fp32(dividend, 1.0f / divisor, quotient);
|
||||
const float square_modulus = bgc_complex_get_square_modulus_fp32(divisor);
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float real = divident->real * divisor->real + divident->imaginary * divisor->imaginary;
|
||||
const float imaginary = divident->imaginary * divisor->real - divident->real * divisor->imaginary;
|
||||
|
||||
const float multiplier = 1.0f / square_modulus;
|
||||
|
||||
quotient->real = real * multiplier;
|
||||
quotient->imaginary = imaginary * multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline void bgc_complex_divide_fp64(const BgcComplexFP64* dividend, const double divisor, BgcComplexFP64* quotient)
|
||||
inline int bgc_complex_devide_fp64(const BgcComplexFP64* divident, const BgcComplexFP64* divisor, BgcComplexFP64* quotient)
|
||||
{
|
||||
bgc_complex_multiply_fp64(dividend, 1.0 / divisor, quotient);
|
||||
const double square_modulus = bgc_complex_get_square_modulus_fp64(divisor);
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double real = divident->real * divisor->real + divident->imaginary * divisor->imaginary;
|
||||
const double imaginary = divident->imaginary * divisor->real - divident->real * divisor->imaginary;
|
||||
|
||||
const double multiplier = 1.0 / square_modulus;
|
||||
|
||||
quotient->real = real * multiplier;
|
||||
quotient->imaginary = imaginary * multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ============== Divide By Number ============== //
|
||||
|
||||
inline void bgc_complex_divide_by_number_fp32(const BgcComplexFP32* dividend, const float divisor, BgcComplexFP32* quotient)
|
||||
{
|
||||
bgc_complex_multiply_by_number_fp32(dividend, 1.0f / divisor, quotient);
|
||||
}
|
||||
|
||||
inline void bgc_complex_divide_by_number_fp64(const BgcComplexFP64* dividend, const double divisor, BgcComplexFP64* quotient)
|
||||
{
|
||||
bgc_complex_multiply_by_number_fp64(dividend, 1.0 / divisor, quotient);
|
||||
}
|
||||
|
||||
// ================== Average2 ================== //
|
||||
|
|
@ -428,7 +490,7 @@ inline void bgc_complex_get_mean_of_three_fp64(const BgcComplexFP64* number1, co
|
|||
|
||||
// =================== Linear =================== //
|
||||
|
||||
inline void bgc_complex_interpolate_linearly_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, const float phase, BgcComplexFP32* interpolation)
|
||||
inline void bgc_complex_interpolate_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, const float phase, BgcComplexFP32* interpolation)
|
||||
{
|
||||
const float counterphase = 1.0f - phase;
|
||||
|
||||
|
|
@ -436,7 +498,7 @@ inline void bgc_complex_interpolate_linearly_fp32(const BgcComplexFP32* number1,
|
|||
interpolation->imaginary = number1->imaginary * counterphase + number2->imaginary * phase;
|
||||
}
|
||||
|
||||
inline void bgc_complex_interpolate_linearly_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, const double phase, BgcComplexFP64* interpolation)
|
||||
inline void bgc_complex_interpolate_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, const double phase, BgcComplexFP64* interpolation)
|
||||
{
|
||||
const double counterphase = 1.0 - phase;
|
||||
|
||||
|
|
@ -444,54 +506,6 @@ inline void bgc_complex_interpolate_linearly_fp64(const BgcComplexFP64* number1,
|
|||
interpolation->imaginary = number1->imaginary * counterphase + number2->imaginary * phase;
|
||||
}
|
||||
|
||||
// ================== Minimal =================== //
|
||||
|
||||
inline void bgc_complex_minimize_fp32(const BgcComplexFP32* number, BgcComplexFP32* minimal)
|
||||
{
|
||||
if (number->real < minimal->real) {
|
||||
minimal->real = number->real;
|
||||
}
|
||||
|
||||
if (number->imaginary < minimal->imaginary) {
|
||||
minimal->imaginary = number->imaginary;
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_complex_minimize_fp64(const BgcComplexFP64* number, BgcComplexFP64* minimal)
|
||||
{
|
||||
if (number->real < minimal->real) {
|
||||
minimal->real = number->real;
|
||||
}
|
||||
|
||||
if (number->imaginary < minimal->imaginary) {
|
||||
minimal->imaginary = number->imaginary;
|
||||
}
|
||||
}
|
||||
|
||||
// ================== Maximal =================== //
|
||||
|
||||
inline void bgc_complex_maximize_fp32(const BgcComplexFP32* number, BgcComplexFP32* maximal)
|
||||
{
|
||||
if (number->real > maximal->real) {
|
||||
maximal->real = number->real;
|
||||
}
|
||||
|
||||
if (number->imaginary > maximal->imaginary) {
|
||||
maximal->imaginary = number->imaginary;
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_complex_maximize_fp64(const BgcComplexFP64* number, BgcComplexFP64* maximal)
|
||||
{
|
||||
if (number->real > maximal->real) {
|
||||
maximal->real = number->real;
|
||||
}
|
||||
|
||||
if (number->imaginary > maximal->imaginary) {
|
||||
maximal->imaginary = number->imaginary;
|
||||
}
|
||||
}
|
||||
|
||||
// ================== Are Close ================= //
|
||||
|
||||
inline int bgc_complex_are_close_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2)
|
||||
|
|
@ -525,7 +539,7 @@ inline int bgc_complex_are_close_fp64(const BgcComplexFP64* number1, const BgcCo
|
|||
return square_distance <= BGC_SQUARE_EPSYLON_FP64;
|
||||
}
|
||||
|
||||
return square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus1 && square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus2;
|
||||
return square_distance <= BGC_SQUARE_EPSYLON_FP64 * square_modulus1 && square_distance <= BGC_SQUARE_EPSYLON_FP64 * square_modulus2;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -25,8 +25,17 @@ extern inline void bgc_cotes_number_swap_fp64(BgcCotesNumberFP64* number1, BgcCo
|
|||
extern inline void bgc_cotes_number_convert_fp64_to_fp32(const BgcCotesNumberFP64* source, BgcCotesNumberFP32* destination);
|
||||
extern inline void bgc_cotes_number_convert_fp32_to_fp64(const BgcCotesNumberFP32* source, BgcCotesNumberFP64* destination);
|
||||
|
||||
extern inline void bgc_cotes_number_invert_fp32(const BgcCotesNumberFP32* number, BgcCotesNumberFP32* inverted);
|
||||
extern inline void bgc_cotes_number_invert_fp64(const BgcCotesNumberFP64* number, BgcCotesNumberFP64* inverted);
|
||||
extern inline void bgc_cotes_number_make_opposite_fp32(BgcCotesNumberFP32* number);
|
||||
extern inline void bgc_cotes_number_make_opposite_fp64(BgcCotesNumberFP64* number);
|
||||
|
||||
extern inline void bgc_cotes_number_get_opposite_fp32(const BgcCotesNumberFP32* number, BgcCotesNumberFP32* opposite);
|
||||
extern inline void bgc_cotes_number_get_opposite_fp64(const BgcCotesNumberFP64* number, BgcCotesNumberFP64* opposite);
|
||||
|
||||
extern inline void bgc_cotes_number_invert_fp32(BgcCotesNumberFP32* number);
|
||||
extern inline void bgc_cotes_number_invert_fp64(BgcCotesNumberFP64* number);
|
||||
|
||||
extern inline void bgc_cotes_number_get_inverse_fp32(const BgcCotesNumberFP32* number, BgcCotesNumberFP32* inverse);
|
||||
extern inline void bgc_cotes_number_get_inverse_fp64(const BgcCotesNumberFP64* number, BgcCotesNumberFP64* inverse);
|
||||
|
||||
extern inline void bgc_cotes_number_get_exponation_fp32(const BgcCotesNumberFP32* base, const float exponent, BgcCotesNumberFP32* power);
|
||||
extern inline void bgc_cotes_number_get_exponation_fp64(const BgcCotesNumberFP64* base, const double exponent, BgcCotesNumberFP64* power);
|
||||
|
|
@ -52,34 +61,34 @@ extern inline void bgc_cotes_number_turn_vector_back_fp64(const BgcCotesNumberFP
|
|||
extern inline int bgc_cotes_number_are_close_fp32(const BgcCotesNumberFP32* number1, const BgcCotesNumberFP32* number2);
|
||||
extern inline int bgc_cotes_number_are_close_fp64(const BgcCotesNumberFP64* number1, const BgcCotesNumberFP64* number2);
|
||||
|
||||
void _bgc_cotes_number_normalize_fp32(const float square_modulus, _BgcTwinCotesNumberFP32* twin)
|
||||
void _bgc_cotes_number_normalize_fp32(const float square_modulus, BgcCotesNumberFP32* number)
|
||||
{
|
||||
// (square_modulus != square_modulus) is true when square_modulus is NaN
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
twin->cos = 1.0f;
|
||||
twin->sin = 0.0f;
|
||||
number->_cos = 1.0f;
|
||||
number->_sin = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
const float multiplier = sqrtf(1.0f / square_modulus);
|
||||
|
||||
twin->cos *= multiplier;
|
||||
twin->sin *= multiplier;
|
||||
number->_cos *= multiplier;
|
||||
number->_sin *= multiplier;
|
||||
}
|
||||
|
||||
void _bgc_cotes_number_normalize_fp64(const double square_modulus, _BgcTwinCotesNumberFP64* twin)
|
||||
void _bgc_cotes_number_normalize_fp64(const double square_modulus, BgcCotesNumberFP64* number)
|
||||
{
|
||||
// (square_modulus != square_modulus) is true when square_modulus is NaN
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
twin->cos = 1.0;
|
||||
twin->sin = 0.0;
|
||||
number->_cos = 1.0;
|
||||
number->_sin = 0.0;
|
||||
return;
|
||||
}
|
||||
|
||||
const double multiplier = sqrt(1.0 / square_modulus);
|
||||
|
||||
twin->cos *= multiplier;
|
||||
twin->sin *= multiplier;
|
||||
number->_cos *= multiplier;
|
||||
number->_sin *= multiplier;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,24 +12,14 @@
|
|||
|
||||
typedef struct
|
||||
{
|
||||
const float cos, sin;
|
||||
float _cos, _sin;
|
||||
} BgcCotesNumberFP32;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const double cos, sin;
|
||||
double _cos, _sin;
|
||||
} BgcCotesNumberFP64;
|
||||
|
||||
// ================= Dark Twins ================= //
|
||||
|
||||
typedef struct {
|
||||
float cos, sin;
|
||||
} _BgcTwinCotesNumberFP32;
|
||||
|
||||
typedef struct {
|
||||
double cos, sin;
|
||||
} _BgcTwinCotesNumberFP64;
|
||||
|
||||
// ================= Constants ================== //
|
||||
|
||||
extern const BgcCotesNumberFP32 BGC_IDLE_COTES_NUMBER_FP32;
|
||||
|
|
@ -39,37 +29,31 @@ extern const BgcCotesNumberFP64 BGC_IDLE_COTES_NUMBER_FP64;
|
|||
|
||||
inline void bgc_cotes_number_reset_fp32(BgcCotesNumberFP32* number)
|
||||
{
|
||||
_BgcTwinCotesNumberFP32* twin = (_BgcTwinCotesNumberFP32*)number;
|
||||
|
||||
twin->cos = 1.0f;
|
||||
twin->sin = 0.0f;
|
||||
number->_cos = 1.0f;
|
||||
number->_sin = 0.0f;
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_reset_fp64(BgcCotesNumberFP64* number)
|
||||
{
|
||||
_BgcTwinCotesNumberFP64* twin = (_BgcTwinCotesNumberFP64*)number;
|
||||
|
||||
twin->cos = 1.0;
|
||||
twin->sin = 0.0;
|
||||
number->_cos = 1.0;
|
||||
number->_sin = 0.0;
|
||||
}
|
||||
|
||||
// ==================== Set ===================== //
|
||||
|
||||
void _bgc_cotes_number_normalize_fp32(const float square_modulus, _BgcTwinCotesNumberFP32* twin);
|
||||
void _bgc_cotes_number_normalize_fp32(const float square_modulus, BgcCotesNumberFP32* twin);
|
||||
|
||||
void _bgc_cotes_number_normalize_fp64(const double square_modulus, _BgcTwinCotesNumberFP64* twin);
|
||||
void _bgc_cotes_number_normalize_fp64(const double square_modulus, BgcCotesNumberFP64* twin);
|
||||
|
||||
inline void bgc_cotes_number_set_values_fp32(const float x1, const float x2, BgcCotesNumberFP32* number)
|
||||
{
|
||||
const float square_modulus = x1 * x1 + x2 * x2;
|
||||
|
||||
_BgcTwinCotesNumberFP32* twin = (_BgcTwinCotesNumberFP32*)number;
|
||||
|
||||
twin->cos = x1;
|
||||
twin->sin = x2;
|
||||
number->_cos = x1;
|
||||
number->_sin = x2;
|
||||
|
||||
if (!bgc_is_sqare_unit_fp32(square_modulus)) {
|
||||
_bgc_cotes_number_normalize_fp32(square_modulus, twin);
|
||||
_bgc_cotes_number_normalize_fp32(square_modulus, number);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -77,13 +61,11 @@ inline void bgc_cotes_number_set_values_fp64(const double x1, const double x2, B
|
|||
{
|
||||
const double square_modulus = x1 * x1 + x2 * x2;
|
||||
|
||||
_BgcTwinCotesNumberFP64* twin = (_BgcTwinCotesNumberFP64*)number;
|
||||
|
||||
twin->cos = x1;
|
||||
twin->sin = x2;
|
||||
number->_cos = x1;
|
||||
number->_sin = x2;
|
||||
|
||||
if (!bgc_is_sqare_unit_fp64(square_modulus)) {
|
||||
_bgc_cotes_number_normalize_fp64(square_modulus, twin);
|
||||
_bgc_cotes_number_normalize_fp64(square_modulus, number);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,168 +75,148 @@ inline void bgc_cotes_number_set_turn_fp32(const float angle, const BgcAngleUnit
|
|||
{
|
||||
const float radians = bgc_angle_to_radians_fp32(angle, unit);
|
||||
|
||||
_BgcTwinCotesNumberFP32* twin = (_BgcTwinCotesNumberFP32*)number;
|
||||
|
||||
twin->cos = cosf(radians);
|
||||
twin->sin = sinf(radians);
|
||||
number->_cos = cosf(radians);
|
||||
number->_sin = sinf(radians);
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_set_turn_fp64(const double angle, const BgcAngleUnitEnum unit, BgcCotesNumberFP64* number)
|
||||
{
|
||||
const double radians = bgc_angle_to_radians_fp64(angle, unit);
|
||||
|
||||
_BgcTwinCotesNumberFP64* twin = (_BgcTwinCotesNumberFP64*)number;
|
||||
|
||||
twin->cos = cos(radians);
|
||||
twin->sin = sin(radians);
|
||||
number->_cos = cos(radians);
|
||||
number->_sin = sin(radians);
|
||||
}
|
||||
|
||||
// =================== Angle =================== //
|
||||
|
||||
inline float bgc_cotes_number_get_angle_fp32(const BgcCotesNumberFP32* number, const BgcAngleUnitEnum unit)
|
||||
{
|
||||
if (number->cos >= 1.0f - BGC_EPSYLON_FP32) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
if (number->cos <= -1.0f + BGC_EPSYLON_FP32) {
|
||||
return bgc_angle_get_half_circle_fp32(unit);
|
||||
}
|
||||
|
||||
if (number->sin >= 1.0f - BGC_EPSYLON_FP32) {
|
||||
return bgc_angle_get_quater_circle_fp32(unit);
|
||||
}
|
||||
|
||||
if (number->sin <= -1.0f + BGC_EPSYLON_FP32) {
|
||||
return 0.75f * bgc_angle_get_full_circle_fp32(unit);
|
||||
}
|
||||
|
||||
return bgc_radians_to_units_fp32(atan2f(number->sin, number->cos), unit);
|
||||
return bgc_radians_to_units_fp32(atan2f(number->_sin, number->_cos), unit);
|
||||
}
|
||||
|
||||
inline double bgc_cotes_number_get_angle_fp64(const BgcCotesNumberFP64* number, const BgcAngleUnitEnum unit)
|
||||
{
|
||||
if (number->cos >= 1.0 - BGC_EPSYLON_FP64) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
if (number->cos <= -1.0 + BGC_EPSYLON_FP64) {
|
||||
return bgc_angle_get_half_circle_fp64(unit);
|
||||
}
|
||||
|
||||
if (number->sin >= 1.0 - BGC_EPSYLON_FP64) {
|
||||
return bgc_angle_get_quater_circle_fp64(unit);
|
||||
}
|
||||
|
||||
if (number->sin <= -1.0 + BGC_EPSYLON_FP64) {
|
||||
return 0.75 * bgc_angle_get_full_circle_fp64(unit);
|
||||
}
|
||||
|
||||
return bgc_radians_to_units_fp64(atan2(number->sin, number->cos), unit);
|
||||
return bgc_radians_to_units_fp64(atan2(number->_sin, number->_cos), unit);
|
||||
}
|
||||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
inline void bgc_cotes_number_copy_fp32(const BgcCotesNumberFP32* source, BgcCotesNumberFP32* destination)
|
||||
{
|
||||
_BgcTwinCotesNumberFP32* twin = (_BgcTwinCotesNumberFP32*)destination;
|
||||
|
||||
twin->cos = source->cos;
|
||||
twin->sin = source->sin;
|
||||
destination->_cos = source->_cos;
|
||||
destination->_sin = source->_sin;
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_copy_fp64(const BgcCotesNumberFP64* source, BgcCotesNumberFP64* destination)
|
||||
{
|
||||
_BgcTwinCotesNumberFP64* twin = (_BgcTwinCotesNumberFP64*)destination;
|
||||
|
||||
twin->cos = source->cos;
|
||||
twin->sin = source->sin;
|
||||
destination->_cos = source->_cos;
|
||||
destination->_sin = source->_sin;
|
||||
}
|
||||
|
||||
// ==================== Swap ==================== //
|
||||
|
||||
inline void bgc_cotes_number_swap_fp32(BgcCotesNumberFP32* number1, BgcCotesNumberFP32* number2)
|
||||
{
|
||||
const float cos = number1->cos;
|
||||
const float sin = number1->sin;
|
||||
const float cos = number1->_cos;
|
||||
const float sin = number1->_sin;
|
||||
|
||||
_BgcTwinCotesNumberFP32* twin1 = (_BgcTwinCotesNumberFP32*)number1;
|
||||
number1->_cos = number2->_cos;
|
||||
number1->_sin = number2->_sin;
|
||||
|
||||
twin1->cos = number2->cos;
|
||||
twin1->sin = number2->sin;
|
||||
|
||||
_BgcTwinCotesNumberFP32* twin2 = (_BgcTwinCotesNumberFP32*)number2;
|
||||
|
||||
twin2->cos = cos;
|
||||
twin2->sin = sin;
|
||||
number2->_cos = cos;
|
||||
number2->_sin = sin;
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_swap_fp64(BgcCotesNumberFP64* number1, BgcCotesNumberFP64* number2)
|
||||
{
|
||||
const double cos = number1->cos;
|
||||
const double sin = number1->sin;
|
||||
const double cos = number1->_cos;
|
||||
const double sin = number1->_sin;
|
||||
|
||||
_BgcTwinCotesNumberFP64* twin1 = (_BgcTwinCotesNumberFP64*)number1;
|
||||
number1->_cos = number2->_cos;
|
||||
number1->_sin = number2->_sin;
|
||||
|
||||
twin1->cos = number2->cos;
|
||||
twin1->sin = number2->sin;
|
||||
|
||||
_BgcTwinCotesNumberFP64* twin2 = (_BgcTwinCotesNumberFP64*)number2;
|
||||
|
||||
twin2->cos = cos;
|
||||
twin2->sin = sin;
|
||||
number2->_cos = cos;
|
||||
number2->_sin = sin;
|
||||
}
|
||||
|
||||
// ================== Convert =================== //
|
||||
|
||||
inline void bgc_cotes_number_convert_fp64_to_fp32(const BgcCotesNumberFP64* source, BgcCotesNumberFP32* destination)
|
||||
{
|
||||
bgc_cotes_number_set_values_fp32((float)source->cos, (float)source->sin, destination);
|
||||
bgc_cotes_number_set_values_fp32((float)source->_cos, (float)source->_sin, destination);
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_convert_fp32_to_fp64(const BgcCotesNumberFP32* source, BgcCotesNumberFP64* destination)
|
||||
{
|
||||
bgc_cotes_number_set_values_fp64((double)source->cos, (double)source->sin, destination);
|
||||
bgc_cotes_number_set_values_fp64((double)source->_cos, (double)source->_sin, destination);
|
||||
}
|
||||
|
||||
// ================== Negative ================== //
|
||||
|
||||
inline void bgc_cotes_number_make_opposite_fp32(BgcCotesNumberFP32* number)
|
||||
{
|
||||
number->_cos = -number->_cos;
|
||||
number->_sin = -number->_sin;
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_make_opposite_fp64(BgcCotesNumberFP64* number)
|
||||
{
|
||||
number->_cos = -number->_cos;
|
||||
number->_sin = -number->_sin;
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_get_opposite_fp32(const BgcCotesNumberFP32* number, BgcCotesNumberFP32* opposite)
|
||||
{
|
||||
opposite->_cos = -number->_cos;
|
||||
opposite->_sin = -number->_sin;
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_get_opposite_fp64(const BgcCotesNumberFP64* number, BgcCotesNumberFP64* opposite)
|
||||
{
|
||||
opposite->_cos = -number->_cos;
|
||||
opposite->_sin = -number->_sin;
|
||||
}
|
||||
|
||||
// =================== Invert =================== //
|
||||
|
||||
inline void bgc_cotes_number_invert_fp32(const BgcCotesNumberFP32* number, BgcCotesNumberFP32* inverted)
|
||||
inline void bgc_cotes_number_invert_fp32(BgcCotesNumberFP32* number)
|
||||
{
|
||||
_BgcTwinCotesNumberFP32* twin = (_BgcTwinCotesNumberFP32*)inverted;
|
||||
|
||||
twin->cos = number->cos;
|
||||
twin->sin = -number->sin;
|
||||
number->_sin = -number->_sin;
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_invert_fp64(const BgcCotesNumberFP64* number, BgcCotesNumberFP64* inverted)
|
||||
inline void bgc_cotes_number_invert_fp64(BgcCotesNumberFP64* number)
|
||||
{
|
||||
_BgcTwinCotesNumberFP64* twin = (_BgcTwinCotesNumberFP64*)inverted;
|
||||
number->_sin = -number->_sin;
|
||||
}
|
||||
|
||||
twin->cos = number->cos;
|
||||
twin->sin = -number->sin;
|
||||
inline void bgc_cotes_number_get_inverse_fp32(const BgcCotesNumberFP32* number, BgcCotesNumberFP32* inverse)
|
||||
{
|
||||
inverse->_cos = number->_cos;
|
||||
inverse->_sin = -number->_sin;
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_get_inverse_fp64(const BgcCotesNumberFP64* number, BgcCotesNumberFP64* inverse)
|
||||
{
|
||||
inverse->_cos = number->_cos;
|
||||
inverse->_sin = -number->_sin;
|
||||
}
|
||||
|
||||
// ================= Exponation ================= //
|
||||
|
||||
inline void bgc_cotes_number_get_exponation_fp32(const BgcCotesNumberFP32* base, const float exponent, BgcCotesNumberFP32* power)
|
||||
{
|
||||
const float power_angle = exponent * atan2f(base->sin, base->cos);
|
||||
const float power_angle = exponent * atan2f(base->_sin, base->_cos);
|
||||
|
||||
_BgcTwinCotesNumberFP32* twin = (_BgcTwinCotesNumberFP32*)power;
|
||||
|
||||
twin->cos = cosf(power_angle);
|
||||
twin->sin = sinf(power_angle);
|
||||
power->_cos = cosf(power_angle);
|
||||
power->_sin = sinf(power_angle);
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_get_exponation_fp64(const BgcCotesNumberFP64* base, const double exponent, BgcCotesNumberFP64* power)
|
||||
{
|
||||
const double power_angle = exponent * atan2(base->sin, base->cos);
|
||||
const double power_angle = exponent * atan2(base->_sin, base->_cos);
|
||||
|
||||
_BgcTwinCotesNumberFP64* twin = (_BgcTwinCotesNumberFP64*)power;
|
||||
|
||||
twin->cos = cos(power_angle);
|
||||
twin->sin = sin(power_angle);
|
||||
power->_cos = cos(power_angle);
|
||||
power->_sin = sin(power_angle);
|
||||
}
|
||||
|
||||
// ================ Combination ================= //
|
||||
|
|
@ -262,8 +224,8 @@ inline void bgc_cotes_number_get_exponation_fp64(const BgcCotesNumberFP64* base,
|
|||
inline void bgc_cotes_number_combine_fp32(const BgcCotesNumberFP32* number1, const BgcCotesNumberFP32* number2, BgcCotesNumberFP32* result)
|
||||
{
|
||||
bgc_cotes_number_set_values_fp32(
|
||||
number1->cos * number2->cos - number1->sin * number2->sin,
|
||||
number1->cos * number2->sin + number1->sin * number2->cos,
|
||||
number1->_cos * number2->_cos - number1->_sin * number2->_sin,
|
||||
number1->_cos * number2->_sin + number1->_sin * number2->_cos,
|
||||
result
|
||||
);
|
||||
}
|
||||
|
|
@ -271,8 +233,8 @@ inline void bgc_cotes_number_combine_fp32(const BgcCotesNumberFP32* number1, con
|
|||
inline void bgc_cotes_number_combine_fp64(const BgcCotesNumberFP64* number1, const BgcCotesNumberFP64* number2, BgcCotesNumberFP64* result)
|
||||
{
|
||||
bgc_cotes_number_set_values_fp64(
|
||||
number1->cos * number2->cos - number1->sin * number2->sin,
|
||||
number1->cos * number2->sin + number1->sin * number2->cos,
|
||||
number1->_cos * number2->_cos - number1->_sin * number2->_sin,
|
||||
number1->_cos * number2->_sin + number1->_sin * number2->_cos,
|
||||
result
|
||||
);
|
||||
}
|
||||
|
|
@ -282,8 +244,8 @@ inline void bgc_cotes_number_combine_fp64(const BgcCotesNumberFP64* number1, con
|
|||
inline void bgc_cotes_number_exclude_fp32(const BgcCotesNumberFP32* base, const BgcCotesNumberFP32* excludant, BgcCotesNumberFP32* difference)
|
||||
{
|
||||
bgc_cotes_number_set_values_fp32(
|
||||
base->cos * excludant->cos + base->sin * excludant->sin,
|
||||
base->sin * excludant->cos - base->cos * excludant->sin,
|
||||
base->_cos * excludant->_cos + base->_sin * excludant->_sin,
|
||||
base->_sin * excludant->_cos - base->_cos * excludant->_sin,
|
||||
difference
|
||||
);
|
||||
}
|
||||
|
|
@ -291,8 +253,8 @@ inline void bgc_cotes_number_exclude_fp32(const BgcCotesNumberFP32* base, const
|
|||
inline void bgc_cotes_number_exclude_fp64(const BgcCotesNumberFP64* base, const BgcCotesNumberFP64* excludant, BgcCotesNumberFP64* difference)
|
||||
{
|
||||
bgc_cotes_number_set_values_fp64(
|
||||
base->cos * excludant->cos + base->sin * excludant->sin,
|
||||
base->sin * excludant->cos - base->cos * excludant->sin,
|
||||
base->_cos * excludant->_cos + base->_sin * excludant->_sin,
|
||||
base->_sin * excludant->_cos - base->_cos * excludant->_sin,
|
||||
difference
|
||||
);
|
||||
}
|
||||
|
|
@ -301,44 +263,44 @@ inline void bgc_cotes_number_exclude_fp64(const BgcCotesNumberFP64* base, const
|
|||
|
||||
inline void bgc_cotes_number_get_rotation_matrix_fp32(const BgcCotesNumberFP32* number, BgcMatrix2x2FP32* matrix)
|
||||
{
|
||||
matrix->r1c1 = number->cos;
|
||||
matrix->r1c2 = -number->sin;
|
||||
matrix->r2c1 = number->sin;
|
||||
matrix->r2c2 = number->cos;
|
||||
matrix->r1c1 = number->_cos;
|
||||
matrix->r1c2 = -number->_sin;
|
||||
matrix->r2c1 = number->_sin;
|
||||
matrix->r2c2 = number->_cos;
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_get_rotation_matrix_fp64(const BgcCotesNumberFP64* number, BgcMatrix2x2FP64* matrix)
|
||||
{
|
||||
matrix->r1c1 = number->cos;
|
||||
matrix->r1c2 = -number->sin;
|
||||
matrix->r2c1 = number->sin;
|
||||
matrix->r2c2 = number->cos;
|
||||
matrix->r1c1 = number->_cos;
|
||||
matrix->r1c2 = -number->_sin;
|
||||
matrix->r2c1 = number->_sin;
|
||||
matrix->r2c2 = number->_cos;
|
||||
}
|
||||
|
||||
// ============== Reverse Matrix ================ //
|
||||
|
||||
inline void bgc_cotes_number_get_reverse_matrix_fp32(const BgcCotesNumberFP32* number, BgcMatrix2x2FP32* matrix)
|
||||
{
|
||||
matrix->r1c1 = number->cos;
|
||||
matrix->r1c2 = number->sin;
|
||||
matrix->r2c1 = -number->sin;
|
||||
matrix->r2c2 = number->cos;
|
||||
matrix->r1c1 = number->_cos;
|
||||
matrix->r1c2 = number->_sin;
|
||||
matrix->r2c1 = -number->_sin;
|
||||
matrix->r2c2 = number->_cos;
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_get_reverse_matrix_fp64(const BgcCotesNumberFP64* number, BgcMatrix2x2FP64* matrix)
|
||||
{
|
||||
matrix->r1c1 = number->cos;
|
||||
matrix->r1c2 = number->sin;
|
||||
matrix->r2c1 = -number->sin;
|
||||
matrix->r2c2 = number->cos;
|
||||
matrix->r1c1 = number->_cos;
|
||||
matrix->r1c2 = number->_sin;
|
||||
matrix->r2c1 = -number->_sin;
|
||||
matrix->r2c2 = number->_cos;
|
||||
}
|
||||
|
||||
// ================ Turn Vector ================= //
|
||||
|
||||
inline void bgc_cotes_number_turn_vector_fp32(const BgcCotesNumberFP32* number, const BgcVector2FP32* vector, BgcVector2FP32* result)
|
||||
{
|
||||
const float x1 = number->cos * vector->x1 - number->sin * vector->x2;
|
||||
const float x2 = number->sin * vector->x1 + number->cos * vector->x2;
|
||||
const float x1 = number->_cos * vector->x1 - number->_sin * vector->x2;
|
||||
const float x2 = number->_sin * vector->x1 + number->_cos * vector->x2;
|
||||
|
||||
result->x1 = x1;
|
||||
result->x2 = x2;
|
||||
|
|
@ -346,8 +308,8 @@ inline void bgc_cotes_number_turn_vector_fp32(const BgcCotesNumberFP32* number,
|
|||
|
||||
inline void bgc_cotes_number_turn_vector_fp64(const BgcCotesNumberFP64* number, const BgcVector2FP64* vector, BgcVector2FP64* result)
|
||||
{
|
||||
const double x1 = number->cos * vector->x1 - number->sin * vector->x2;
|
||||
const double x2 = number->sin * vector->x1 + number->cos * vector->x2;
|
||||
const double x1 = number->_cos * vector->x1 - number->_sin * vector->x2;
|
||||
const double x2 = number->_sin * vector->x1 + number->_cos * vector->x2;
|
||||
|
||||
result->x1 = x1;
|
||||
result->x2 = x2;
|
||||
|
|
@ -357,8 +319,8 @@ inline void bgc_cotes_number_turn_vector_fp64(const BgcCotesNumberFP64* number,
|
|||
|
||||
inline void bgc_cotes_number_turn_vector_back_fp32(const BgcCotesNumberFP32* number, const BgcVector2FP32* vector, BgcVector2FP32* result)
|
||||
{
|
||||
const float x1 = number->sin * vector->x2 + number->cos * vector->x1;
|
||||
const float x2 = number->cos * vector->x2 - number->sin * vector->x1;
|
||||
const float x1 = number->_sin * vector->x2 + number->_cos * vector->x1;
|
||||
const float x2 = number->_cos * vector->x2 - number->_sin * vector->x1;
|
||||
|
||||
result->x1 = x1;
|
||||
result->x2 = x2;
|
||||
|
|
@ -366,8 +328,8 @@ inline void bgc_cotes_number_turn_vector_back_fp32(const BgcCotesNumberFP32* num
|
|||
|
||||
inline void bgc_cotes_number_turn_vector_back_fp64(const BgcCotesNumberFP64* number, const BgcVector2FP64* vector, BgcVector2FP64* result)
|
||||
{
|
||||
const double x1 = number->sin * vector->x2 + number->cos * vector->x1;
|
||||
const double x2 = number->cos * vector->x2 - number->sin * vector->x1;
|
||||
const double x1 = number->_sin * vector->x2 + number->_cos * vector->x1;
|
||||
const double x2 = number->_cos * vector->x2 - number->_sin * vector->x1;
|
||||
|
||||
result->x1 = x1;
|
||||
result->x2 = x2;
|
||||
|
|
@ -377,16 +339,16 @@ inline void bgc_cotes_number_turn_vector_back_fp64(const BgcCotesNumberFP64* num
|
|||
|
||||
inline int bgc_cotes_number_are_close_fp32(const BgcCotesNumberFP32* number1, const BgcCotesNumberFP32* number2)
|
||||
{
|
||||
const float d_cos = number1->cos - number2->cos;
|
||||
const float d_sin = number1->sin - number2->sin;
|
||||
const float d_cos = number1->_cos - number2->_cos;
|
||||
const float d_sin = number1->_sin - number2->_sin;
|
||||
|
||||
return d_cos * d_cos + d_sin * d_sin <= BGC_SQUARE_EPSYLON_FP32;
|
||||
}
|
||||
|
||||
inline int bgc_cotes_number_are_close_fp64(const BgcCotesNumberFP64* number1, const BgcCotesNumberFP64* number2)
|
||||
{
|
||||
const double d_cos = number1->cos - number2->cos;
|
||||
const double d_sin = number1->sin - number2->sin;
|
||||
const double d_cos = number1->_cos - number2->_cos;
|
||||
const double d_sin = number1->_sin - number2->_sin;
|
||||
|
||||
return d_cos * d_cos + d_sin * d_sin <= BGC_SQUARE_EPSYLON_FP64;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -274,22 +274,6 @@ inline int bgc_matrix3x3_is_singular_fp64(const BgcMatrix3x3FP64* matrix)
|
|||
|
||||
// ================ Is Rotation ================= //
|
||||
|
||||
inline int bgc_matrix3x3_is_rotation_fp32(const BgcMatrix3x3FP32* matrix)
|
||||
{
|
||||
if (!bgc_is_unit_fp32(bgc_matrix3x3_get_determinant_fp32(matrix))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
BgcMatrix3x3FP32 transposed, product;
|
||||
|
||||
bgc_matrix3x3_transpose_fp32(matrix, &transposed);
|
||||
bgc_matrix_product_3x3_at_3x3_fp32(matrix, &transposed, &product);
|
||||
|
||||
return bgc_is_unit_fp32(product.r1c1) && bgc_is_zero_fp32(product.r1c2) && bgc_is_zero_fp32(product.r1c3)
|
||||
&& bgc_is_zero_fp32(product.r2c1) && bgc_is_unit_fp32(product.r2c2) && bgc_is_zero_fp32(product.r2c3)
|
||||
&& bgc_is_zero_fp32(product.r3c1) && bgc_is_zero_fp32(product.r3c2) && bgc_is_unit_fp32(product.r3c3);
|
||||
}
|
||||
|
||||
inline int bgc_matrix3x3_is_rotation_fp32a(const BgcMatrix3x3FP32* matrix)
|
||||
{
|
||||
if (!bgc_is_unit_fp32(bgc_matrix3x3_get_determinant_fp32(matrix))) {
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
extern inline void bgc_quaternion_reset_fp32(BgcQuaternionFP32* quaternion);
|
||||
extern inline void bgc_quaternion_reset_fp64(BgcQuaternionFP64* quaternion);
|
||||
|
||||
extern inline void bgc_quaternion_set_to_identity_fp32(BgcQuaternionFP32* quaternion);
|
||||
extern inline void bgc_quaternion_set_to_identity_fp64(BgcQuaternionFP64* quaternion);
|
||||
extern inline void bgc_quaternion_make_unit_fp32(BgcQuaternionFP32* quaternion);
|
||||
extern inline void bgc_quaternion_make_unit_fp64(BgcQuaternionFP64* quaternion);
|
||||
|
||||
extern inline void bgc_quaternion_set_values_fp32(const float s0, const float x1, const float x2, const float x3, BgcQuaternionFP32* quaternion);
|
||||
extern inline void bgc_quaternion_set_values_fp64(const double s0, const double x1, const double x2, const double x3, BgcQuaternionFP64* quaternion);
|
||||
|
|
@ -31,21 +31,6 @@ extern inline void bgc_quaternion_swap_fp64(BgcQuaternionFP64* quarternion1, Bgc
|
|||
extern inline void bgc_quaternion_convert_fp64_to_fp32(const BgcQuaternionFP64* source, BgcQuaternionFP32* destination);
|
||||
extern inline void bgc_quaternion_convert_fp32_to_fp64(const BgcQuaternionFP32* source, BgcQuaternionFP64* destination);
|
||||
|
||||
extern inline void bgc_quaternion_conjugate_fp32(const BgcQuaternionFP32* quaternion, BgcQuaternionFP32* conjugate);
|
||||
extern inline void bgc_quaternion_conjugate_fp64(const BgcQuaternionFP64* quaternion, BgcQuaternionFP64* conjugate);
|
||||
|
||||
extern inline int bgc_quaternion_invert_fp32(const BgcQuaternionFP32* quaternion, BgcQuaternionFP32* inverted);
|
||||
extern inline int bgc_quaternion_invert_fp64(const BgcQuaternionFP64* quaternion, BgcQuaternionFP64* inverted);
|
||||
|
||||
extern inline int bgc_quaternion_normalize_fp32(const BgcQuaternionFP32* quaternion, BgcQuaternionFP32* normalized);
|
||||
extern inline int bgc_quaternion_normalize_fp64(const BgcQuaternionFP64* quaternion, BgcQuaternionFP64* normalized);
|
||||
|
||||
extern inline void bgc_quaternion_get_product_fp32(const BgcQuaternionFP32* left, const BgcQuaternionFP32* right, BgcQuaternionFP32* product);
|
||||
extern inline void bgc_quaternion_get_product_fp64(const BgcQuaternionFP64* left, const BgcQuaternionFP64* right, BgcQuaternionFP64* product);
|
||||
|
||||
extern inline int bgc_quaternion_get_ratio_fp32(const BgcQuaternionFP32* divident, const BgcQuaternionFP32* divisor, BgcQuaternionFP32* quotient);
|
||||
extern inline int bgc_quaternion_get_ratio_fp64(const BgcQuaternionFP64* divident, const BgcQuaternionFP64* divisor, BgcQuaternionFP64* quotient);
|
||||
|
||||
extern inline void bgc_quaternion_add_fp32(const BgcQuaternionFP32* quaternion1, const BgcQuaternionFP32* quaternion2, BgcQuaternionFP32* sum);
|
||||
extern inline void bgc_quaternion_add_fp64(const BgcQuaternionFP64* quaternion1, const BgcQuaternionFP64* quaternion2, BgcQuaternionFP64* sum);
|
||||
|
||||
|
|
@ -55,17 +40,50 @@ extern inline void bgc_quaternion_add_scaled_fp64(const BgcQuaternionFP64* basic
|
|||
extern inline void bgc_quaternion_subtract_fp32(const BgcQuaternionFP32* minuend, const BgcQuaternionFP32* subtrahend, BgcQuaternionFP32* difference);
|
||||
extern inline void bgc_quaternion_subtract_fp64(const BgcQuaternionFP64* minuend, const BgcQuaternionFP64* subtrahend, BgcQuaternionFP64* difference);
|
||||
|
||||
extern inline void bgc_quaternion_subtract_scaled_fp32(const BgcQuaternionFP32* basic_quaternion, const BgcQuaternionFP32* scalable_quaternion, const float scale, BgcQuaternionFP32* difference);
|
||||
extern inline void bgc_quaternion_subtract_scaled_fp64(const BgcQuaternionFP64* basic_quaternion, const BgcQuaternionFP64* scalable_quaternion, const double scale, BgcQuaternionFP64* difference);
|
||||
extern inline void bgc_quaternion_multiply_fp32(const BgcQuaternionFP32* left, const BgcQuaternionFP32* right, BgcQuaternionFP32* product);
|
||||
extern inline void bgc_quaternion_multiply_fp64(const BgcQuaternionFP64* left, const BgcQuaternionFP64* right, BgcQuaternionFP64* product);
|
||||
|
||||
extern inline void bgc_quaternion_multiply_fp32(const BgcQuaternionFP32* multiplicand, const float multipier, BgcQuaternionFP32* product);
|
||||
extern inline void bgc_quaternion_multiply_fp64(const BgcQuaternionFP64* multiplicand, const double multipier, BgcQuaternionFP64* product);
|
||||
extern inline void bgc_quaternion_multiply_by_number_fp32(const BgcQuaternionFP32* multiplicand, const float multipier, BgcQuaternionFP32* product);
|
||||
extern inline void bgc_quaternion_multiply_by_number_fp64(const BgcQuaternionFP64* multiplicand, const double multipier, BgcQuaternionFP64* product);
|
||||
|
||||
extern inline void bgc_quaternion_divide_fp32(const BgcQuaternionFP32* dividend, const float divisor, BgcQuaternionFP32* quotient);
|
||||
extern inline void bgc_quaternion_divide_fp64(const BgcQuaternionFP64* dividend, const double divisor, BgcQuaternionFP64* quotient);
|
||||
extern inline int bgc_quaternion_divide_fp32(const BgcQuaternionFP32* divident, const BgcQuaternionFP32* divisor, BgcQuaternionFP32* quotient);
|
||||
extern inline int bgc_quaternion_divide_fp64(const BgcQuaternionFP64* divident, const BgcQuaternionFP64* divisor, BgcQuaternionFP64* quotient);
|
||||
|
||||
extern inline void bgc_quaternion_interpolate_linearly_fp32(const BgcQuaternionFP32* vector1, const BgcQuaternionFP32* vector2, const float phase, BgcQuaternionFP32* interpolation);
|
||||
extern inline void bgc_quaternion_interpolate_linearly_fp64(const BgcQuaternionFP64* vector1, const BgcQuaternionFP64* vector2, const double phase, BgcQuaternionFP64* interpolation);
|
||||
extern inline void bgc_quaternion_divide_by_number_fp32(const BgcQuaternionFP32* dividend, const float divisor, BgcQuaternionFP32* quotient);
|
||||
extern inline void bgc_quaternion_divide_by_number_fp64(const BgcQuaternionFP64* dividend, const double divisor, BgcQuaternionFP64* quotient);
|
||||
|
||||
extern inline void bgc_quaternion_get_mean_of_two_fp32(const BgcQuaternionFP32* vector1, const BgcQuaternionFP32* vector2, BgcQuaternionFP32* mean);
|
||||
extern inline void bgc_quaternion_get_mean_of_two_fp64(const BgcQuaternionFP64* vector1, const BgcQuaternionFP64* vector2, BgcQuaternionFP64* mean);
|
||||
|
||||
extern inline void bgc_quaternion_get_mean_of_three_fp32(const BgcQuaternionFP32* vector1, const BgcQuaternionFP32* vector2, const BgcQuaternionFP32* vector3, BgcQuaternionFP32* mean);
|
||||
extern inline void bgc_quaternion_get_mean_of_three_fp64(const BgcQuaternionFP64* vector1, const BgcQuaternionFP64* vector2, const BgcQuaternionFP64* vector3, BgcQuaternionFP64* mean);
|
||||
|
||||
extern inline void bgc_quaternion_interpolate_fp32(const BgcQuaternionFP32* vector1, const BgcQuaternionFP32* vector2, const float phase, BgcQuaternionFP32* interpolation);
|
||||
extern inline void bgc_quaternion_interpolate_fp64(const BgcQuaternionFP64* vector1, const BgcQuaternionFP64* vector2, const double phase, BgcQuaternionFP64* interpolation);
|
||||
|
||||
extern inline void bgc_quaternion_conjugate_fp32(BgcQuaternionFP32* quaternion);
|
||||
extern inline void bgc_quaternion_conjugate_fp64(BgcQuaternionFP64* quaternion);
|
||||
|
||||
extern inline void bgc_quaternion_get_conjugate_fp32(const BgcQuaternionFP32* quaternion, BgcQuaternionFP32* conjugate);
|
||||
extern inline void bgc_quaternion_get_conjugate_fp64(const BgcQuaternionFP64* quaternion, BgcQuaternionFP64* conjugate);
|
||||
|
||||
extern inline void bgc_quaternion_make_opposite_fp32(BgcQuaternionFP32* quaternion);
|
||||
extern inline void bgc_quaternion_make_opposite_fp64(BgcQuaternionFP64* quaternion);
|
||||
|
||||
extern inline void bgc_quaternion_get_opposite_fp32(const BgcQuaternionFP32* quaternion, BgcQuaternionFP32* opposite);
|
||||
extern inline void bgc_quaternion_get_opposite_fp64(const BgcQuaternionFP64* quaternion, BgcQuaternionFP64* opposite);
|
||||
|
||||
extern inline int bgc_quaternion_invert_fp32(BgcQuaternionFP32* quaternion);
|
||||
extern inline int bgc_quaternion_invert_fp64(BgcQuaternionFP64* quaternion);
|
||||
|
||||
extern inline int bgc_quaternion_get_inverse_fp32(const BgcQuaternionFP32* quaternion, BgcQuaternionFP32* inverse);
|
||||
extern inline int bgc_quaternion_get_inverse_fp64(const BgcQuaternionFP64* quaternion, BgcQuaternionFP64* inverse);
|
||||
|
||||
extern inline int bgc_quaternion_normalize_fp32(BgcQuaternionFP32* quaternion);
|
||||
extern inline int bgc_quaternion_normalize_fp64(BgcQuaternionFP64* quaternion);
|
||||
|
||||
extern inline int bgc_quaternion_get_normalized_fp32(const BgcQuaternionFP32* quaternion, BgcQuaternionFP32* normalized);
|
||||
extern inline int bgc_quaternion_get_normalized_fp64(const BgcQuaternionFP64* quaternion, BgcQuaternionFP64* normalized);
|
||||
|
||||
extern inline int bgc_quaternion_get_rotation_matrix_fp32(const BgcQuaternionFP32* quaternion, BgcMatrix3x3FP32* rotation);
|
||||
extern inline int bgc_quaternion_get_rotation_matrix_fp64(const BgcQuaternionFP64* quaternion, BgcMatrix3x3FP64* rotation);
|
||||
|
|
@ -73,8 +91,8 @@ extern inline int bgc_quaternion_get_rotation_matrix_fp64(const BgcQuaternionFP6
|
|||
extern inline int bgc_quaternion_get_reverse_matrix_fp32(const BgcQuaternionFP32* quaternion, BgcMatrix3x3FP32* reverse);
|
||||
extern inline int bgc_quaternion_get_reverse_matrix_fp64(const BgcQuaternionFP64* quaternion, BgcMatrix3x3FP64* reverse);
|
||||
|
||||
extern inline int bgc_quaternion_get_both_matrixes_fp32(const BgcQuaternionFP32* quaternion, BgcMatrix3x3FP32* rotation, BgcMatrix3x3FP32* reverse);
|
||||
extern inline int bgc_quaternion_get_both_matrixes_fp64(const BgcQuaternionFP64* quaternion, BgcMatrix3x3FP64* rotation, BgcMatrix3x3FP64* reverse);
|
||||
extern inline int bgc_quaternion_get_both_matrices_fp32(const BgcQuaternionFP32* quaternion, BgcMatrix3x3FP32* rotation, BgcMatrix3x3FP32* reverse);
|
||||
extern inline int bgc_quaternion_get_both_matrices_fp64(const BgcQuaternionFP64* quaternion, BgcMatrix3x3FP64* rotation, BgcMatrix3x3FP64* reverse);
|
||||
|
||||
extern inline int bgc_quaternion_are_close_fp32(const BgcQuaternionFP32* quaternion1, const BgcQuaternionFP32* quaternion2);
|
||||
extern inline int bgc_quaternion_are_close_fp32(const BgcQuaternionFP32* quaternion1, const BgcQuaternionFP32* quaternion2);
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@ inline void bgc_quaternion_reset_fp64(BgcQuaternionFP64 * quaternion)
|
|||
quaternion->x3 = 0.0;
|
||||
}
|
||||
|
||||
// ================== Set Unit ================== //
|
||||
// ================= Make Unit ================== //
|
||||
|
||||
inline void bgc_quaternion_set_to_identity_fp32(BgcQuaternionFP32 * quaternion)
|
||||
inline void bgc_quaternion_make_unit_fp32(BgcQuaternionFP32 * quaternion)
|
||||
{
|
||||
quaternion->s0 = 1.0f;
|
||||
quaternion->x1 = 0.0f;
|
||||
|
|
@ -43,7 +43,7 @@ inline void bgc_quaternion_set_to_identity_fp32(BgcQuaternionFP32 * quaternion)
|
|||
quaternion->x3 = 0.0f;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_set_to_identity_fp64(BgcQuaternionFP64 * quaternion)
|
||||
inline void bgc_quaternion_make_unit_fp64(BgcQuaternionFP64 * quaternion)
|
||||
{
|
||||
quaternion->s0 = 1.0;
|
||||
quaternion->x1 = 0.0;
|
||||
|
|
@ -191,186 +191,6 @@ inline void bgc_quaternion_convert_fp32_to_fp64(const BgcQuaternionFP32* source,
|
|||
destination->x3 = source->x3;
|
||||
}
|
||||
|
||||
// ================= Conjugate ================== //
|
||||
|
||||
inline void bgc_quaternion_conjugate_fp32(const BgcQuaternionFP32* quaternion, BgcQuaternionFP32* conjugate)
|
||||
{
|
||||
conjugate->s0 = quaternion->s0;
|
||||
conjugate->x1 = -quaternion->x1;
|
||||
conjugate->x2 = -quaternion->x2;
|
||||
conjugate->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_conjugate_fp64(const BgcQuaternionFP64* quaternion, BgcQuaternionFP64* conjugate)
|
||||
{
|
||||
conjugate->s0 = quaternion->s0;
|
||||
conjugate->x1 = -quaternion->x1;
|
||||
conjugate->x2 = -quaternion->x2;
|
||||
conjugate->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
// =================== Invert =================== //
|
||||
|
||||
inline int bgc_quaternion_invert_fp32(const BgcQuaternionFP32* quaternion, BgcQuaternionFP32* inverted)
|
||||
{
|
||||
const float square_modulus = bgc_quaternion_get_square_modulus_fp32(quaternion);
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float multiplicand = 1.0f / square_modulus;
|
||||
|
||||
inverted->s0 = quaternion->s0 * multiplicand;
|
||||
inverted->x1 = -quaternion->x1 * multiplicand;
|
||||
inverted->x2 = -quaternion->x2 * multiplicand;
|
||||
inverted->x3 = -quaternion->x3 * multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_quaternion_invert_fp64(const BgcQuaternionFP64* quaternion, BgcQuaternionFP64* inverted)
|
||||
{
|
||||
const double square_modulus = bgc_quaternion_get_square_modulus_fp64(quaternion);
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double multiplicand = 1.0 / square_modulus;
|
||||
|
||||
inverted->s0 = quaternion->s0 * multiplicand;
|
||||
inverted->x1 = -quaternion->x1 * multiplicand;
|
||||
inverted->x2 = -quaternion->x2 * multiplicand;
|
||||
inverted->x3 = -quaternion->x3 * multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ================= Normalize ================== //
|
||||
|
||||
inline int bgc_quaternion_normalize_fp32(const BgcQuaternionFP32* quaternion, BgcQuaternionFP32* normalized)
|
||||
{
|
||||
const float square_modulus = bgc_quaternion_get_square_modulus_fp32(quaternion);
|
||||
|
||||
if (bgc_is_sqare_unit_fp32(square_modulus)) {
|
||||
bgc_quaternion_copy_fp32(quaternion, normalized);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float multiplier = sqrtf(1.0f / square_modulus);
|
||||
|
||||
normalized->s0 = quaternion->s0 * multiplier;
|
||||
normalized->x1 = quaternion->x1 * multiplier;
|
||||
normalized->x2 = quaternion->x2 * multiplier;
|
||||
normalized->x3 = quaternion->x3 * multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_quaternion_normalize_fp64(const BgcQuaternionFP64* quaternion, BgcQuaternionFP64* normalized)
|
||||
{
|
||||
const double square_modulus = bgc_quaternion_get_square_modulus_fp64(quaternion);
|
||||
|
||||
if (bgc_is_sqare_unit_fp64(square_modulus)) {
|
||||
bgc_quaternion_copy_fp64(quaternion, normalized);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double multiplier = sqrt(1.0 / square_modulus);
|
||||
|
||||
normalized->s0 *= multiplier;
|
||||
normalized->x1 *= multiplier;
|
||||
normalized->x2 *= multiplier;
|
||||
normalized->x3 *= multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ================ Get Product ================= //
|
||||
|
||||
inline void bgc_quaternion_get_product_fp32(const BgcQuaternionFP32* left, const BgcQuaternionFP32* right, BgcQuaternionFP32* product)
|
||||
{
|
||||
const float s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3);
|
||||
const float x1 = (left->x1 * right->s0 + left->s0 * right->x1) - (left->x3 * right->x2 - left->x2 * right->x3);
|
||||
const float x2 = (left->x2 * right->s0 + left->s0 * right->x2) - (left->x1 * right->x3 - left->x3 * right->x1);
|
||||
const float x3 = (left->x3 * right->s0 + left->s0 * right->x3) - (left->x2 * right->x1 - left->x1 * right->x2);
|
||||
|
||||
product->s0 = s0;
|
||||
product->x1 = x1;
|
||||
product->x2 = x2;
|
||||
product->x3 = x3;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_get_product_fp64(const BgcQuaternionFP64* left, const BgcQuaternionFP64* right, BgcQuaternionFP64* product)
|
||||
{
|
||||
const double s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3);
|
||||
const double x1 = (left->x1 * right->s0 + left->s0 * right->x1) - (left->x3 * right->x2 - left->x2 * right->x3);
|
||||
const double x2 = (left->x2 * right->s0 + left->s0 * right->x2) - (left->x1 * right->x3 - left->x3 * right->x1);
|
||||
const double x3 = (left->x3 * right->s0 + left->s0 * right->x3) - (left->x2 * right->x1 - left->x1 * right->x2);
|
||||
|
||||
product->s0 = s0;
|
||||
product->x1 = x1;
|
||||
product->x2 = x2;
|
||||
product->x3 = x3;
|
||||
}
|
||||
|
||||
// ================= Get Ratio ================== //
|
||||
|
||||
inline int bgc_quaternion_get_ratio_fp32(const BgcQuaternionFP32* divident, const BgcQuaternionFP32* divisor, BgcQuaternionFP32* quotient)
|
||||
{
|
||||
const float square_modulus = bgc_quaternion_get_square_modulus_fp32(divisor);
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float s0 = (divident->s0 * divisor->s0 + divident->x1 * divisor->x1) + (divident->x2 * divisor->x2 + divident->x3 * divisor->x3);
|
||||
const float x1 = (divident->x1 * divisor->s0 + divident->x3 * divisor->x2) - (divident->s0 * divisor->x1 + divident->x2 * divisor->x3);
|
||||
const float x2 = (divident->x2 * divisor->s0 + divident->x1 * divisor->x3) - (divident->s0 * divisor->x2 + divident->x3 * divisor->x1);
|
||||
const float x3 = (divident->x3 * divisor->s0 + divident->x2 * divisor->x1) - (divident->s0 * divisor->x3 + divident->x1 * divisor->x2);
|
||||
|
||||
const float multiplicand = 1.0f / square_modulus;
|
||||
|
||||
quotient->s0 = s0 * multiplicand;
|
||||
quotient->x1 = x1 * multiplicand;
|
||||
quotient->x2 = x2 * multiplicand;
|
||||
quotient->x3 = x3 * multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_quaternion_get_ratio_fp64(const BgcQuaternionFP64* divident, const BgcQuaternionFP64* divisor, BgcQuaternionFP64* quotient)
|
||||
{
|
||||
const double square_modulus = bgc_quaternion_get_square_modulus_fp64(divisor);
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double s0 = (divident->s0 * divisor->s0 + divident->x1 * divisor->x1) + (divident->x2 * divisor->x2 + divident->x3 * divisor->x3);
|
||||
const double x1 = (divident->x1 * divisor->s0 + divident->x3 * divisor->x2) - (divident->s0 * divisor->x1 + divident->x2 * divisor->x3);
|
||||
const double x2 = (divident->x2 * divisor->s0 + divident->x1 * divisor->x3) - (divident->s0 * divisor->x2 + divident->x3 * divisor->x1);
|
||||
const double x3 = (divident->x3 * divisor->s0 + divident->x2 * divisor->x1) - (divident->s0 * divisor->x3 + divident->x1 * divisor->x2);
|
||||
|
||||
const double multiplicand = 1.0 / square_modulus;
|
||||
|
||||
quotient->s0 = s0 * multiplicand;
|
||||
quotient->x1 = x1 * multiplicand;
|
||||
quotient->x2 = x2 * multiplicand;
|
||||
quotient->x3 = x3 * multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ==================== Add ===================== //
|
||||
|
||||
inline void bgc_quaternion_add_fp32(const BgcQuaternionFP32 * quaternion1, const BgcQuaternionFP32 * quaternion2, BgcQuaternionFP32 * sum)
|
||||
|
|
@ -425,27 +245,35 @@ inline void bgc_quaternion_subtract_fp64(const BgcQuaternionFP64 * minuend, cons
|
|||
difference->x3 = minuend->x3 - subtrahend->x3;
|
||||
}
|
||||
|
||||
// ============== Subtract scaled =============== //
|
||||
|
||||
inline void bgc_quaternion_subtract_scaled_fp32(const BgcQuaternionFP32 * basic_quaternion, const BgcQuaternionFP32 * scalable_quaternion, const float scale, BgcQuaternionFP32 * difference)
|
||||
{
|
||||
difference->s0 = basic_quaternion->s0 - scalable_quaternion->s0 * scale;
|
||||
difference->x1 = basic_quaternion->x1 - scalable_quaternion->x1 * scale;
|
||||
difference->x2 = basic_quaternion->x2 - scalable_quaternion->x2 * scale;
|
||||
difference->x3 = basic_quaternion->x3 - scalable_quaternion->x3 * scale;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_subtract_scaled_fp64(const BgcQuaternionFP64 * basic_quaternion, const BgcQuaternionFP64 * scalable_quaternion, const double scale, BgcQuaternionFP64 * difference)
|
||||
{
|
||||
difference->s0 = basic_quaternion->s0 - scalable_quaternion->s0 * scale;
|
||||
difference->x1 = basic_quaternion->x1 - scalable_quaternion->x1 * scale;
|
||||
difference->x2 = basic_quaternion->x2 - scalable_quaternion->x2 * scale;
|
||||
difference->x3 = basic_quaternion->x3 - scalable_quaternion->x3 * scale;
|
||||
}
|
||||
|
||||
// ================== Multiply ================== //
|
||||
|
||||
inline void bgc_quaternion_multiply_fp32(const BgcQuaternionFP32* multiplicand, const float multipier, BgcQuaternionFP32* product)
|
||||
inline void bgc_quaternion_multiply_fp32(const BgcQuaternionFP32* left, const BgcQuaternionFP32* right, BgcQuaternionFP32* product)
|
||||
{
|
||||
const float s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3);
|
||||
const float x1 = (left->x1 * right->s0 + left->s0 * right->x1) - (left->x3 * right->x2 - left->x2 * right->x3);
|
||||
const float x2 = (left->x2 * right->s0 + left->s0 * right->x2) - (left->x1 * right->x3 - left->x3 * right->x1);
|
||||
const float x3 = (left->x3 * right->s0 + left->s0 * right->x3) - (left->x2 * right->x1 - left->x1 * right->x2);
|
||||
|
||||
product->s0 = s0;
|
||||
product->x1 = x1;
|
||||
product->x2 = x2;
|
||||
product->x3 = x3;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_multiply_fp64(const BgcQuaternionFP64* left, const BgcQuaternionFP64* right, BgcQuaternionFP64* product)
|
||||
{
|
||||
const double s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3);
|
||||
const double x1 = (left->x1 * right->s0 + left->s0 * right->x1) - (left->x3 * right->x2 - left->x2 * right->x3);
|
||||
const double x2 = (left->x2 * right->s0 + left->s0 * right->x2) - (left->x1 * right->x3 - left->x3 * right->x1);
|
||||
const double x3 = (left->x3 * right->s0 + left->s0 * right->x3) - (left->x2 * right->x1 - left->x1 * right->x2);
|
||||
|
||||
product->s0 = s0;
|
||||
product->x1 = x1;
|
||||
product->x2 = x2;
|
||||
product->x3 = x3;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_multiply_by_number_fp32(const BgcQuaternionFP32* multiplicand, const float multipier, BgcQuaternionFP32* product)
|
||||
{
|
||||
product->s0 = multiplicand->s0 * multipier;
|
||||
product->x1 = multiplicand->x1 * multipier;
|
||||
|
|
@ -453,7 +281,7 @@ inline void bgc_quaternion_multiply_fp32(const BgcQuaternionFP32* multiplicand,
|
|||
product->x3 = multiplicand->x3 * multipier;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_multiply_fp64(const BgcQuaternionFP64* multiplicand, const double multipier, BgcQuaternionFP64* product)
|
||||
inline void bgc_quaternion_multiply_by_number_fp64(const BgcQuaternionFP64* multiplicand, const double multipier, BgcQuaternionFP64* product)
|
||||
{
|
||||
product->s0 = multiplicand->s0 * multipier;
|
||||
product->x1 = multiplicand->x1 * multipier;
|
||||
|
|
@ -463,19 +291,101 @@ inline void bgc_quaternion_multiply_fp64(const BgcQuaternionFP64* multiplicand,
|
|||
|
||||
// =================== Divide =================== //
|
||||
|
||||
inline void bgc_quaternion_divide_fp32(const BgcQuaternionFP32* dividend, const float divisor, BgcQuaternionFP32* quotient)
|
||||
inline int bgc_quaternion_divide_fp32(const BgcQuaternionFP32* divident, const BgcQuaternionFP32* divisor, BgcQuaternionFP32* quotient)
|
||||
{
|
||||
bgc_quaternion_multiply_fp32(dividend, 1.0f / divisor, quotient);
|
||||
const float square_modulus = bgc_quaternion_get_square_modulus_fp32(divisor);
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float s0 = (divident->s0 * divisor->s0 + divident->x1 * divisor->x1) + (divident->x2 * divisor->x2 + divident->x3 * divisor->x3);
|
||||
const float x1 = (divident->x1 * divisor->s0 + divident->x3 * divisor->x2) - (divident->s0 * divisor->x1 + divident->x2 * divisor->x3);
|
||||
const float x2 = (divident->x2 * divisor->s0 + divident->x1 * divisor->x3) - (divident->s0 * divisor->x2 + divident->x3 * divisor->x1);
|
||||
const float x3 = (divident->x3 * divisor->s0 + divident->x2 * divisor->x1) - (divident->s0 * divisor->x3 + divident->x1 * divisor->x2);
|
||||
|
||||
const float multiplicand = 1.0f / square_modulus;
|
||||
|
||||
quotient->s0 = s0 * multiplicand;
|
||||
quotient->x1 = x1 * multiplicand;
|
||||
quotient->x2 = x2 * multiplicand;
|
||||
quotient->x3 = x3 * multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_divide_fp64(const BgcQuaternionFP64* dividend, const double divisor, BgcQuaternionFP64* quotient)
|
||||
inline int bgc_quaternion_divide_fp64(const BgcQuaternionFP64* divident, const BgcQuaternionFP64* divisor, BgcQuaternionFP64* quotient)
|
||||
{
|
||||
bgc_quaternion_multiply_fp64(dividend, 1.0 / divisor, quotient);
|
||||
const double square_modulus = bgc_quaternion_get_square_modulus_fp64(divisor);
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double s0 = (divident->s0 * divisor->s0 + divident->x1 * divisor->x1) + (divident->x2 * divisor->x2 + divident->x3 * divisor->x3);
|
||||
const double x1 = (divident->x1 * divisor->s0 + divident->x3 * divisor->x2) - (divident->s0 * divisor->x1 + divident->x2 * divisor->x3);
|
||||
const double x2 = (divident->x2 * divisor->s0 + divident->x1 * divisor->x3) - (divident->s0 * divisor->x2 + divident->x3 * divisor->x1);
|
||||
const double x3 = (divident->x3 * divisor->s0 + divident->x2 * divisor->x1) - (divident->s0 * divisor->x3 + divident->x1 * divisor->x2);
|
||||
|
||||
const double multiplicand = 1.0 / square_modulus;
|
||||
|
||||
quotient->s0 = s0 * multiplicand;
|
||||
quotient->x1 = x1 * multiplicand;
|
||||
quotient->x2 = x2 * multiplicand;
|
||||
quotient->x3 = x3 * multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_divide_by_number_fp32(const BgcQuaternionFP32* dividend, const float divisor, BgcQuaternionFP32* quotient)
|
||||
{
|
||||
bgc_quaternion_multiply_by_number_fp32(dividend, 1.0f / divisor, quotient);
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_divide_by_number_fp64(const BgcQuaternionFP64* dividend, const double divisor, BgcQuaternionFP64* quotient)
|
||||
{
|
||||
bgc_quaternion_multiply_by_number_fp64(dividend, 1.0 / divisor, quotient);
|
||||
}
|
||||
|
||||
// ================ Mean of Two ================= //
|
||||
|
||||
inline void bgc_quaternion_get_mean_of_two_fp32(const BgcQuaternionFP32* vector1, const BgcQuaternionFP32* vector2, BgcQuaternionFP32* mean)
|
||||
{
|
||||
mean->s0 = (vector1->s0 + vector2->s0) * 0.5f;
|
||||
mean->x1 = (vector1->x1 + vector2->x1) * 0.5f;
|
||||
mean->x2 = (vector1->x2 + vector2->x2) * 0.5f;
|
||||
mean->x3 = (vector1->x3 + vector2->x3) * 0.5f;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_get_mean_of_two_fp64(const BgcQuaternionFP64* vector1, const BgcQuaternionFP64* vector2, BgcQuaternionFP64* mean)
|
||||
{
|
||||
mean->s0 = (vector1->s0 + vector2->s0) * 0.5f;
|
||||
mean->x1 = (vector1->x1 + vector2->x1) * 0.5f;
|
||||
mean->x2 = (vector1->x2 + vector2->x2) * 0.5f;
|
||||
mean->x3 = (vector1->x3 + vector2->x3) * 0.5f;
|
||||
}
|
||||
|
||||
// =============== Mean of Three ================ //
|
||||
|
||||
inline void bgc_quaternion_get_mean_of_three_fp32(const BgcQuaternionFP32* vector1, const BgcQuaternionFP32* vector2, const BgcQuaternionFP32* vector3, BgcQuaternionFP32* mean)
|
||||
{
|
||||
mean->s0 = (vector1->s0 + vector2->s0 + vector3->s0) * BGC_ONE_THIRD_FP32;
|
||||
mean->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BGC_ONE_THIRD_FP32;
|
||||
mean->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BGC_ONE_THIRD_FP32;
|
||||
mean->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * BGC_ONE_THIRD_FP32;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_get_mean_of_three_fp64(const BgcQuaternionFP64* vector1, const BgcQuaternionFP64* vector2, const BgcQuaternionFP64* vector3, BgcQuaternionFP64* mean)
|
||||
{
|
||||
mean->s0 = (vector1->s0 + vector2->s0 + vector3->s0) * BGC_ONE_THIRD_FP64;
|
||||
mean->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BGC_ONE_THIRD_FP64;
|
||||
mean->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BGC_ONE_THIRD_FP64;
|
||||
mean->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * BGC_ONE_THIRD_FP64;
|
||||
}
|
||||
|
||||
// ============ Linear Interpolation ============ //
|
||||
|
||||
inline void bgc_quaternion_interpolate_linearly_fp32(const BgcQuaternionFP32* quaternion1, const BgcQuaternionFP32* quaternion2, const float phase, BgcQuaternionFP32* interpolation)
|
||||
inline void bgc_quaternion_interpolate_fp32(const BgcQuaternionFP32* quaternion1, const BgcQuaternionFP32* quaternion2, const float phase, BgcQuaternionFP32* interpolation)
|
||||
{
|
||||
const float counterphase = 1.0f - phase;
|
||||
|
||||
|
|
@ -485,7 +395,7 @@ inline void bgc_quaternion_interpolate_linearly_fp32(const BgcQuaternionFP32* qu
|
|||
interpolation->x3 = quaternion1->x3 * counterphase + quaternion2->x3 * phase;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_interpolate_linearly_fp64(const BgcQuaternionFP64* quaternion1, const BgcQuaternionFP64* quaternion2, const double phase, BgcQuaternionFP64* interpolation)
|
||||
inline void bgc_quaternion_interpolate_fp64(const BgcQuaternionFP64* quaternion1, const BgcQuaternionFP64* quaternion2, const double phase, BgcQuaternionFP64* interpolation)
|
||||
{
|
||||
const double counterphase = 1.0 - phase;
|
||||
|
||||
|
|
@ -495,6 +405,202 @@ inline void bgc_quaternion_interpolate_linearly_fp64(const BgcQuaternionFP64* qu
|
|||
interpolation->x3 = quaternion1->x3 * counterphase + quaternion2->x3 * phase;
|
||||
}
|
||||
|
||||
// ================= Conjugate ================== //
|
||||
|
||||
inline void bgc_quaternion_conjugate_fp32(BgcQuaternionFP32* quaternion)
|
||||
{
|
||||
quaternion->x1 = -quaternion->x1;
|
||||
quaternion->x2 = -quaternion->x2;
|
||||
quaternion->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_conjugate_fp64(BgcQuaternionFP64* quaternion)
|
||||
{
|
||||
quaternion->x1 = -quaternion->x1;
|
||||
quaternion->x2 = -quaternion->x2;
|
||||
quaternion->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_get_conjugate_fp32(const BgcQuaternionFP32* quaternion, BgcQuaternionFP32* conjugate)
|
||||
{
|
||||
conjugate->s0 = quaternion->s0;
|
||||
conjugate->x1 = -quaternion->x1;
|
||||
conjugate->x2 = -quaternion->x2;
|
||||
conjugate->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_get_conjugate_fp64(const BgcQuaternionFP64* quaternion, BgcQuaternionFP64* conjugate)
|
||||
{
|
||||
conjugate->s0 = quaternion->s0;
|
||||
conjugate->x1 = -quaternion->x1;
|
||||
conjugate->x2 = -quaternion->x2;
|
||||
conjugate->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
// ================== Negative ================== //
|
||||
|
||||
inline void bgc_quaternion_make_opposite_fp32(BgcQuaternionFP32* quaternion)
|
||||
{
|
||||
quaternion->s0 = -quaternion->s0;
|
||||
quaternion->x1 = -quaternion->x1;
|
||||
quaternion->x2 = -quaternion->x2;
|
||||
quaternion->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_make_opposite_fp64(BgcQuaternionFP64* quaternion)
|
||||
{
|
||||
quaternion->s0 = -quaternion->s0;
|
||||
quaternion->x1 = -quaternion->x1;
|
||||
quaternion->x2 = -quaternion->x2;
|
||||
quaternion->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_get_opposite_fp32(const BgcQuaternionFP32* quaternion, BgcQuaternionFP32* opposite)
|
||||
{
|
||||
opposite->s0 = -quaternion->s0;
|
||||
opposite->x1 = -quaternion->x1;
|
||||
opposite->x2 = -quaternion->x2;
|
||||
opposite->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_get_opposite_fp64(const BgcQuaternionFP64* quaternion, BgcQuaternionFP64* opposite)
|
||||
{
|
||||
opposite->s0 = -quaternion->s0;
|
||||
opposite->x1 = -quaternion->x1;
|
||||
opposite->x2 = -quaternion->x2;
|
||||
opposite->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
// =================== Invert =================== //
|
||||
|
||||
inline int bgc_quaternion_get_inverse_fp32(const BgcQuaternionFP32* quaternion, BgcQuaternionFP32* inverse)
|
||||
{
|
||||
const float square_modulus = bgc_quaternion_get_square_modulus_fp32(quaternion);
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float multiplicand = 1.0f / square_modulus;
|
||||
|
||||
inverse->s0 = quaternion->s0 * multiplicand;
|
||||
inverse->x1 = -quaternion->x1 * multiplicand;
|
||||
inverse->x2 = -quaternion->x2 * multiplicand;
|
||||
inverse->x3 = -quaternion->x3 * multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_quaternion_get_inverse_fp64(const BgcQuaternionFP64* quaternion, BgcQuaternionFP64* inverse)
|
||||
{
|
||||
const double square_modulus = bgc_quaternion_get_square_modulus_fp64(quaternion);
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double multiplicand = 1.0 / square_modulus;
|
||||
|
||||
inverse->s0 = quaternion->s0 * multiplicand;
|
||||
inverse->x1 = -quaternion->x1 * multiplicand;
|
||||
inverse->x2 = -quaternion->x2 * multiplicand;
|
||||
inverse->x3 = -quaternion->x3 * multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_quaternion_invert_fp32(BgcQuaternionFP32* quaternion)
|
||||
{
|
||||
return bgc_quaternion_get_inverse_fp32(quaternion, quaternion);
|
||||
}
|
||||
|
||||
inline int bgc_quaternion_invert_fp64(BgcQuaternionFP64* quaternion)
|
||||
{
|
||||
return bgc_quaternion_get_inverse_fp64(quaternion, quaternion);
|
||||
}
|
||||
|
||||
// ================= Normalize ================== //
|
||||
|
||||
inline int bgc_quaternion_normalize_fp32(BgcQuaternionFP32* quaternion)
|
||||
{
|
||||
const float square_modulus = bgc_quaternion_get_square_modulus_fp32(quaternion);
|
||||
|
||||
if (bgc_is_sqare_unit_fp32(square_modulus)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float multiplier = sqrtf(1.0f / square_modulus);
|
||||
|
||||
quaternion->s0 *= multiplier;
|
||||
quaternion->x1 *= multiplier;
|
||||
quaternion->x2 *= multiplier;
|
||||
quaternion->x3 *= multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_quaternion_normalize_fp64(BgcQuaternionFP64* quaternion)
|
||||
{
|
||||
const double square_modulus = bgc_quaternion_get_square_modulus_fp64(quaternion);
|
||||
|
||||
if (bgc_is_sqare_unit_fp64(square_modulus)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double multiplier = sqrt(1.0 / square_modulus);
|
||||
|
||||
quaternion->s0 *= multiplier;
|
||||
quaternion->x1 *= multiplier;
|
||||
quaternion->x2 *= multiplier;
|
||||
quaternion->x3 *= multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_quaternion_get_normalized_fp32(const BgcQuaternionFP32* quaternion, BgcQuaternionFP32* normalized)
|
||||
{
|
||||
const float square_modulus = bgc_quaternion_get_square_modulus_fp32(quaternion);
|
||||
|
||||
if (bgc_is_sqare_unit_fp32(square_modulus)) {
|
||||
bgc_quaternion_copy_fp32(quaternion, normalized);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
bgc_quaternion_reset_fp32(normalized);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_quaternion_multiply_by_number_fp32(quaternion, sqrtf(1.0f / square_modulus), normalized);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_quaternion_get_normalized_fp64(const BgcQuaternionFP64* quaternion, BgcQuaternionFP64* normalized)
|
||||
{
|
||||
const double square_modulus = bgc_quaternion_get_square_modulus_fp64(quaternion);
|
||||
|
||||
if (bgc_is_sqare_unit_fp64(square_modulus)) {
|
||||
bgc_quaternion_copy_fp64(quaternion, normalized);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
bgc_quaternion_reset_fp64(normalized);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_quaternion_multiply_by_number_fp64(quaternion, sqrt(1.0 / square_modulus), normalized);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// =============== Get Exponation =============== //
|
||||
|
||||
int bgc_quaternion_get_exponation_fp32(const BgcQuaternionFP32* base, const float exponent, BgcQuaternionFP32* power);
|
||||
|
|
@ -514,6 +620,7 @@ inline int bgc_quaternion_get_rotation_matrix_fp32(const BgcQuaternionFP32* quat
|
|||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus)
|
||||
{
|
||||
bgc_matrix3x3_set_to_identity_fp32(rotation);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -554,6 +661,7 @@ inline int bgc_quaternion_get_rotation_matrix_fp64(const BgcQuaternionFP64* quat
|
|||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus)
|
||||
{
|
||||
bgc_matrix3x3_set_to_identity_fp64(rotation);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -596,6 +704,7 @@ inline int bgc_quaternion_get_reverse_matrix_fp32(const BgcQuaternionFP32* quate
|
|||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus)
|
||||
{
|
||||
bgc_matrix3x3_set_to_identity_fp32(reverse);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -636,6 +745,7 @@ inline int bgc_quaternion_get_reverse_matrix_fp64(const BgcQuaternionFP64* quate
|
|||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus)
|
||||
{
|
||||
bgc_matrix3x3_set_to_identity_fp64(reverse);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -667,7 +777,7 @@ inline int bgc_quaternion_get_reverse_matrix_fp64(const BgcQuaternionFP64* quate
|
|||
|
||||
// ============= Get Both Matrixes ============== //
|
||||
|
||||
inline int bgc_quaternion_get_both_matrixes_fp32(const BgcQuaternionFP32* quaternion, BgcMatrix3x3FP32* rotation, BgcMatrix3x3FP32* reverse)
|
||||
inline int bgc_quaternion_get_both_matrices_fp32(const BgcQuaternionFP32* quaternion, BgcMatrix3x3FP32* rotation, BgcMatrix3x3FP32* reverse)
|
||||
{
|
||||
if (bgc_quaternion_get_reverse_matrix_fp32(quaternion, reverse)) {
|
||||
bgc_matrix3x3_transpose_fp32(reverse, rotation);
|
||||
|
|
@ -677,7 +787,7 @@ inline int bgc_quaternion_get_both_matrixes_fp32(const BgcQuaternionFP32* quater
|
|||
return 0;
|
||||
}
|
||||
|
||||
inline int bgc_quaternion_get_both_matrixes_fp64(const BgcQuaternionFP64* quaternion, BgcMatrix3x3FP64* rotation, BgcMatrix3x3FP64* reverse)
|
||||
inline int bgc_quaternion_get_both_matrices_fp64(const BgcQuaternionFP64* quaternion, BgcMatrix3x3FP64* rotation, BgcMatrix3x3FP64* reverse)
|
||||
{
|
||||
if (bgc_quaternion_get_reverse_matrix_fp64(quaternion, reverse)) {
|
||||
bgc_matrix3x3_transpose_fp64(reverse, rotation);
|
||||
|
|
|
|||
|
|
@ -72,9 +72,7 @@ inline void bgc_rotation3_set_values_fp64(const double x1, const double x2, cons
|
|||
|
||||
inline void bgc_rotation3_set_with_axis_fp32(const BgcVector3FP32* axis, const float angle, const BgcAngleUnitEnum unit, BgcRotation3FP32* rotation)
|
||||
{
|
||||
bgc_vector3_copy_fp32(axis, &rotation->axis);
|
||||
|
||||
if (bgc_vector3_normalize_fp32(&rotation->axis)) {
|
||||
if (bgc_vector3_get_normalized_fp32(axis, &rotation->axis)) {
|
||||
rotation->radians = bgc_angle_to_radians_fp32(angle, unit);
|
||||
}
|
||||
else {
|
||||
|
|
@ -84,9 +82,7 @@ inline void bgc_rotation3_set_with_axis_fp32(const BgcVector3FP32* axis, const f
|
|||
|
||||
inline void bgc_rotation3_set_with_axis_fp64(const BgcVector3FP64* axis, const double angle, const BgcAngleUnitEnum unit, BgcRotation3FP64* rotation)
|
||||
{
|
||||
bgc_vector3_copy_fp64(axis, &rotation->axis);
|
||||
|
||||
if (bgc_vector3_normalize_fp64(&rotation->axis)) {
|
||||
if (bgc_vector3_get_normalized_fp64(axis, &rotation->axis)) {
|
||||
rotation->radians = bgc_angle_to_radians_fp64(angle, unit);
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ extern inline void bgc_slerp_get_turn_for_phase_fp64(const BgcSlerpFP64* slerp,
|
|||
|
||||
void bgc_slerp_make_fp32(const BgcVersorFP32* start, const BgcVersorFP32* augment, BgcSlerpFP32* slerp)
|
||||
{
|
||||
const float square_vector = augment->x1 * augment->x1 + augment->x2 * augment->x2 + augment->x3 * augment->x3;
|
||||
const float square_vector = augment->_x1 * augment->_x1 + augment->_x2 * augment->_x2 + augment->_x3 * augment->_x3;
|
||||
|
||||
if (square_vector != square_vector) {
|
||||
bgc_slerp_reset_fp32(slerp);
|
||||
|
|
@ -22,10 +22,10 @@ void bgc_slerp_make_fp32(const BgcVersorFP32* start, const BgcVersorFP32* augmen
|
|||
}
|
||||
|
||||
if (square_vector <= BGC_SQUARE_EPSYLON_FP32) {
|
||||
slerp->s0_cos_weight = start->s0;
|
||||
slerp->x1_cos_weight = start->x1;
|
||||
slerp->x2_cos_weight = start->x2;
|
||||
slerp->x3_cos_weight = start->x3;
|
||||
slerp->s0_cos_weight = start->_s0;
|
||||
slerp->x1_cos_weight = start->_x1;
|
||||
slerp->x2_cos_weight = start->_x2;
|
||||
slerp->x3_cos_weight = start->_x3;
|
||||
|
||||
slerp->s0_sin_weight = 0.0f;
|
||||
slerp->x1_sin_weight = 0.0f;
|
||||
|
|
@ -38,24 +38,24 @@ void bgc_slerp_make_fp32(const BgcVersorFP32* start, const BgcVersorFP32* augmen
|
|||
|
||||
const float vector_modulus = sqrtf(square_vector);
|
||||
|
||||
slerp->radians = atan2f(vector_modulus, augment->s0);
|
||||
slerp->radians = atan2f(vector_modulus, augment->_s0);
|
||||
|
||||
const float multiplier = 1.0f / vector_modulus;
|
||||
|
||||
slerp->s0_cos_weight = start->s0;
|
||||
slerp->x1_cos_weight = start->x1;
|
||||
slerp->x2_cos_weight = start->x2;
|
||||
slerp->x3_cos_weight = start->x3;
|
||||
slerp->s0_cos_weight = start->_s0;
|
||||
slerp->x1_cos_weight = start->_x1;
|
||||
slerp->x2_cos_weight = start->_x2;
|
||||
slerp->x3_cos_weight = start->_x3;
|
||||
|
||||
slerp->s0_sin_weight = -multiplier * (augment->x1 * start->x1 + augment->x2 * start->x2 + augment->x3 * start->x3);
|
||||
slerp->x1_sin_weight = multiplier * (augment->x1 * start->s0 + augment->x2 * start->x3 - augment->x3 * start->x2);
|
||||
slerp->x2_sin_weight = multiplier * (augment->x2 * start->s0 - augment->x1 * start->x3 + augment->x3 * start->x1);
|
||||
slerp->x3_sin_weight = multiplier * (augment->x3 * start->s0 - augment->x2 * start->x1 + augment->x1 * start->x2);
|
||||
slerp->s0_sin_weight = -multiplier * (augment->_x1 * start->_x1 + augment->_x2 * start->_x2 + augment->_x3 * start->_x3);
|
||||
slerp->x1_sin_weight = multiplier * (augment->_x1 * start->_s0 + augment->_x2 * start->_x3 - augment->_x3 * start->_x2);
|
||||
slerp->x2_sin_weight = multiplier * (augment->_x2 * start->_s0 - augment->_x1 * start->_x3 + augment->_x3 * start->_x1);
|
||||
slerp->x3_sin_weight = multiplier * (augment->_x3 * start->_s0 - augment->_x2 * start->_x1 + augment->_x1 * start->_x2);
|
||||
}
|
||||
|
||||
void bgc_slerp_make_fp64(const BgcVersorFP64* start, const BgcVersorFP64* augment, BgcSlerpFP64* slerp)
|
||||
{
|
||||
const double square_vector = augment->x1 * augment->x1 + augment->x2 * augment->x2 + augment->x3 * augment->x3;
|
||||
const double square_vector = augment->_x1 * augment->_x1 + augment->_x2 * augment->_x2 + augment->_x3 * augment->_x3;
|
||||
|
||||
if (square_vector != square_vector) {
|
||||
bgc_slerp_reset_fp64(slerp);
|
||||
|
|
@ -63,10 +63,10 @@ void bgc_slerp_make_fp64(const BgcVersorFP64* start, const BgcVersorFP64* augmen
|
|||
}
|
||||
|
||||
if (square_vector <= BGC_SQUARE_EPSYLON_FP64) {
|
||||
slerp->s0_cos_weight = start->s0;
|
||||
slerp->x1_cos_weight = start->x1;
|
||||
slerp->x2_cos_weight = start->x2;
|
||||
slerp->x3_cos_weight = start->x3;
|
||||
slerp->s0_cos_weight = start->_s0;
|
||||
slerp->x1_cos_weight = start->_x1;
|
||||
slerp->x2_cos_weight = start->_x2;
|
||||
slerp->x3_cos_weight = start->_x3;
|
||||
|
||||
slerp->s0_sin_weight = 0.0;
|
||||
slerp->x1_sin_weight = 0.0;
|
||||
|
|
@ -79,17 +79,17 @@ void bgc_slerp_make_fp64(const BgcVersorFP64* start, const BgcVersorFP64* augmen
|
|||
|
||||
const double vector_modulus = sqrt(square_vector);
|
||||
|
||||
slerp->radians = atan2(vector_modulus, augment->s0);
|
||||
slerp->radians = atan2(vector_modulus, augment->_s0);
|
||||
|
||||
const double multiplier = 1.0 / vector_modulus;
|
||||
|
||||
slerp->s0_cos_weight = start->s0;
|
||||
slerp->x1_cos_weight = start->x1;
|
||||
slerp->x2_cos_weight = start->x2;
|
||||
slerp->x3_cos_weight = start->x3;
|
||||
slerp->s0_cos_weight = start->_s0;
|
||||
slerp->x1_cos_weight = start->_x1;
|
||||
slerp->x2_cos_weight = start->_x2;
|
||||
slerp->x3_cos_weight = start->_x3;
|
||||
|
||||
slerp->s0_sin_weight = -multiplier * (augment->x1 * start->x1 + augment->x2 * start->x2 + augment->x3 * start->x3);
|
||||
slerp->x1_sin_weight = multiplier * (augment->x1 * start->s0 + augment->x2 * start->x3 - augment->x3 * start->x2);
|
||||
slerp->x2_sin_weight = multiplier * (augment->x2 * start->s0 - augment->x1 * start->x3 + augment->x3 * start->x1);
|
||||
slerp->x3_sin_weight = multiplier * (augment->x3 * start->s0 - augment->x2 * start->x1 + augment->x1 * start->x2);
|
||||
slerp->s0_sin_weight = -multiplier * (augment->_x1 * start->_x1 + augment->_x2 * start->_x2 + augment->_x3 * start->_x3);
|
||||
slerp->x1_sin_weight = multiplier * (augment->_x1 * start->_s0 + augment->_x2 * start->_x3 - augment->_x3 * start->_x2);
|
||||
slerp->x2_sin_weight = multiplier * (augment->_x2 * start->_s0 - augment->_x1 * start->_x3 + augment->_x3 * start->_x1);
|
||||
slerp->x3_sin_weight = multiplier * (augment->_x3 * start->_s0 - augment->_x2 * start->_x1 + augment->_x1 * start->_x2);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ inline void bgc_slerp_make_shortened_fp32(const BgcVersorFP32* start, const BgcV
|
|||
BgcVersorFP32 augment;
|
||||
|
||||
bgc_versor_exclude_fp32(end, start, &augment);
|
||||
bgc_versor_shorten_fp32(&augment, &augment);
|
||||
bgc_versor_shorten_fp32(&augment);
|
||||
|
||||
bgc_slerp_make_fp32(start, &augment, slerp);
|
||||
}
|
||||
|
|
@ -90,7 +90,7 @@ inline void bgc_slerp_make_shortened_fp64(const BgcVersorFP64* start, const BgcV
|
|||
BgcVersorFP64 augment;
|
||||
|
||||
bgc_versor_exclude_fp64(end, start, &augment);
|
||||
bgc_versor_shorten_fp64(&augment, &augment);
|
||||
bgc_versor_shorten_fp64(&augment);
|
||||
|
||||
bgc_slerp_make_fp64(start, &augment, slerp);
|
||||
}
|
||||
|
|
|
|||
16
basic-geometry/types.h
Normal file
16
basic-geometry/types.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef _BGC_TYPES_H_
|
||||
#define _BGC_TYPES_H_
|
||||
|
||||
// ================== Complex =================== //
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float real, imaginary;
|
||||
} BgcComplexFP32;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double real, imaginary;
|
||||
} BgcComplexFP64;
|
||||
|
||||
#endif
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#include "utilities.h"
|
||||
|
||||
extern inline int bgc_is_correct_direction(const int direction);
|
||||
extern inline int bgc_is_correct_axis(const int axis);
|
||||
|
||||
extern inline int bgc_is_zero_fp32(const float square_value);
|
||||
extern inline int bgc_is_zero_fp64(const double square_value);
|
||||
|
|
|
|||
|
|
@ -32,15 +32,25 @@
|
|||
#define BGC_SUCCESS 0
|
||||
#define BGC_FAILED -1
|
||||
|
||||
#define BGC_DIRECTION_X1 1
|
||||
#define BGC_DIRECTION_X2 2
|
||||
#define BGC_DIRECTION_X3 3
|
||||
#define BGC_ATTITUDE_ANY 0
|
||||
#define BGC_ATTITUDE_ZERO 1
|
||||
#define BGC_ATTITUDE_ORTHOGONAL 2
|
||||
#define BGC_ATTITUDE_CO_DIRECTIONAL 3
|
||||
#define BGC_ATTITUDE_COUNTER_DIRECTIONAL 4
|
||||
|
||||
inline int bgc_is_correct_direction(const int direction)
|
||||
#define BGC_AXIS_X1 1
|
||||
#define BGC_AXIS_X2 2
|
||||
#define BGC_AXIS_X3 3
|
||||
|
||||
#define BGC_AXIS_REVERSE_X1 -1
|
||||
#define BGC_AXIS_REVERSE_X2 -2
|
||||
#define BGC_AXIS_REVERSE_X3 -3
|
||||
|
||||
inline int bgc_is_correct_axis(const int axis)
|
||||
{
|
||||
return direction == BGC_DIRECTION_X1 || direction == -BGC_DIRECTION_X1
|
||||
|| direction == BGC_DIRECTION_X2 || direction == -BGC_DIRECTION_X2
|
||||
|| direction == BGC_DIRECTION_X3 || direction == -BGC_DIRECTION_X3;
|
||||
return axis == BGC_AXIS_X1 || axis == BGC_AXIS_REVERSE_X1
|
||||
|| axis == BGC_AXIS_X2 || axis == BGC_AXIS_REVERSE_X2
|
||||
|| axis == BGC_AXIS_X3 || axis == BGC_AXIS_REVERSE_X3;
|
||||
}
|
||||
|
||||
inline int bgc_is_zero_fp32(const float value)
|
||||
|
|
|
|||
|
|
@ -6,9 +6,6 @@ extern inline void bgc_vector2_reset_fp64(BgcVector2FP64* vector);
|
|||
extern inline void bgc_vector2_set_values_fp32(const float x1, const float x2, BgcVector2FP32* destination);
|
||||
extern inline void bgc_vector2_set_values_fp64(const double x1, const double x2, BgcVector2FP64* destination);
|
||||
|
||||
extern inline int bgc_vector2_get_direction_fp32(const int direction, BgcVector2FP32* vector);
|
||||
extern inline int bgc_vector2_get_direction_fp64(const int direction, BgcVector2FP64* vector);
|
||||
|
||||
extern inline float bgc_vector2_get_square_modulus_fp32(const BgcVector2FP32* vector);
|
||||
extern inline double bgc_vector2_get_square_modulus_fp64(const BgcVector2FP64* vector);
|
||||
|
||||
|
|
@ -30,12 +27,6 @@ extern inline void bgc_vector2_swap_fp64(BgcVector2FP64* vector1, BgcVector2FP64
|
|||
extern inline void bgc_vector2_convert_fp64_to_fp32(const BgcVector2FP64* source, BgcVector2FP32* destination);
|
||||
extern inline void bgc_vector2_convert_fp32_to_fp64(const BgcVector2FP32* source, BgcVector2FP64* destination);
|
||||
|
||||
extern inline void bgc_vector2_reverse_fp32(const BgcVector2FP32* vector, BgcVector2FP32* reverse);
|
||||
extern inline void bgc_vector2_reverse_fp64(const BgcVector2FP64* vector, BgcVector2FP64* reverse);
|
||||
|
||||
extern inline int bgc_vector2_normalize_fp32(const BgcVector2FP32* vector, BgcVector2FP32* normalized);
|
||||
extern inline int bgc_vector2_normalize_fp64(const BgcVector2FP64* vector, BgcVector2FP64* normalized);
|
||||
|
||||
extern inline void bgc_vector2_add_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, BgcVector2FP32* sum);
|
||||
extern inline void bgc_vector2_add_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, BgcVector2FP64* sum);
|
||||
|
||||
|
|
@ -45,9 +36,6 @@ extern inline void bgc_vector2_add_scaled_fp64(const BgcVector2FP64* basic_vecto
|
|||
extern inline void bgc_vector2_subtract_fp32(const BgcVector2FP32* minuend, const BgcVector2FP32* subtrahend, BgcVector2FP32* difference);
|
||||
extern inline void bgc_vector2_subtract_fp64(const BgcVector2FP64* minuend, const BgcVector2FP64* subtrahend, BgcVector2FP64* difference);
|
||||
|
||||
extern inline void bgc_vector2_subtract_scaled_fp32(const BgcVector2FP32* basic_vector, const BgcVector2FP32* scalable_vector, const float scale, BgcVector2FP32* difference);
|
||||
extern inline void bgc_vector2_subtract_scaled_fp64(const BgcVector2FP64* basic_vector, const BgcVector2FP64* scalable_vector, const double scale, BgcVector2FP64* difference);
|
||||
|
||||
extern inline void bgc_vector2_multiply_fp32(const BgcVector2FP32* multiplicand, const float multiplier, BgcVector2FP32* product);
|
||||
extern inline void bgc_vector2_multiply_fp64(const BgcVector2FP64* multiplicand, const double multiplier, BgcVector2FP64* product);
|
||||
|
||||
|
|
@ -60,14 +48,20 @@ 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_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_interpolate_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const float phase, BgcVector2FP32* interpolation);
|
||||
extern inline void bgc_vector2_interpolate_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);
|
||||
extern inline void bgc_vector2_make_opposite_fp32(BgcVector2FP32* vector);
|
||||
extern inline void bgc_vector2_make_opposite_fp64(BgcVector2FP64* vector);
|
||||
|
||||
extern inline void bgc_vector2_maximize_fp32(const BgcVector2FP32* vector, BgcVector2FP32* maximal);
|
||||
extern inline void bgc_vector2_maximize_fp64(const BgcVector2FP64* vector, BgcVector2FP64* maximal);
|
||||
extern inline void bgc_vector2_get_opposite_fp32(const BgcVector2FP32* vector, BgcVector2FP32* opposite);
|
||||
extern inline void bgc_vector2_get_opposite_fp64(const BgcVector2FP64* vector, BgcVector2FP64* opposite);
|
||||
|
||||
extern inline int bgc_vector2_normalize_fp32(BgcVector2FP32* vector);
|
||||
extern inline int bgc_vector2_normalize_fp64(BgcVector2FP64* vector);
|
||||
|
||||
extern inline int bgc_vector2_get_normalized_fp32(const BgcVector2FP32* vector, BgcVector2FP32* normalized);
|
||||
extern inline int bgc_vector2_get_normalized_fp64(const BgcVector2FP64* vector, BgcVector2FP64* normalized);
|
||||
|
||||
extern inline float bgc_vector2_get_scalar_product_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2);
|
||||
extern inline double bgc_vector2_get_scalar_product_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2);
|
||||
|
|
@ -87,6 +81,15 @@ 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);
|
||||
|
||||
extern inline int bgc_vector2_are_parallel_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2);
|
||||
extern inline int bgc_vector2_are_parallel_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2);
|
||||
|
||||
extern inline int bgc_vector2_are_orthogonal_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2);
|
||||
extern inline int bgc_vector2_are_orthogonal_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2);
|
||||
|
||||
extern inline int bgc_vector2_get_attitude_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2);
|
||||
extern inline int bgc_vector2_get_attitude_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2);
|
||||
|
||||
// =================== Angle ==================== //
|
||||
|
||||
float bgc_vector2_get_angle_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const BgcAngleUnitEnum unit)
|
||||
|
|
@ -105,11 +108,13 @@ float bgc_vector2_get_angle_fp32(const BgcVector2FP32* vector1, const BgcVector2
|
|||
return 0.0f;
|
||||
}
|
||||
|
||||
const float scalar = bgc_vector2_get_scalar_product_fp32(vector1, vector2);
|
||||
const float multiplier = sqrtf(1.0f / (square_modulus1 * square_modulus2));
|
||||
|
||||
const float cross = bgc_vector2_get_cross_product_fp32(vector1, vector2);
|
||||
const float x = bgc_vector2_get_scalar_product_fp32(vector1, vector2);
|
||||
|
||||
return bgc_radians_to_units_fp32(atan2f(cross >= 0 ? cross : -cross, scalar), unit);
|
||||
const float y = fabsf(bgc_vector2_get_cross_product_fp32(vector1, vector2));
|
||||
|
||||
return bgc_radians_to_units_fp32(atan2f(y * multiplier, x * multiplier), unit);
|
||||
}
|
||||
|
||||
double bgc_vector2_get_angle_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, const BgcAngleUnitEnum unit)
|
||||
|
|
@ -128,9 +133,11 @@ double bgc_vector2_get_angle_fp64(const BgcVector2FP64* vector1, const BgcVector
|
|||
return 0.0;
|
||||
}
|
||||
|
||||
const double scalar = bgc_vector2_get_scalar_product_fp64(vector1, vector2);
|
||||
const double multiplier = sqrt(1.0 / (square_modulus1 * square_modulus2));
|
||||
|
||||
const double cross = bgc_vector2_get_cross_product_fp64(vector1, vector2);
|
||||
const double x = bgc_vector2_get_scalar_product_fp64(vector1, vector2);
|
||||
|
||||
return bgc_radians_to_units_fp64(atan2(cross >= 0 ? cross : -cross, scalar), unit);
|
||||
const double y = bgc_vector2_get_cross_product_fp64(vector1, vector2);
|
||||
|
||||
return bgc_radians_to_units_fp64(atan2(y * multiplier, x * multiplier), unit);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,62 +44,6 @@ inline void bgc_vector2_set_values_fp64(const double x1, const double x2, BgcVec
|
|||
destination->x2 = x2;
|
||||
}
|
||||
|
||||
// ================= Directions ================= //
|
||||
|
||||
inline int bgc_vector2_get_direction_fp32(const int direction, BgcVector2FP32* vector)
|
||||
{
|
||||
switch (direction) {
|
||||
case BGC_DIRECTION_X1:
|
||||
vector->x1 = 1.0f;
|
||||
vector->x2 = 0.0f;
|
||||
return 1;
|
||||
|
||||
case BGC_DIRECTION_X2:
|
||||
vector->x1 = 0.0f;
|
||||
vector->x2 = 1.0f;
|
||||
return 1;
|
||||
|
||||
case -BGC_DIRECTION_X1:
|
||||
vector->x1 = -1.0f;
|
||||
vector->x2 = 0.0f;
|
||||
return 1;
|
||||
|
||||
case -BGC_DIRECTION_X2:
|
||||
vector->x1 = 0.0f;
|
||||
vector->x2 = -1.0f;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline int bgc_vector2_get_direction_fp64(const int direction, BgcVector2FP64* vector)
|
||||
{
|
||||
switch (direction) {
|
||||
case BGC_DIRECTION_X1:
|
||||
vector->x1 = 1.0;
|
||||
vector->x2 = 0.0;
|
||||
return 1;
|
||||
|
||||
case BGC_DIRECTION_X2:
|
||||
vector->x1 = 0.0;
|
||||
vector->x2 = 1.0;
|
||||
return 1;
|
||||
|
||||
case -BGC_DIRECTION_X1:
|
||||
vector->x1 = -1.0;
|
||||
vector->x2 = 0.0;
|
||||
return 1;
|
||||
|
||||
case -BGC_DIRECTION_X2:
|
||||
vector->x1 = 0.0;
|
||||
vector->x2 = -1.0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ================== Modulus =================== //
|
||||
|
||||
inline float bgc_vector2_get_square_modulus_fp32(const BgcVector2FP32* vector)
|
||||
|
|
@ -198,66 +142,6 @@ inline void bgc_vector2_convert_fp32_to_fp64(const BgcVector2FP32* source, BgcVe
|
|||
destination->x2 = source->x2;
|
||||
}
|
||||
|
||||
// ================== Reverse =================== //
|
||||
|
||||
inline void bgc_vector2_reverse_fp32(const BgcVector2FP32* vector, BgcVector2FP32* reverse)
|
||||
{
|
||||
reverse->x1 = -vector->x1;
|
||||
reverse->x2 = -vector->x2;
|
||||
}
|
||||
|
||||
inline void bgc_vector2_reverse_fp64(const BgcVector2FP64* vector, BgcVector2FP64* reverse)
|
||||
{
|
||||
reverse->x1 = -vector->x1;
|
||||
reverse->x2 = -vector->x2;
|
||||
}
|
||||
|
||||
// ================= Normalize ================== //
|
||||
|
||||
inline int bgc_vector2_normalize_fp32(const BgcVector2FP32* vector, BgcVector2FP32* normalized)
|
||||
{
|
||||
const float square_modulus = bgc_vector2_get_square_modulus_fp32(vector);
|
||||
|
||||
if (bgc_is_sqare_unit_fp32(square_modulus)) {
|
||||
normalized->x1 = vector->x1;
|
||||
normalized->x2 = vector->x2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float multiplicand = sqrtf(1.0f / square_modulus);
|
||||
|
||||
normalized->x1 = vector->x1 * multiplicand;
|
||||
normalized->x2 = vector->x2 * multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_vector2_normalize_fp64(const BgcVector2FP64* vector, BgcVector2FP64* normalized)
|
||||
{
|
||||
const double square_modulus = bgc_vector2_get_square_modulus_fp64(vector);
|
||||
|
||||
if (bgc_is_sqare_unit_fp64(square_modulus)) {
|
||||
normalized->x1 = vector->x1;
|
||||
normalized->x2 = vector->x2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double multiplicand = sqrt(1.0 / square_modulus);
|
||||
|
||||
normalized->x1 = vector->x1 * multiplicand;
|
||||
normalized->x2 = vector->x2 * multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ==================== Add ===================== //
|
||||
|
||||
inline void bgc_vector2_add_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, BgcVector2FP32* sum)
|
||||
|
|
@ -300,20 +184,6 @@ inline void bgc_vector2_subtract_fp64(const BgcVector2FP64* minuend, const BgcVe
|
|||
difference->x2 = minuend->x2 - subtrahend->x2;
|
||||
}
|
||||
|
||||
// ============== Subtract scaled =============== //
|
||||
|
||||
inline void bgc_vector2_subtract_scaled_fp32(const BgcVector2FP32* basic_vector, const BgcVector2FP32* scalable_vector, const float scale, BgcVector2FP32* difference)
|
||||
{
|
||||
difference->x1 = basic_vector->x1 - scalable_vector->x1 * scale;
|
||||
difference->x2 = basic_vector->x2 - scalable_vector->x2 * scale;
|
||||
}
|
||||
|
||||
inline void bgc_vector2_subtract_scaled_fp64(const BgcVector2FP64* basic_vector, const BgcVector2FP64* scalable_vector, const double scale, BgcVector2FP64* difference)
|
||||
{
|
||||
difference->x1 = basic_vector->x1 - scalable_vector->x1 * scale;
|
||||
difference->x2 = basic_vector->x2 - scalable_vector->x2 * scale;
|
||||
}
|
||||
|
||||
// ================== Multiply ================== //
|
||||
|
||||
inline void bgc_vector2_multiply_fp32(const BgcVector2FP32* multiplicand, const float multiplier, BgcVector2FP32* product)
|
||||
|
|
@ -340,7 +210,7 @@ inline void bgc_vector2_divide_fp64(const BgcVector2FP64* dividend, const double
|
|||
bgc_vector2_multiply_fp64(dividend, 1.0 / divisor, quotient);
|
||||
}
|
||||
|
||||
// ================== Average2 ================== //
|
||||
// ================ Mean of Two ================= //
|
||||
|
||||
inline void bgc_vector2_get_mean_of_two_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, BgcVector2FP32* mean)
|
||||
{
|
||||
|
|
@ -354,7 +224,7 @@ inline void bgc_vector2_get_mean_of_two_fp64(const BgcVector2FP64* vector1, cons
|
|||
mean->x2 = (vector1->x2 + vector2->x2) * 0.5;
|
||||
}
|
||||
|
||||
// ================== Average3 ================== //
|
||||
// =============== Mean of Three ================ //
|
||||
|
||||
inline void bgc_vector2_get_mean_of_three_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const BgcVector2FP32* vector3, BgcVector2FP32* mean)
|
||||
{
|
||||
|
|
@ -370,7 +240,7 @@ inline void bgc_vector2_get_mean_of_three_fp64(const BgcVector2FP64* vector1, co
|
|||
|
||||
// =================== Linear =================== //
|
||||
|
||||
inline void bgc_vector2_interpolate_linearly_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const float phase, BgcVector2FP32* interpolation)
|
||||
inline void bgc_vector2_interpolate_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const float phase, BgcVector2FP32* interpolation)
|
||||
{
|
||||
const float counterphase = 1.0f - phase;
|
||||
|
||||
|
|
@ -378,7 +248,7 @@ inline void bgc_vector2_interpolate_linearly_fp32(const BgcVector2FP32* vector1,
|
|||
interpolation->x2 = vector1->x2 * counterphase + vector2->x2 * phase;
|
||||
}
|
||||
|
||||
inline void bgc_vector2_interpolate_linearly_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, const double phase, BgcVector2FP64* interpolation)
|
||||
inline void bgc_vector2_interpolate_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, const double phase, BgcVector2FP64* interpolation)
|
||||
{
|
||||
const double counterphase = 1.0 - phase;
|
||||
|
||||
|
|
@ -386,52 +256,108 @@ inline void bgc_vector2_interpolate_linearly_fp64(const BgcVector2FP64* vector1,
|
|||
interpolation->x2 = vector1->x2 * counterphase + vector2->x2 * phase;
|
||||
}
|
||||
|
||||
// ================== Minimal =================== //
|
||||
// ================== Negative ================== //
|
||||
|
||||
inline void bgc_vector2_minimize_fp32(const BgcVector2FP32* vector, BgcVector2FP32* minimal)
|
||||
inline void bgc_vector2_make_opposite_fp32(BgcVector2FP32* vector)
|
||||
{
|
||||
if (vector->x1 < minimal->x1) {
|
||||
minimal->x1 = vector->x1;
|
||||
}
|
||||
|
||||
if (vector->x2 < minimal->x2) {
|
||||
minimal->x2 = vector->x2;
|
||||
}
|
||||
vector->x1 = -vector->x1;
|
||||
vector->x2 = -vector->x2;
|
||||
}
|
||||
|
||||
inline void bgc_vector2_minimize_fp64(const BgcVector2FP64* vector, BgcVector2FP64* minimal)
|
||||
inline void bgc_vector2_make_opposite_fp64(BgcVector2FP64* vector)
|
||||
{
|
||||
if (vector->x1 < minimal->x1) {
|
||||
minimal->x1 = vector->x1;
|
||||
}
|
||||
|
||||
if (vector->x2 < minimal->x2) {
|
||||
minimal->x2 = vector->x2;
|
||||
}
|
||||
vector->x1 = -vector->x1;
|
||||
vector->x2 = -vector->x2;
|
||||
}
|
||||
|
||||
// ================== Maximal =================== //
|
||||
|
||||
inline void bgc_vector2_maximize_fp32(const BgcVector2FP32* vector, BgcVector2FP32* maximal)
|
||||
inline void bgc_vector2_get_opposite_fp32(const BgcVector2FP32* vector, BgcVector2FP32* opposite)
|
||||
{
|
||||
if (vector->x1 > maximal->x1) {
|
||||
maximal->x1 = vector->x1;
|
||||
}
|
||||
|
||||
if (vector->x2 > maximal->x2) {
|
||||
maximal->x2 = vector->x2;
|
||||
}
|
||||
opposite->x1 = -vector->x1;
|
||||
opposite->x2 = -vector->x2;
|
||||
}
|
||||
|
||||
inline void bgc_vector2_maximize_fp64(const BgcVector2FP64* vector, BgcVector2FP64* maximal)
|
||||
inline void bgc_vector2_get_opposite_fp64(const BgcVector2FP64* vector, BgcVector2FP64* opposite)
|
||||
{
|
||||
if (vector->x1 > maximal->x1) {
|
||||
maximal->x1 = vector->x1;
|
||||
opposite->x1 = -vector->x1;
|
||||
opposite->x2 = -vector->x2;
|
||||
}
|
||||
|
||||
// ================= Normalize ================== //
|
||||
|
||||
inline int bgc_vector2_normalize_fp32(BgcVector2FP32* vector)
|
||||
{
|
||||
const float square_modulus = bgc_vector2_get_square_modulus_fp32(vector);
|
||||
|
||||
if (bgc_is_sqare_unit_fp32(square_modulus)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (vector->x2 > maximal->x2) {
|
||||
maximal->x2 = vector->x2;
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float multiplier = sqrtf(1.0f / square_modulus);
|
||||
|
||||
vector->x1 *= multiplier;
|
||||
vector->x2 *= multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_vector2_normalize_fp64(BgcVector2FP64* vector)
|
||||
{
|
||||
const double square_modulus = bgc_vector2_get_square_modulus_fp64(vector);
|
||||
|
||||
if (bgc_is_sqare_unit_fp64(square_modulus)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double multiplier = sqrt(1.0 / square_modulus);
|
||||
|
||||
vector->x1 *= multiplier;
|
||||
vector->x2 *= multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_vector2_get_normalized_fp32(const BgcVector2FP32* vector, BgcVector2FP32* normalized)
|
||||
{
|
||||
const float square_modulus = bgc_vector2_get_square_modulus_fp32(vector);
|
||||
|
||||
if (bgc_is_sqare_unit_fp32(square_modulus)) {
|
||||
bgc_vector2_copy_fp32(vector, normalized);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
bgc_vector2_reset_fp32(normalized);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_vector2_multiply_fp32(vector, sqrtf(1.0f / square_modulus), normalized);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_vector2_get_normalized_fp64(const BgcVector2FP64* vector, BgcVector2FP64* normalized)
|
||||
{
|
||||
const double square_modulus = bgc_vector2_get_square_modulus_fp64(vector);
|
||||
|
||||
if (bgc_is_sqare_unit_fp64(square_modulus)) {
|
||||
bgc_vector2_copy_fp64(vector, normalized);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
bgc_vector2_reset_fp64(normalized);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_vector2_multiply_fp64(vector, sqrt(1.0 / square_modulus), normalized);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ============= Get Scalar Product ============= //
|
||||
|
|
@ -468,16 +394,16 @@ double bgc_vector2_get_angle_fp64(const BgcVector2FP64* vector1, const BgcVector
|
|||
|
||||
inline float bgc_vector2_get_square_distance_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2)
|
||||
{
|
||||
const float dx1 = (vector1->x1 - vector2->x1);
|
||||
const float dx2 = (vector1->x2 - vector2->x2);
|
||||
const float dx1 = vector1->x1 - vector2->x1;
|
||||
const float dx2 = vector1->x2 - vector2->x2;
|
||||
|
||||
return dx1 * dx1 + dx2 * dx2;
|
||||
}
|
||||
|
||||
inline double bgc_vector2_get_square_distance_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2)
|
||||
{
|
||||
const double dx1 = (vector1->x1 - vector2->x1);
|
||||
const double dx2 = (vector1->x2 - vector2->x2);
|
||||
const double dx1 = vector1->x1 - vector2->x1;
|
||||
const double dx2 = vector1->x2 - vector2->x2;
|
||||
|
||||
return dx1 * dx1 + dx2 * dx2;
|
||||
}
|
||||
|
|
@ -496,14 +422,14 @@ inline double bgc_vector2_get_distance_fp64(const BgcVector2FP64* vector1, const
|
|||
|
||||
// ============== Are Close Enough ============== //
|
||||
|
||||
inline int bgc_vector2_are_close_enough_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const float distance)
|
||||
inline int bgc_vector2_are_close_enough_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const float distance_limit)
|
||||
{
|
||||
return bgc_vector2_get_square_distance_fp32(vector1, vector2) <= distance * distance;
|
||||
return bgc_vector2_get_square_distance_fp32(vector1, vector2) <= distance_limit * distance_limit;
|
||||
}
|
||||
|
||||
inline int bgc_vector2_are_close_enough_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, const double distance)
|
||||
inline int bgc_vector2_are_close_enough_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, const double distance_limit)
|
||||
{
|
||||
return bgc_vector2_get_square_distance_fp64(vector1, vector2) <= distance * distance;
|
||||
return bgc_vector2_get_square_distance_fp64(vector1, vector2) <= distance_limit * distance_limit;
|
||||
}
|
||||
|
||||
// ================== Are Close ================= //
|
||||
|
|
@ -531,7 +457,143 @@ inline int bgc_vector2_are_close_fp64(const BgcVector2FP64* vector1, const BgcVe
|
|||
return square_distance <= BGC_SQUARE_EPSYLON_FP64;
|
||||
}
|
||||
|
||||
return square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus1 && square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus2;
|
||||
return square_distance <= BGC_SQUARE_EPSYLON_FP64 * square_modulus1 && square_distance <= BGC_SQUARE_EPSYLON_FP64 * square_modulus2;
|
||||
}
|
||||
|
||||
|
||||
// ================== Parallel ================== //
|
||||
|
||||
inline int bgc_vector2_are_parallel_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2)
|
||||
{
|
||||
const float square_modulus1 = bgc_vector2_get_square_modulus_fp32(vector1);
|
||||
|
||||
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP32) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const float square_modulus2 = bgc_vector2_get_square_modulus_fp32(vector2);
|
||||
|
||||
if (square_modulus2 <= BGC_SQUARE_EPSYLON_FP32) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const float cross_product = bgc_vector2_get_cross_product_fp32(vector1, vector2);
|
||||
|
||||
return cross_product * cross_product <= BGC_SQUARE_EPSYLON_FP32 * square_modulus1 * square_modulus2;
|
||||
}
|
||||
|
||||
inline int bgc_vector2_are_parallel_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2)
|
||||
{
|
||||
const double square_modulus1 = bgc_vector2_get_square_modulus_fp64(vector1);
|
||||
|
||||
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP64) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const double square_modulus2 = bgc_vector2_get_square_modulus_fp64(vector2);
|
||||
|
||||
if (square_modulus2 <= BGC_SQUARE_EPSYLON_FP64) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const double cross_product = bgc_vector2_get_cross_product_fp64(vector1, vector2);
|
||||
|
||||
return cross_product * cross_product <= BGC_SQUARE_EPSYLON_FP64 * square_modulus1 * square_modulus2;
|
||||
}
|
||||
|
||||
// ================= Orthogonal ================= //
|
||||
|
||||
inline int bgc_vector2_are_orthogonal_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2)
|
||||
{
|
||||
const float square_modulus1 = bgc_vector2_get_square_modulus_fp32(vector1);
|
||||
|
||||
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP32) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const float square_modulus2 = bgc_vector2_get_square_modulus_fp32(vector2);
|
||||
|
||||
if (square_modulus2 <= BGC_SQUARE_EPSYLON_FP32) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const float scalar_product = bgc_vector2_get_scalar_product_fp32(vector1, vector2);
|
||||
|
||||
return scalar_product * scalar_product <= BGC_SQUARE_EPSYLON_FP32 * square_modulus1 * square_modulus2;
|
||||
}
|
||||
|
||||
inline int bgc_vector2_are_orthogonal_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2)
|
||||
{
|
||||
const double square_modulus1 = bgc_vector2_get_square_modulus_fp64(vector1);
|
||||
|
||||
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP64) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const double square_modulus2 = bgc_vector2_get_square_modulus_fp64(vector2);
|
||||
|
||||
if (square_modulus2 <= BGC_SQUARE_EPSYLON_FP64) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const double scalar_product = bgc_vector2_get_scalar_product_fp64(vector1, vector2);
|
||||
|
||||
return scalar_product * scalar_product <= BGC_SQUARE_EPSYLON_FP64 * square_modulus1 * square_modulus2;
|
||||
}
|
||||
|
||||
|
||||
// ================== Attitude ================== //
|
||||
|
||||
inline int bgc_vector2_get_attitude_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2)
|
||||
{
|
||||
const float square_modulus1 = bgc_vector2_get_square_modulus_fp32(vector1);
|
||||
const float square_modulus2 = bgc_vector2_get_square_modulus_fp32(vector2);
|
||||
|
||||
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP32 || square_modulus2 <= BGC_SQUARE_EPSYLON_FP32) {
|
||||
return BGC_ATTITUDE_ZERO;
|
||||
}
|
||||
|
||||
const float square_limit = BGC_SQUARE_EPSYLON_FP32 * square_modulus1 * square_modulus2;
|
||||
|
||||
const float scalar_product = bgc_vector2_get_scalar_product_fp32(vector1, vector2);
|
||||
|
||||
if (scalar_product * scalar_product <= square_limit) {
|
||||
return BGC_ATTITUDE_ORTHOGONAL;
|
||||
}
|
||||
|
||||
const float cross_product = bgc_vector2_get_cross_product_fp32(vector1, vector2);
|
||||
|
||||
if (cross_product * cross_product > square_limit) {
|
||||
return BGC_ATTITUDE_ANY;
|
||||
}
|
||||
|
||||
return scalar_product > 0.0f ? BGC_ATTITUDE_CO_DIRECTIONAL : BGC_ATTITUDE_COUNTER_DIRECTIONAL;
|
||||
}
|
||||
|
||||
inline int bgc_vector2_get_attitude_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2)
|
||||
{
|
||||
const double square_modulus1 = bgc_vector2_get_square_modulus_fp64(vector1);
|
||||
const double square_modulus2 = bgc_vector2_get_square_modulus_fp64(vector2);
|
||||
|
||||
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP64 || square_modulus2 <= BGC_SQUARE_EPSYLON_FP64) {
|
||||
return BGC_ATTITUDE_ZERO;
|
||||
}
|
||||
|
||||
const double square_limit = BGC_SQUARE_EPSYLON_FP64 * square_modulus1 * square_modulus2;
|
||||
|
||||
const double scalar_product = bgc_vector2_get_scalar_product_fp64(vector1, vector2);
|
||||
|
||||
if (scalar_product * scalar_product <= square_limit) {
|
||||
return BGC_ATTITUDE_ORTHOGONAL;
|
||||
}
|
||||
|
||||
const double cross_product = bgc_vector2_get_cross_product_fp64(vector1, vector2);
|
||||
|
||||
if (cross_product * cross_product > square_limit) {
|
||||
return BGC_ATTITUDE_ANY;
|
||||
}
|
||||
|
||||
return scalar_product > 0.0 ? BGC_ATTITUDE_CO_DIRECTIONAL : BGC_ATTITUDE_COUNTER_DIRECTIONAL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,9 +6,6 @@ extern inline void bgc_vector3_reset_fp64(BgcVector3FP64* vector);
|
|||
extern inline void bgc_vector3_set_values_fp32(const float x1, const float x2, const float x3, BgcVector3FP32* destination);
|
||||
extern inline void bgc_vector3_set_values_fp64(const double x1, const double x2, const double x3, BgcVector3FP64* destination);
|
||||
|
||||
inline int bgc_vector3_get_direction_fp32(const int direction, BgcVector3FP32* vector);
|
||||
inline int bgc_vector3_get_direction_fp64(const int direction, BgcVector3FP64* vector);
|
||||
|
||||
extern inline float bgc_vector3_get_square_modulus_fp32(const BgcVector3FP32* vector);
|
||||
extern inline double bgc_vector3_get_square_modulus_fp64(const BgcVector3FP64* vector);
|
||||
|
||||
|
|
@ -30,15 +27,6 @@ extern inline void bgc_vector3_convert_fp32_to_fp64(const BgcVector3FP32* source
|
|||
extern inline void bgc_vector3_swap_fp32(BgcVector3FP32* vector1, BgcVector3FP32* vector2);
|
||||
extern inline void bgc_vector3_swap_fp64(BgcVector3FP64* vector1, BgcVector3FP64* vector2);
|
||||
|
||||
extern inline void bgc_vector3_reverse_fp32(const BgcVector3FP32* vector, BgcVector3FP32* reverse);
|
||||
extern inline void bgc_vector3_reverse_fp64(const BgcVector3FP64* vector, BgcVector3FP64* reverse);
|
||||
|
||||
extern inline int bgc_vector3_normalize_fp32(BgcVector3FP32* vector);
|
||||