Добавлены функции модуля для версоров и кватернионо / Functions of modulus have been added for versors and quaternions

This commit is contained in:
Andrey Pokidov 2024-11-25 19:47:45 +07:00
parent bef7ab98f4
commit 03e390c1d0
12 changed files with 246 additions and 211 deletions

View file

@ -58,9 +58,9 @@ static inline void bg_fp64_versor_reset(BgFP64Versor* versor)
// ==================== Set ===================== //
void __bg_fp32_versor_normalize(const float square_module, __BgFP32DarkTwinVersor* twin);
void __bg_fp32_versor_normalize(const float square_modulus, __BgFP32DarkTwinVersor* twin);
void __bg_fp64_versor_normalize(const double square_module, __BgFP64DarkTwinVersor* twin);
void __bg_fp64_versor_normalize(const double square_modulus, __BgFP64DarkTwinVersor* twin);
static inline void bg_fp32_versor_set_values(const float s0, const float x1, const float x2, const float x3, BgFP32Versor* versor)
{
@ -71,13 +71,13 @@ static inline void bg_fp32_versor_set_values(const float s0, const float x1, con
twin->x2 = x2;
twin->x3 = x3;
const float square_module = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
const float square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
if (1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON) {
if (1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON) {
return;
}
__bg_fp32_versor_normalize(square_module, (__BgFP32DarkTwinVersor*)versor);
__bg_fp32_versor_normalize(square_modulus, (__BgFP32DarkTwinVersor*)versor);
}
static inline void bg_fp64_versor_set_values(const double s0, const double x1, const double x2, const double x3, BgFP64Versor* versor)
@ -89,13 +89,13 @@ static inline void bg_fp64_versor_set_values(const double s0, const double x1, c
twin->x2 = x2;
twin->x3 = x3;
const double square_module = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
const double square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
if (1.0 - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0 + BG_FP64_TWO_EPSYLON) {
if (1.0 - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + BG_FP64_TWO_EPSYLON) {
return;
}
__bg_fp64_versor_normalize(square_module, twin);
__bg_fp64_versor_normalize(square_modulus, twin);
}
// ==================== Copy ==================== //
@ -150,6 +150,30 @@ static inline void bg_fp64_versor_set_rotation(const BgFP64Rotation3* rotation,
bg_fp64_versor_set_crude_turn(rotation->axis.x1, rotation->axis.x2, rotation->axis.x3, rotation->radians, BG_ANGLE_UNIT_RADIANS, result);
}
// =============== Square modulus =============== //
static inline int bg_fp32_versor_get_square_modulus(const BgFP32Versor* versor)
{
return (versor->s0 * versor->s0 + versor->x1 * versor->x1) + (versor->x2 * versor->x2 + versor->x3 * versor->x3);
}
static inline int bg_fp64_versor_get_square_modulus(const BgFP64Versor* versor)
{
return (versor->s0 * versor->s0 + versor->x1 * versor->x1) + (versor->x2 * versor->x2 + versor->x3 * versor->x3);
}
// =================== Modulus ================== //
static inline int bg_fp32_versor_get_modulus(const BgFP32Versor* versor)
{
return sqrtf(bg_fp32_versor_get_square_modulus(versor));
}
static inline int bg_fp64_versor_get_modulus(const BgFP64Versor* versor)
{
return sqrt(bg_fp64_versor_get_square_modulus(versor));
}
// ================= Comparison ================= //
static inline int bg_fp32_versor_is_idle(const BgFP32Versor* versor)
@ -257,7 +281,7 @@ static inline void bg_fp32_versor_combine(const BgFP32Versor* second, const BgFP
const float x2 = (second->x2 * first->s0 + second->s0 * first->x2) - (second->x1 * first->x3 - second->x3 * first->x1);
const float x3 = (second->x3 * first->s0 + second->s0 * first->x3) - (second->x2 * first->x1 - second->x1 * first->x2);
const float square_module = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
const float square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
__BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)result;
@ -266,11 +290,11 @@ static inline void bg_fp32_versor_combine(const BgFP32Versor* second, const BgFP
twin->x2 = x2;
twin->x3 = x3;
if (1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON) {
if (1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON) {
return;
}
__bg_fp32_versor_normalize(square_module, twin);
__bg_fp32_versor_normalize(square_modulus, twin);
}
static inline void bg_fp64_versor_combine(const BgFP64Versor* second, const BgFP64Versor* first, BgFP64Versor* result)
@ -280,7 +304,7 @@ static inline void bg_fp64_versor_combine(const BgFP64Versor* second, const BgFP
const double x2 = (second->x2 * first->s0 + second->s0 * first->x2) - (second->x1 * first->x3 - second->x3 * first->x1);
const double x3 = (second->x3 * first->s0 + second->s0 * first->x3) - (second->x2 * first->x1 - second->x1 * first->x2);
const double square_module = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
const double square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
__BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)result;
@ -289,11 +313,11 @@ static inline void bg_fp64_versor_combine(const BgFP64Versor* second, const BgFP
twin->x2 = x2;
twin->x3 = x3;
if (1.0 - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0 + BG_FP64_TWO_EPSYLON) {
if (1.0 - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + BG_FP64_TWO_EPSYLON) {
return;
}
__bg_fp64_versor_normalize(square_module, twin);
__bg_fp64_versor_normalize(square_modulus, twin);
}
// ================= Rotation3 ================== //