Добавлены функции модуля для версоров и кватернионо / 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

@ -57,7 +57,7 @@ void print_versor(const BgFP32Versor* versor)
void print_vector(const BgFP32Vector3* vector)
{
printf("(%f, %f, %f) / %f\n", vector->x1, vector->x2, vector->x3, bg_fp32_vector3_get_module(vector));
printf("(%f, %f, %f) / %f\n", vector->x1, vector->x2, vector->x3, bg_fp32_vector3_get_modulus(vector));
}
/*
int main()
@ -120,7 +120,6 @@ int main()
}
*/
/*
int main()
{
const unsigned int amount = 1000000;
@ -130,7 +129,7 @@ int main()
now = GetTickCount64();
srand((unsigned int)(now & 0xfffffff));
#else
timespec now;
struct timespec now;
clock_gettime(0, &now);
srand((unsigned int)(now.tv_nsec & 0xfffffff));
#endif // _WIN64
@ -191,14 +190,3 @@ int main()
free(versors1);
return 0;
}
*/
int main() {
BgFP32Versor versor;
bg_fp32_versor_reset(&versor);
printf("Versor: (%f, %f, %f, %f)\n", versor.s0, versor.x1, versor.x2, versor.x3);
return 0;
}

View file

@ -18,20 +18,20 @@ const BgFP32Vector2 TEST_BG_FP32_VECTOR2_COMMON_2[] = {
{ 1.5f, -23.35f }
};
// =============== Square module ================ //
// =============== Square modulus =============== //
const float BG_FP32_VECTOR2_SQUARE_MODULE_1[] = { 25.0f, 25.0f, 500000000.0f, 100.01f, 15266.150221f };
const float BG_FP32_VECTOR2_SQUARE_MODULUS_1[] = { 25.0f, 25.0f, 500000000.0f, 100.01f, 15266.150221f };
int test_bg_fp32_vector2_square_module()
int test_bg_fp32_vector2_square_modulus()
{
print_test_name("BgFP32Vector2 square module");
print_test_name("BgFP32Vector2 square modulus");
float square_module;
float square_modulus;
for (int i = 0; i < TEST_BG_FP32_VECTOR2_AMOUNT_1; i++) {
square_module = bg_fp32_vector2_get_square_module(&TEST_BG_FP32_VECTOR2_COMMON_1[i]);
square_modulus = bg_fp32_vector2_get_square_modulus(&TEST_BG_FP32_VECTOR2_COMMON_1[i]);
if (!test_bg_fp32_are_equal(square_module, BG_FP32_VECTOR2_SQUARE_MODULE_1[i], TEST_BG_FP32_TWO_EPSYLON)) {
if (!test_bg_fp32_are_equal(square_modulus, BG_FP32_VECTOR2_SQUARE_MODULUS_1[i], TEST_BG_FP32_TWO_EPSYLON)) {
print_test_failed();
return TEST_RESULT_FAILED;
}
@ -43,18 +43,18 @@ int test_bg_fp32_vector2_square_module()
// =================== Module =================== //
const float BG_FP32_VECTOR2_MODULE_1[] = { 5.0f, 5.0f, 22360.68f, 10.0005f, 123.55626338f };
const float BG_FP32_VECTOR2_MODULUS_1[] = { 5.0f, 5.0f, 22360.68f, 10.0005f, 123.55626338f };
int test_bg_fp32_vector2_module()
int test_bg_fp32_vector2_modulus()
{
print_test_name("BgFP32Vector2 module");
print_test_name("BgFP32Vector2 modulus");
float square_module;
float square_modulus;
for (int i = 0; i < TEST_BG_FP32_VECTOR2_AMOUNT_1; i++) {
square_module = bg_fp32_vector2_get_module(&TEST_BG_FP32_VECTOR2_COMMON_1[i]);
square_modulus = bg_fp32_vector2_get_modulus(&TEST_BG_FP32_VECTOR2_COMMON_1[i]);
if (!test_bg_fp32_are_equal(square_module, BG_FP32_VECTOR2_MODULE_1[i], TEST_BG_FP32_EPSYLON)) {
if (!test_bg_fp32_are_equal(square_modulus, BG_FP32_VECTOR2_MODULUS_1[i], TEST_BG_FP32_EPSYLON)) {
print_test_failed();
return TEST_RESULT_FAILED;
}
@ -130,11 +130,11 @@ int test_bg_fp32_vector2()
{
print_test_section("BgFP32Vector2");
if (test_bg_fp32_vector2_square_module() != TEST_RESULT_SUCCES) {
if (test_bg_fp32_vector2_square_modulus() != TEST_RESULT_SUCCES) {
return TEST_RESULT_FAILED;
}
if (test_bg_fp32_vector2_module() != TEST_RESULT_SUCCES) {
if (test_bg_fp32_vector2_modulus() != TEST_RESULT_SUCCES) {
return TEST_RESULT_FAILED;
}

View file

@ -5,9 +5,9 @@
int test_bg_fp32_vector2();
int test_bg_fp32_vector2_square_module();
int test_bg_fp32_vector2_square_modulus();
int test_bg_fp32_vector2_module();
int test_bg_fp32_vector2_modulus();
int test_bg_fp32_vector2_add();

View file

@ -9,15 +9,15 @@ void bg_fp32_quaternion_get_rotation_matrix(const BgFP32Quaternion* quaternion,
const float x2x2 = quaternion->x2 * quaternion->x2;
const float x3x3 = quaternion->x3 * quaternion->x3;
const float square_module = (s0s0 + x1x1) + (x2x2 + x3x3);
const float square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
if (-BG_FP32_EPSYLON <= square_module && square_module <= BG_FP32_EPSYLON)
if (-BG_FP32_EPSYLON <= square_modulus && square_modulus <= BG_FP32_EPSYLON)
{
bg_fp32_matrix3x3_set_to_identity(matrix);
return;
}
const float corrector1 = 1.0f / square_module;
const float corrector1 = 1.0f / square_modulus;
const float corrector2 = 2.0f * corrector1;
const float s0x1 = quaternion->s0 * quaternion->x1;
@ -47,15 +47,15 @@ void bg_fp64_quaternion_get_rotation_matrix(const BgFP64Quaternion* quaternion,
const double x2x2 = quaternion->x2 * quaternion->x2;
const double x3x3 = quaternion->x3 * quaternion->x3;
const double square_module = (s0s0 + x1x1) + (x2x2 + x3x3);
const double square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
if (-BG_FP64_EPSYLON <= square_module && square_module <= BG_FP64_EPSYLON)
if (-BG_FP64_EPSYLON <= square_modulus && square_modulus <= BG_FP64_EPSYLON)
{
bg_fp64_matrix3x3_set_to_identity(matrix);
return;
}
const double corrector1 = 1.0f / square_module;
const double corrector1 = 1.0f / square_modulus;
const double corrector2 = 2.0f * corrector1;
const double s0x1 = quaternion->s0 * quaternion->x1;
@ -87,15 +87,15 @@ void bg_fp32_quaternion_get_reverse_matrix(const BgFP32Quaternion* quaternion, B
const float x2x2 = quaternion->x2 * quaternion->x2;
const float x3x3 = quaternion->x3 * quaternion->x3;
const float square_module = (s0s0 + x1x1) + (x2x2 + x3x3);
const float square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
if (-BG_FP32_EPSYLON <= square_module && square_module <= BG_FP32_EPSYLON)
if (-BG_FP32_EPSYLON <= square_modulus && square_modulus <= BG_FP32_EPSYLON)
{
bg_fp32_matrix3x3_set_to_identity(matrix);
return;
}
const float corrector1 = 1.0f / square_module;
const float corrector1 = 1.0f / square_modulus;
const float corrector2 = 2.0f * corrector1;
const float s0x1 = quaternion->s0 * quaternion->x1;
@ -125,15 +125,15 @@ void bg_fp64_quaternion_get_reverse_matrix(const BgFP64Quaternion* quaternion, B
const double x2x2 = quaternion->x2 * quaternion->x2;
const double x3x3 = quaternion->x3 * quaternion->x3;
const double square_module = (s0s0 + x1x1) + (x2x2 + x3x3);
const double square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
if (-BG_FP64_EPSYLON <= square_module && square_module <= BG_FP64_EPSYLON)
if (-BG_FP64_EPSYLON <= square_modulus && square_modulus <= BG_FP64_EPSYLON)
{
bg_fp64_matrix3x3_set_to_identity(matrix);
return;
}
const double corrector1 = 1.0f / square_module;
const double corrector1 = 1.0f / square_modulus;
const double corrector2 = 2.0f * corrector1;
const double s0x1 = quaternion->s0 * quaternion->x1;

View file

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

500

Internal server error

Forgejo version: 11.0.1+gitea-1.22.0

@ -89,72 +89,96 @@ static inline void bg_fp64_quaternion_copy(const BgFP64Quaternion* from, BgFP64Q
// ============= Copy to twin type ============== //
static inline void bg_fp32_quaternion_set_from_fp64(const BgFP64Quaternion* versor, BgFP32Quaternion* result)