Развитие структуры Posture3 для хранения пложения тела в виде нормализованного дуального кватерниона

This commit is contained in:
Andrey Pokidov 2026-02-26 02:36:03 +07:00
parent 0c27a6e59b
commit add4d89c80
3 changed files with 109 additions and 24 deletions

View file

@ -3,10 +3,18 @@
extern inline void bgc_fp32_posture3_reset(BGC_FP32_Posture3* posture);
extern inline void bgc_fp64_posture3_reset(BGC_FP64_Posture3* posture);
void _bgc_fp32_posture3_normalize(BGC_FP32_Posture3* posture)
{
const float square_magnitude = bgc_fp32_quaternion_get_square_magnitude(&posture->_dual_versor.real_part);
extern inline void bgc_fp32_posture3_copy(BGC_FP32_Posture3* destination, const BGC_FP32_Posture3* source);
extern inline void bgc_fp64_posture3_copy(BGC_FP64_Posture3* destination, const BGC_FP64_Posture3* source);
extern inline void bgc_fp32_posture3_swap(BGC_FP32_Posture3* posture1, BGC_FP32_Posture3* posture2);
extern inline void bgc_fp64_posture3_swap(BGC_FP64_Posture3* posture1, BGC_FP64_Posture3* posture2);
extern inline void bgc_fp32_posture3_convert_to_fp64(BGC_FP64_Posture3* destination, const BGC_FP32_Posture3* source);
extern inline void bgc_fp64_posture3_convert_to_fp32(BGC_FP32_Posture3* destination, const BGC_FP64_Posture3* source);
void _bgc_fp32_posture3_normalize(BGC_FP32_Posture3* posture, const float square_magnitude)
{
if (square_magnitude <= BGC_FP32_SQUARE_EPSILON || isnan(square_magnitude)) {
bgc_fp32_posture3_reset(posture);
return;
@ -14,6 +22,19 @@ void _bgc_fp32_posture3_normalize(BGC_FP32_Posture3* posture)
const float multiplier = sqrtf(1.0f / square_magnitude);
bgc_fp32_quaternion_multiply_by_real(&posture->_dual_versor.real_part, &posture->_dual_versor.real_part, multiplier);
bgc_fp32_quaternion_multiply_by_real(&posture->_dual_versor.dual_part, &posture->_dual_versor.dual_part, multiplier);
bgc_fp32_quaternion_multiply_by_real(&posture->_real_part, &posture->_real_part, multiplier);
bgc_fp32_quaternion_multiply_by_real(&posture->_dual_part, &posture->_dual_part, multiplier);
}
void _bgc_fp64_posture3_normalize(BGC_FP64_Posture3* posture, const double square_magnitude)
{
if (square_magnitude <= BGC_FP64_SQUARE_EPSILON || isnan(square_magnitude)) {
bgc_fp64_posture3_reset(posture);
return;
}
const double multiplier = sqrt(1.0 / square_magnitude);
bgc_fp64_quaternion_multiply_by_real(&posture->_real_part, &posture->_real_part, multiplier);
bgc_fp64_quaternion_multiply_by_real(&posture->_dual_part, &posture->_dual_part, multiplier);
}