Добавление дополнительных операций умножения кватернионов, переименование функций для единообразия названий

This commit is contained in:
Andrey Pokidov 2026-03-29 12:19:03 +07:00
parent 078512c3d5
commit d83ab7160d
18 changed files with 379 additions and 177 deletions

View file

@ -298,98 +298,6 @@ inline void bgc_fp64_quaternion_multiply_by_real_number(BGC_FP64_Quaternion* con
product->x3 = multiplicand->x3 * multiplier;
}
// =========== Multiply By Quaternion =========== //
inline void bgc_fp32_quaternion_multiply_by_quaternion(BGC_FP32_Quaternion* const product, const BGC_FP32_Quaternion* const left, const BGC_FP32_Quaternion* const right)
{
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_fp64_quaternion_multiply_by_quaternion(BGC_FP64_Quaternion* const product, const BGC_FP64_Quaternion* const left, const BGC_FP64_Quaternion* const right)
{
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;
}
// ====== Multiply By Conjugate Quaternion ====== //
inline void bgc_fp32_quaternion_multiply_by_conjugate(BGC_FP32_Quaternion* const product, const BGC_FP32_Quaternion* const left, const BGC_FP32_Quaternion* const right)
{
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->x3 * right->x2) - (left->s0 * right->x1 + left->x2 * right->x3);
const float x2 = (left->x2 * right->s0 + left->x1 * right->x3) - (left->s0 * right->x2 + left->x3 * right->x1);
const float x3 = (left->x3 * right->s0 + left->x2 * right->x1) - (left->s0 * right->x3 + left->x1 * right->x2);
product->s0 = s0;
product->x1 = x1;
product->x2 = x2;
product->x3 = x3;
}
inline void bgc_fp64_quaternion_multiply_by_conjugate(BGC_FP64_Quaternion* const product, const BGC_FP64_Quaternion* const left, const BGC_FP64_Quaternion* const right)
{
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->x3 * right->x2) - (left->s0 * right->x1 + left->x2 * right->x3);
const double x2 = (left->x2 * right->s0 + left->x1 * right->x3) - (left->s0 * right->x2 + left->x3 * right->x1);
const double x3 = (left->x3 * right->s0 + left->x2 * right->x1) - (left->s0 * right->x3 + left->x1 * right->x2);
product->s0 = s0;
product->x1 = x1;
product->x2 = x2;
product->x3 = x3;
}
// ====== Restrict Multiply By Quaternion ======= //
inline void _bgc_fp32_restrict_quaternion_multiply_by_quaternion(BGC_FP32_Quaternion* restrict const product, const BGC_FP32_Quaternion* const left, const BGC_FP32_Quaternion* const right)
{
product->s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3);
product->x1 = (left->x1 * right->s0 + left->s0 * right->x1) - (left->x3 * right->x2 - left->x2 * right->x3);
product->x2 = (left->x2 * right->s0 + left->s0 * right->x2) - (left->x1 * right->x3 - left->x3 * right->x1);
product->x3 = (left->x3 * right->s0 + left->s0 * right->x3) - (left->x2 * right->x1 - left->x1 * right->x2);
}
inline void _bgc_fp64_restrict_quaternion_multiply_by_quaternion(BGC_FP64_Quaternion* restrict const product, const BGC_FP64_Quaternion* const left, const BGC_FP64_Quaternion* const right)
{
product->s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3);
product->x1 = (left->x1 * right->s0 + left->s0 * right->x1) - (left->x3 * right->x2 - left->x2 * right->x3);
product->x2 = (left->x2 * right->s0 + left->s0 * right->x2) - (left->x1 * right->x3 - left->x3 * right->x1);
product->x3 = (left->x3 * right->s0 + left->s0 * right->x3) - (left->x2 * right->x1 - left->x1 * right->x2);
}
// = Restrict Multiply By Conjugate Quaternion == //
inline void _bgc_fp32_restrict_quaternion_multiply_by_conjugate(BGC_FP32_Quaternion* restrict const product, const BGC_FP32_Quaternion* const left, const BGC_FP32_Quaternion* const right)
{
product->s0 = (left->s0 * right->s0 + left->x1 * right->x1) + (left->x2 * right->x2 + left->x3 * right->x3);
product->x1 = (left->x1 * right->s0 + left->x3 * right->x2) - (left->s0 * right->x1 + left->x2 * right->x3);
product->x2 = (left->x2 * right->s0 + left->x1 * right->x3) - (left->s0 * right->x2 + left->x3 * right->x1);
product->x3 = (left->x3 * right->s0 + left->x2 * right->x1) - (left->s0 * right->x3 + left->x1 * right->x2);
}
inline void _bgc_fp64_restrict_quaternion_multiply_by_conjugate(BGC_FP64_Quaternion* restrict const product, const BGC_FP64_Quaternion* const left, const BGC_FP64_Quaternion* const right)
{
product->s0 = (left->s0 * right->s0 + left->x1 * right->x1) + (left->x2 * right->x2 + left->x3 * right->x3);
product->x1 = (left->x1 * right->s0 + left->x3 * right->x2) - (left->s0 * right->x1 + left->x2 * right->x3);
product->x2 = (left->x2 * right->s0 + left->x1 * right->x3) - (left->s0 * right->x2 + left->x3 * right->x1);
product->x3 = (left->x3 * right->s0 + left->x2 * right->x1) - (left->s0 * right->x3 + left->x1 * right->x2);
}
// ========== Multiply By Dual Number =========== //
inline void bgc_fp32_quaternion_multiply_by_dual_number(BGC_FP32_DualQuaternion* const product, const BGC_FP32_Quaternion* const multiplicand, const BGC_FP32_DualNumber* const multiplier)
@ -466,6 +374,154 @@ inline void _bgc_fp64_restrict_quaternion_multiply_by_dual_number(BGC_FP64_DualQ
product->dual_part.x3 = multiplicand->x3 * multiplier->dual_part;
}
// =========== Multiply By Quaternion =========== //
inline void bgc_fp32_quaternion_multiply_by_quaternion(BGC_FP32_Quaternion* const product, const BGC_FP32_Quaternion* const left, const BGC_FP32_Quaternion* const right)
{
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_fp64_quaternion_multiply_by_quaternion(BGC_FP64_Quaternion* const product, const BGC_FP64_Quaternion* const left, const BGC_FP64_Quaternion* const right)
{
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;
}
// ====== Multiply By Conjugate Quaternion ====== //
inline void bgc_fp32_quaternion_multiply_by_conjugate(BGC_FP32_Quaternion* const product, const BGC_FP32_Quaternion* const left, const BGC_FP32_Quaternion* const right)
{
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->x3 * right->x2) - (left->s0 * right->x1 + left->x2 * right->x3);
const float x2 = (left->x2 * right->s0 + left->x1 * right->x3) - (left->s0 * right->x2 + left->x3 * right->x1);
const float x3 = (left->x3 * right->s0 + left->x2 * right->x1) - (left->s0 * right->x3 + left->x1 * right->x2);
product->s0 = s0;
product->x1 = x1;
product->x2 = x2;
product->x3 = x3;
}
inline void bgc_fp64_quaternion_multiply_by_conjugate(BGC_FP64_Quaternion* const product, const BGC_FP64_Quaternion* const left, const BGC_FP64_Quaternion* const right)
{
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->x3 * right->x2) - (left->s0 * right->x1 + left->x2 * right->x3);
const double x2 = (left->x2 * right->s0 + left->x1 * right->x3) - (left->s0 * right->x2 + left->x3 * right->x1);
const double x3 = (left->x3 * right->s0 + left->x2 * right->x1) - (left->s0 * right->x3 + left->x1 * right->x2);
product->s0 = s0;
product->x1 = x1;
product->x2 = x2;
product->x3 = x3;
}
// ====== Multiply Conjugate By Quaternion ====== //
inline void bgc_fp32_conjugate_quaternion_multiply_by_quaternion(BGC_FP32_Quaternion* const product, const BGC_FP32_Quaternion* const left, const BGC_FP32_Quaternion* const right)
{
const float s0 = (left->s0 * right->s0 + left->x1 * right->x1) + (left->x2 * right->x2 + left->x3 * right->x3);
const float x1 = (left->s0 * right->x1 - left->x1 * right->s0) + (left->x3 * right->x2 - left->x2 * right->x3);
const float x2 = (left->s0 * right->x2 - left->x2 * right->s0) + (left->x1 * right->x3 - left->x3 * right->x1);
const float x3 = (left->s0 * right->x3 - left->x3 * right->s0) + (left->x2 * right->x1 - left->x1 * right->x2);
product->s0 = s0;
product->x1 = x1;
product->x2 = x2;
product->x3 = x3;
}
inline void bgc_fp64_conjugate_quaternion_multiply_by_quaternion(BGC_FP64_Quaternion* const product, const BGC_FP64_Quaternion* const left, const BGC_FP64_Quaternion* const right)
{
const double s0 = (left->s0 * right->s0 + left->x1 * right->x1) + (left->x2 * right->x2 + left->x3 * right->x3);
const double x1 = (left->s0 * right->x1 - left->x1 * right->s0) + (left->x3 * right->x2 - left->x2 * right->x3);
const double x2 = (left->s0 * right->x2 - left->x2 * right->s0) + (left->x1 * right->x3 - left->x3 * right->x1);
const double x3 = (left->s0 * right->x3 - left->x3 * right->s0) + (left->x2 * right->x1 - left->x1 * right->x2);
product->s0 = s0;
product->x1 = x1;
product->x2 = x2;
product->x3 = x3;
}
// ====== Multiply Conjugate By Conjugate ======= //
inline void bgc_fp32_conjugate_quaternion_multiply_by_conjugate(BGC_FP32_Quaternion* const product, const BGC_FP32_Quaternion* const left, const BGC_FP32_Quaternion* const right)
{
const float s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3);
const float x1 = (left->x2 * right->x3 - left->x3 * right->x2) - (left->x1 * right->s0 + left->s0 * right->x1);
const float x2 = (left->x3 * right->x1 - left->x1 * right->x3) - (left->x2 * right->s0 + left->s0 * right->x2);
const float x3 = (left->x1 * right->x2 - left->x2 * right->x1) - (left->x3 * right->s0 + left->s0 * right->x3);
product->s0 = s0;
product->x1 = x1;
product->x2 = x2;
product->x3 = x3;
}
inline void bgc_fp64_conjugate_quaternion_multiply_by_conjugate(BGC_FP64_Quaternion* const product, const BGC_FP64_Quaternion* const left, const BGC_FP64_Quaternion* const right)
{
const double s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3);
const double x1 = (left->x2 * right->x3 - left->x3 * right->x2) - (left->x1 * right->s0 + left->s0 * right->x1);
const double x2 = (left->x3 * right->x1 - left->x1 * right->x3) - (left->x2 * right->s0 + left->s0 * right->x2);
const double x3 = (left->x1 * right->x2 - left->x2 * right->x1) - (left->x3 * right->s0 + left->s0 * right->x3);
product->s0 = s0;
product->x1 = x1;
product->x2 = x2;
product->x3 = x3;
}
// ====== Restrict Multiply By Quaternion ======= //
inline void _bgc_fp32_restrict_quaternion_multiply_by_quaternion(BGC_FP32_Quaternion* restrict const product, const BGC_FP32_Quaternion* const left, const BGC_FP32_Quaternion* const right)
{
product->s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3);
product->x1 = (left->x1 * right->s0 + left->s0 * right->x1) - (left->x3 * right->x2 - left->x2 * right->x3);
product->x2 = (left->x2 * right->s0 + left->s0 * right->x2) - (left->x1 * right->x3 - left->x3 * right->x1);
product->x3 = (left->x3 * right->s0 + left->s0 * right->x3) - (left->x2 * right->x1 - left->x1 * right->x2);
}
inline void _bgc_fp64_restrict_quaternion_multiply_by_quaternion(BGC_FP64_Quaternion* restrict const product, const BGC_FP64_Quaternion* const left, const BGC_FP64_Quaternion* const right)
{
product->s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3);
product->x1 = (left->x1 * right->s0 + left->s0 * right->x1) - (left->x3 * right->x2 - left->x2 * right->x3);
product->x2 = (left->x2 * right->s0 + left->s0 * right->x2) - (left->x1 * right->x3 - left->x3 * right->x1);
product->x3 = (left->x3 * right->s0 + left->s0 * right->x3) - (left->x2 * right->x1 - left->x1 * right->x2);
}
// = Restrict Multiply By Conjugate Quaternion == //
inline void _bgc_fp32_restrict_quaternion_multiply_by_conjugate(BGC_FP32_Quaternion* restrict const product, const BGC_FP32_Quaternion* const left, const BGC_FP32_Quaternion* const right)
{
product->s0 = (left->s0 * right->s0 + left->x1 * right->x1) + (left->x2 * right->x2 + left->x3 * right->x3);
product->x1 = (left->x1 * right->s0 + left->x3 * right->x2) - (left->s0 * right->x1 + left->x2 * right->x3);
product->x2 = (left->x2 * right->s0 + left->x1 * right->x3) - (left->s0 * right->x2 + left->x3 * right->x1);
product->x3 = (left->x3 * right->s0 + left->x2 * right->x1) - (left->s0 * right->x3 + left->x1 * right->x2);
}
inline void _bgc_fp64_restrict_quaternion_multiply_by_conjugate(BGC_FP64_Quaternion* restrict const product, const BGC_FP64_Quaternion* const left, const BGC_FP64_Quaternion* const right)
{
product->s0 = (left->s0 * right->s0 + left->x1 * right->x1) + (left->x2 * right->x2 + left->x3 * right->x3);
product->x1 = (left->x1 * right->s0 + left->x3 * right->x2) - (left->s0 * right->x1 + left->x2 * right->x3);
product->x2 = (left->x2 * right->s0 + left->x1 * right->x3) - (left->s0 * right->x2 + left->x3 * right->x1);
product->x3 = (left->x3 * right->s0 + left->x2 * right->x1) - (left->s0 * right->x3 + left->x1 * right->x2);
}
// ======== Multiply By Dual Quaternion ========= //
inline void bgc_fp32_quaternion_multiply_by_dual_quaternion(BGC_FP32_DualQuaternion* const product, const BGC_FP32_Quaternion* const left, const BGC_FP32_DualQuaternion* const right)