Отказ от терминов Versor и Cotes Number в пользу Turn3 и Turn2, использование кватернионов внутри Turn3
This commit is contained in:
parent
38cff7e27d
commit
b470a3194b
27 changed files with 1815 additions and 2045 deletions
|
|
@ -40,7 +40,7 @@ BGC_FP32_Affine3* _create_bgc_affine3_random_list(int affine_amount)
|
|||
BGC_FP32_Position3 position;
|
||||
|
||||
for (int i = 0; i < affine_amount; i++) {
|
||||
bgc_fp32_versor_make(
|
||||
bgc_fp32_turn3_set_raw_values(
|
||||
&position.turn,
|
||||
get_random_value_fp32(),
|
||||
get_random_value_fp32(),
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
#endif // _WINDOWS_
|
||||
|
||||
typedef struct {
|
||||
BGC_FP32_Versor versor1, versor2, result;
|
||||
BGC_FP32_Turn3 versor1, versor2, result;
|
||||
} structure_fp32_t;
|
||||
|
||||
structure_fp32_t* allocate_structures(const unsigned int amount)
|
||||
|
|
@ -29,7 +29,7 @@ structure_fp32_t* make_structures(const unsigned int amount)
|
|||
const float multiplier = 2.0f / RAND_MAX;
|
||||
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
bgc_fp32_versor_make(
|
||||
bgc_fp32_turn3_set_raw_values(
|
||||
&list[i].versor1,
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
|
|
@ -37,7 +37,7 @@ structure_fp32_t* make_structures(const unsigned int amount)
|
|||
rand() * multiplier - 1.0f
|
||||
);
|
||||
|
||||
bgc_fp32_versor_make(
|
||||
bgc_fp32_turn3_set_raw_values(
|
||||
&list[i].versor2,
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
|
|
@ -45,20 +45,20 @@ structure_fp32_t* make_structures(const unsigned int amount)
|
|||
rand() * multiplier - 1.0f
|
||||
);
|
||||
|
||||
bgc_fp32_versor_reset(&list[i].result);
|
||||
bgc_fp32_turn3_reset(&list[i].result);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void print_versor_fp32(const BGC_FP32_Versor* versor)
|
||||
void print_quaternion_fp32(const BGC_FP32_Quaternion* quaternion)
|
||||
{
|
||||
printf("Versor (s0 = %0.12f, x1 = %0.12f, x2 = %0.12f, x3 = %0.12f)\n", versor->_s0, versor->_x1, versor->_x2, versor->_x3);
|
||||
printf("Quaternion FP32(s0 = %0.12f, x1 = %0.12f, x2 = %0.12f, x3 = %0.12f)\n", quaternion->s0, quaternion->x1, quaternion->x2, quaternion->x3);
|
||||
}
|
||||
|
||||
void print_versor_fp64(const BGC_FP64_Versor* versor)
|
||||
void print_quaternion_fp64(const BGC_FP64_Quaternion* quaternion)
|
||||
{
|
||||
printf("Versor (s0 = %0.20f, x1 = %0.20f, x2 = %0.20f, x3 = %0.20f)\n", versor->_s0, versor->_x1, versor->_x2, versor->_x3);
|
||||
printf("Quaternion FP64(s0 = %0.12f, x1 = %0.12f, x2 = %0.12f, x3 = %0.12f)\n", quaternion->s0, quaternion->x1, quaternion->x2, quaternion->x3);
|
||||
}
|
||||
|
||||
void print_vector_fp32(const BGC_FP32_Vector3* vector)
|
||||
|
|
@ -75,11 +75,11 @@ void list_work(const uint_fast32_t amount, structure_fp32_t* list)
|
|||
{
|
||||
for (uint_fast32_t j = 0; j < 1000; j++) {
|
||||
for (uint_fast32_t i = 0; i < amount; i++) {
|
||||
bgc_fp32_versor_combine(&list[i].versor1, &list[i].versor1, &list[i].result);
|
||||
bgc_fp32_turn3_combine(&list[i].result, &list[i].versor1, &list[i].versor2);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
int main()
|
||||
{
|
||||
const unsigned int amount = 1000000;
|
||||
|
|
@ -113,15 +113,15 @@ int main()
|
|||
printf("Time: %lf\n", (end.tv_sec - start.tv_sec) * 1000.0 + (end.tv_nsec - start.tv_nsec) * 0.000001);
|
||||
#endif // _WIN64
|
||||
|
||||
print_versor_fp32(&list[10].versor1);
|
||||
print_versor_fp32(&list[10].versor2);
|
||||
print_versor_fp32(&list[10].result);
|
||||
print_quaternion_fp32(&list[10].versor1._versor);
|
||||
print_quaternion_fp32(&list[10].versor2._versor);
|
||||
print_quaternion_fp32(&list[10].result._versor);
|
||||
|
||||
free(list);
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
int main() {
|
||||
|
|
@ -140,10 +140,10 @@ int main() {
|
|||
*/
|
||||
/*
|
||||
int main() {
|
||||
BGC_FP32_Versor start = { 1.0f, 0.0f, 0.0f, 0.0f };
|
||||
BGC_FP32_Versor end = { 0.0f, 1.0f, 0.0f, 0.0f };
|
||||
BGC_FP32_Versor result;
|
||||
bgc_fp32_versor_spherical_interpolation(&start, &end, 0.5f, &result);
|
||||
BGC_FP32_Turn3 start = { 1.0f, 0.0f, 0.0f, 0.0f };
|
||||
BGC_FP32_Turn3 end = { 0.0f, 1.0f, 0.0f, 0.0f };
|
||||
BGC_FP32_Turn3 result;
|
||||
bgc_fp32_turn3_spherical_interpolation(&start, &end, 0.5f, &result);
|
||||
printf("Result: %0.12f, %0.12f, %0.12f, %0.12f\n", result.s0, result.x1, result.x2, result.x3);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -154,7 +154,7 @@ void test_basis_difference_fp32()
|
|||
|
||||
BGC_FP32_Vector3 initial_primary, initial_auxiliary;
|
||||
BGC_FP32_Vector3 final_primary, final_auxiliary;
|
||||
BGC_FP32_Versor turn;
|
||||
BGC_FP32_Turn3 turn;
|
||||
|
||||
// No turn
|
||||
bgc_fp32_vector3_make(&initial_primary, 1.0f, 0.0f, 0.0f);
|
||||
|
|
@ -163,10 +163,10 @@ void test_basis_difference_fp32()
|
|||
bgc_fp32_vector3_make(&final_primary, 1.0f, 0.0f, 0.0f);
|
||||
bgc_fp32_vector3_make(&final_auxiliary, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
bgc_fp32_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
bgc_fp32_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
printf("\nNo turn:\n");
|
||||
print_versor_fp32(&turn);
|
||||
print_quaternion_fp32(&turn._versor);
|
||||
|
||||
// Turn around (1, 1, 0) axis on 180 degrees
|
||||
bgc_fp32_vector3_make(&initial_primary, 1.0f, 0.0f, 0.0f);
|
||||
|
|
@ -175,10 +175,10 @@ void test_basis_difference_fp32()
|
|||
bgc_fp32_vector3_make(&final_primary, 0.0f, 1.0f, 0.0f);
|
||||
bgc_fp32_vector3_make(&final_auxiliary, 1.0f, 0.0f, 0.0f);
|
||||
|
||||
bgc_fp32_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
bgc_fp32_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
printf("\nTurn around (1, 1, 0) axis on 180 degrees:\n");
|
||||
print_versor_fp32(&turn);
|
||||
print_quaternion_fp32(&turn._versor);
|
||||
|
||||
// 180 degree turn
|
||||
bgc_fp32_vector3_make(&initial_primary, 1.0f, 0.0f, 0.0f);
|
||||
|
|
@ -187,10 +187,10 @@ void test_basis_difference_fp32()
|
|||
bgc_fp32_vector3_make(&final_primary, -1.0f, 0.0f, 0.0f);
|
||||
bgc_fp32_vector3_make(&final_auxiliary, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
bgc_fp32_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
bgc_fp32_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
printf("\n180 degree turn around (0, 1, 0):\n");
|
||||
print_versor_fp32(&turn);
|
||||
print_quaternion_fp32(&turn._versor);
|
||||
|
||||
// 90 degree turn around x3 axis
|
||||
bgc_fp32_vector3_make(&initial_primary, 2.0f, 0.0f, 0.0f);
|
||||
|
|
@ -199,10 +199,10 @@ void test_basis_difference_fp32()
|
|||
bgc_fp32_vector3_make(&final_primary, 0.0f, 10.0f, 0.0f);
|
||||
bgc_fp32_vector3_make(&final_auxiliary,-1.0f, 0.0f, 0.0f);
|
||||
|
||||
bgc_fp32_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
bgc_fp32_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
printf("\n90 degree turn around (0, 0, 1):\n");
|
||||
print_versor_fp32(&turn);
|
||||
print_quaternion_fp32(&turn._versor);
|
||||
|
||||
// Unorthogonal pairs turn at 90 degrees around x3 axis
|
||||
bgc_fp32_vector3_make(&initial_primary, 2.0f, 0.0f, 0.0f);
|
||||
|
|
@ -211,10 +211,10 @@ void test_basis_difference_fp32()
|
|||
bgc_fp32_vector3_make(&final_primary, 0.0f, 10.0f, 0.0f);
|
||||
bgc_fp32_vector3_make(&final_auxiliary, -1.0f, 5.0f, 0.0f);
|
||||
|
||||
bgc_fp32_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
bgc_fp32_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
printf("\nUnorthogonal pairs turn at 90 degrees around (0, 0, 1):\n");
|
||||
print_versor_fp32(&turn);
|
||||
print_quaternion_fp32(&turn._versor);
|
||||
|
||||
// Zero vectors
|
||||
bgc_fp32_vector3_make(&initial_primary, 0.0f, 0.0f, 0.0f);
|
||||
|
|
@ -224,11 +224,11 @@ void test_basis_difference_fp32()
|
|||
|
||||
int code;
|
||||
|
||||
code = bgc_fp32_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
code = bgc_fp32_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
if (code >= 0) {
|
||||
printf("\nZero vectors: this cannot be!\n");
|
||||
print_versor_fp32(&turn);
|
||||
print_quaternion_fp32(&turn._versor);
|
||||
}
|
||||
else {
|
||||
printf("\nZero vector validation works fine\n");
|
||||
|
|
@ -240,11 +240,11 @@ void test_basis_difference_fp32()
|
|||
bgc_fp32_vector3_make(&final_primary, 1.0f, 0.0f, 0.0f);
|
||||
bgc_fp32_vector3_make(&final_auxiliary, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
code = bgc_fp32_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
code = bgc_fp32_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
if (code >= 0) {
|
||||
printf("\nParallel vectors: this cannot be!\n");
|
||||
print_versor_fp32(&turn);
|
||||
print_quaternion_fp32(&turn._versor);
|
||||
}
|
||||
else {
|
||||
printf("\nParallelism validation works fine\n");
|
||||
|
|
@ -257,10 +257,10 @@ void test_basis_difference_fp32()
|
|||
bgc_fp32_vector3_make(&final_primary, 0.999848f, 0.017452f, 0.0f);
|
||||
bgc_fp32_vector3_make(&final_auxiliary, -0.017452f, 0.999848f, 0.0f);
|
||||
|
||||
bgc_fp32_versor_make_basis_difference(&turn , &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
bgc_fp32_turn3_make_basis_difference(&turn , &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
printf("\nSmall angle turn (about 1 degree):\n");
|
||||
print_versor_fp32(&turn);
|
||||
print_quaternion_fp32(&turn._versor);
|
||||
|
||||
// About 179 degrees turn
|
||||
bgc_fp32_vector3_make(&initial_primary, 1.0f, 0.0f, 0.0f);
|
||||
|
|
@ -269,10 +269,10 @@ void test_basis_difference_fp32()
|
|||
bgc_fp32_vector3_make(&final_primary, -0.999848f, -0.017452f, 0.0f);
|
||||
bgc_fp32_vector3_make(&final_auxiliary, 0.017452f, -0.999848f, 0.0f);
|
||||
|
||||
bgc_fp32_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
bgc_fp32_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
printf("\nAbout 179 degrees turn:\n");
|
||||
print_versor_fp32(&turn);
|
||||
print_quaternion_fp32(&turn._versor);
|
||||
|
||||
// 120 degrees around (-1, -1, 1)
|
||||
bgc_fp32_vector3_make(&initial_primary, 1.0f, 0.0f, 0.0f);
|
||||
|
|
@ -281,10 +281,10 @@ void test_basis_difference_fp32()
|
|||
bgc_fp32_vector3_make(&final_primary, 0.0f, 1.0f, 0.0f);
|
||||
bgc_fp32_vector3_make(&final_auxiliary, 0.0f, 0.0f, -1.0f);
|
||||
|
||||
bgc_fp32_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
bgc_fp32_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
printf("\n120 degees turn:\n");
|
||||
print_versor_fp32(&turn);
|
||||
print_quaternion_fp32(&turn._versor);
|
||||
|
||||
|
||||
// About 1 degree turn difference between initial_primary and initial_auxiliary directions
|
||||
|
|
@ -293,10 +293,10 @@ void test_basis_difference_fp32()
|
|||
bgc_fp32_vector3_make(&final_primary, 0.0f, 1.0f, 0.0f);
|
||||
bgc_fp32_vector3_make(&final_auxiliary, -1.0f, 0.0f, 0.0f);
|
||||
|
||||
bgc_fp32_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
bgc_fp32_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
printf("\nAbout 1 degree turn difference between initial_primary and initial_auxiliary directions:\n");
|
||||
print_versor_fp32(&turn);
|
||||
print_quaternion_fp32(&turn._versor);
|
||||
|
||||
// About 0.01 degree turn difference between initial_primary and initial_auxiliary directions
|
||||
bgc_fp32_vector3_make(&initial_primary, 1.0f, 0.0f, 0.0f);
|
||||
|
|
@ -304,10 +304,10 @@ void test_basis_difference_fp32()
|
|||
bgc_fp32_vector3_make(&final_primary, 0.0f, -1.0f, 0.0f);
|
||||
bgc_fp32_vector3_make(&final_auxiliary, 1.0f, 0.0f, 0.0f);
|
||||
|
||||
bgc_fp32_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
bgc_fp32_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
printf("\nAbout 0.01 degree turn difference between initial_primary and initial_auxiliary directions:\n");
|
||||
print_versor_fp32(&turn);
|
||||
print_quaternion_fp32(&turn._versor);
|
||||
}
|
||||
|
||||
void test_basis_difference_fp64()
|
||||
|
|
@ -315,7 +315,7 @@ void test_basis_difference_fp64()
|
|||
|
||||
BGC_FP64_Vector3 initial_primary, initial_auxiliary;
|
||||
BGC_FP64_Vector3 final_primary, final_auxiliary;
|
||||
BGC_FP64_Versor turn;
|
||||
BGC_FP64_Turn3 turn;
|
||||
|
||||
// No turn
|
||||
bgc_fp64_vector3_make(&initial_primary, 1.0, 0.0, 0.0);
|
||||
|
|
@ -323,10 +323,10 @@ void test_basis_difference_fp64()
|
|||
bgc_fp64_vector3_make(&final_primary, 1.0, 0.0, 0.0);
|
||||
bgc_fp64_vector3_make(&final_auxiliary, 0.0, 1.0, 0.0);
|
||||
|
||||
bgc_fp64_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
bgc_fp64_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
printf("\nNo turn:\n");
|
||||
print_versor_fp64(&turn);
|
||||
print_quaternion_fp64(&turn._versor);
|
||||
|
||||
// Turn around (1, 1, 0) axis on 180 degrees
|
||||
bgc_fp64_vector3_make(&initial_primary, 1.0, 0.0, 0.0);
|
||||
|
|
@ -334,10 +334,10 @@ void test_basis_difference_fp64()
|
|||
bgc_fp64_vector3_make(&final_primary, 0.0, 1.0, 0.0);
|
||||
bgc_fp64_vector3_make(&final_auxiliary, 1.0, 0.0, 0.0);
|
||||
|
||||
bgc_fp64_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
bgc_fp64_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
printf("\nTurn around (1, 1, 0) axis on 180 degrees:\n");
|
||||
print_versor_fp64(&turn);
|
||||
print_quaternion_fp64(&turn._versor);
|
||||
|
||||
// 180 degree turn
|
||||
bgc_fp64_vector3_make(&initial_primary, 1.0, 0.0, 0.0);
|
||||
|
|
@ -346,10 +346,10 @@ void test_basis_difference_fp64()
|
|||
bgc_fp64_vector3_make(&initial_auxiliary, -1.0, 0.0, 0.0);
|
||||
bgc_fp64_vector3_make(&final_auxiliary, 0.0, 1.0, 0.0);
|
||||
|
||||
bgc_fp64_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
bgc_fp64_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
printf("\n180 degree turn around (0, 1, 0):\n");
|
||||
print_versor_fp64(&turn);
|
||||
print_quaternion_fp64(&turn._versor);
|
||||
|
||||
// 90 degree turn around x3 axis
|
||||
bgc_fp64_vector3_make(&initial_primary, 2.0, 0.0, 0.0);
|
||||
|
|
@ -358,10 +358,10 @@ void test_basis_difference_fp64()
|
|||
bgc_fp64_vector3_make(&final_primary, 0.0, 10.0, 0.0);
|
||||
bgc_fp64_vector3_make(&final_auxiliary, -1.0, 0.0, 0.0);
|
||||
|
||||
bgc_fp64_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
bgc_fp64_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
printf("\n90 degree turn around (0, 0, 1):\n");
|
||||
print_versor_fp64(&turn);
|
||||
print_quaternion_fp64(&turn._versor);
|
||||
|
||||
// Unorthogonal pairs turn at 90 degrees around x3 axis
|
||||
bgc_fp64_vector3_make(&initial_primary, 2.0, 0.0, 0.0);
|
||||
|
|
@ -370,10 +370,10 @@ void test_basis_difference_fp64()
|
|||
bgc_fp64_vector3_make(&final_primary, 0.0, 10.0, 0.0);
|
||||
bgc_fp64_vector3_make(&final_auxiliary, -1.0, 5.0, 0.0);
|
||||
|
||||
bgc_fp64_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
bgc_fp64_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
printf("\nUnorthogonal pairs turn at 90 degrees around (0, 0, 1):\n");
|
||||
print_versor_fp64(&turn);
|
||||
print_quaternion_fp64(&turn._versor);
|
||||
|
||||
// Zero vectors
|
||||
bgc_fp64_vector3_make(&initial_primary, 0.0, 0.0, 0.0);
|
||||
|
|
@ -383,11 +383,11 @@ void test_basis_difference_fp64()
|
|||
|
||||
int code;
|
||||
|
||||
code = bgc_fp64_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
code = bgc_fp64_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
if (code >= 0) {
|
||||
printf("\nZero vectors: this cannot be!\n");
|
||||
print_versor_fp64(&turn);
|
||||
print_quaternion_fp64(&turn._versor);
|
||||
}
|
||||
else {
|
||||
printf("\nZero vector validation works fine\n");
|
||||
|
|
@ -399,11 +399,11 @@ void test_basis_difference_fp64()
|
|||
bgc_fp64_vector3_make(&final_primary, 1.0, 0.0, 0.0);
|
||||
bgc_fp64_vector3_make(&final_auxiliary, 0.0, 1.0, 0.0);
|
||||
|
||||
code = bgc_fp64_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
code = bgc_fp64_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
if (code >= 0) {
|
||||
printf("\nParallel vectors: this cannot be!\n");
|
||||
print_versor_fp64(&turn);
|
||||
print_quaternion_fp64(&turn._versor);
|
||||
}
|
||||
else {
|
||||
printf("\nParallelism validation works fine\n");
|
||||
|
|
@ -416,10 +416,10 @@ void test_basis_difference_fp64()
|
|||
bgc_fp64_vector3_make(&final_primary, 0.999848, 0.017452, 0.0);
|
||||
bgc_fp64_vector3_make(&final_auxiliary, -0.017452, 0.999848, 0.0);
|
||||
|
||||
bgc_fp64_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
bgc_fp64_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
printf("\nSmall angle turn (about 1 degree):\n");
|
||||
print_versor_fp64(&turn);
|
||||
print_quaternion_fp64(&turn._versor);
|
||||
|
||||
// About 179 degrees turn
|
||||
bgc_fp64_vector3_make(&initial_primary, 1.0, 0.0, 0.0);
|
||||
|
|
@ -428,10 +428,10 @@ void test_basis_difference_fp64()
|
|||
bgc_fp64_vector3_make(&final_primary, -0.999848, -0.017452, 0.0);
|
||||
bgc_fp64_vector3_make(&final_auxiliary, 0.017452, -0.999848, 0.0);
|
||||
|
||||
bgc_fp64_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
bgc_fp64_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
printf("\nAbout 179 degrees turn:\n");
|
||||
print_versor_fp64(&turn);
|
||||
print_quaternion_fp64(&turn._versor);
|
||||
|
||||
// 120 degrees around (-1, -1, 1)
|
||||
bgc_fp64_vector3_make(&initial_primary, 1.0, 0.0, 0.0);
|
||||
|
|
@ -440,10 +440,10 @@ void test_basis_difference_fp64()
|
|||
bgc_fp64_vector3_make(&final_primary, 0.0, 1.0, 0.0);
|
||||
bgc_fp64_vector3_make(&final_auxiliary, 0.0, 0.0, -1.0);
|
||||
|
||||
bgc_fp64_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
bgc_fp64_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
printf("\n120 degees turn:\n");
|
||||
print_versor_fp64(&turn);
|
||||
print_quaternion_fp64(&turn._versor);
|
||||
|
||||
|
||||
// About 1 degree turn difference between initial_primary and initial_auxiliary directions
|
||||
|
|
@ -452,10 +452,10 @@ void test_basis_difference_fp64()
|
|||
bgc_fp64_vector3_make(&final_primary, 0.0, 1.0, 0.0);
|
||||
bgc_fp64_vector3_make(&final_auxiliary, -1.0, 0.0, 0.0);
|
||||
|
||||
bgc_fp64_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
bgc_fp64_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
printf("\nAbout 1 degree turn difference between initial_primary and initial_auxiliary directions:\n");
|
||||
print_versor_fp64(&turn);
|
||||
print_quaternion_fp64(&turn._versor);
|
||||
|
||||
// About 0.001 degree turn difference between initial_primary and initial_auxiliary directions
|
||||
bgc_fp64_vector3_make(&initial_primary, 1.0, 0.0, 0.0);
|
||||
|
|
@ -463,30 +463,30 @@ void test_basis_difference_fp64()
|
|||
bgc_fp64_vector3_make(&final_primary, 0.0, -1.0, 0.0);
|
||||
bgc_fp64_vector3_make(&final_auxiliary, 1.0, 0.0, 0.0);
|
||||
|
||||
bgc_fp64_versor_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
bgc_fp64_turn3_make_basis_difference(&turn, &initial_primary, &initial_auxiliary, &final_primary, &final_auxiliary);
|
||||
|
||||
printf("\nAbout 0.01 degree turn difference between initial_primary and initial_auxiliary directions:\n");
|
||||
print_versor_fp64(&turn);
|
||||
print_quaternion_fp64(&turn._versor);
|
||||
}
|
||||
|
||||
/*
|
||||
#include "affine3.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
//BGC_FP32_Versor start = { 1.0f, 0.0f, 0.0f, 0.0f };
|
||||
//BGC_FP32_Versor end = { 0.0f, 1.0f, 0.0f, 0.0f };
|
||||
|
||||
BGC_FP32_Versor start = { 1.0f, 0.0f, 0.0f, 0.0f };
|
||||
BGC_FP32_Versor end = { 0.9999f, 0.01414f, 0.0f, 0.0f };
|
||||
//BGC_FP32_Turn3 start = { 1.0f, 0.0f, 0.0f, 0.0f };
|
||||
//BGC_FP32_Turn3 end = { 0.0f, 1.0f, 0.0f, 0.0f };
|
||||
|
||||
BGC_FP32_Turn3 start = { 1.0f, 0.0f, 0.0f, 0.0f };
|
||||
BGC_FP32_Turn3 end = { 0.9999f, 0.01414f, 0.0f, 0.0f };
|
||||
BGC_FP32_Slerp slerp;
|
||||
BGC_FP32_Versor result;
|
||||
BGC_FP32_Turn3 result;
|
||||
bgc_fp32_slerp_make_full(&slerp, &start, &end);
|
||||
bgc_fp32_slerp_get_phase_versor(&result, &slerp, 0.5f);
|
||||
|
||||
//print_versor_fp32(&result);
|
||||
|
||||
//print_quaternion_fp32(&result);
|
||||
|
||||
test_basis_difference_fp64();
|
||||
|
||||
|
||||
//printf("Affine3 performance test: %f\n", test_bgc_affine3_performance(10000000, 10));
|
||||
|
||||
//printf("sizeof(BGC_FP32_Affine3) = %zu\n", sizeof(BGC_FP32_Affine3));
|
||||
|
|
@ -495,3 +495,4 @@ int main()
|
|||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -25,19 +25,19 @@ typedef struct {
|
|||
// =================== Versor =================== //
|
||||
|
||||
typedef struct {
|
||||
BGC_FP32_Versor first, second;
|
||||
BGC_FP32_Turn3 first, second;
|
||||
} TestVersorPairFP32;
|
||||
|
||||
typedef struct {
|
||||
BGC_FP64_Versor first, second;
|
||||
BGC_FP64_Turn3 first, second;
|
||||
} TestVersorPairFP64;
|
||||
|
||||
typedef struct {
|
||||
BGC_FP32_Versor first, second, result;
|
||||
BGC_FP32_Turn3 first, second, result;
|
||||
} TestVersorTripletFP32;
|
||||
|
||||
typedef struct {
|
||||
BGC_FP64_Versor first, second, result;
|
||||
BGC_FP64_Turn3 first, second, result;
|
||||
} TestVersorTripletFP64;
|
||||
|
||||
// ================= Functions ================== //
|
||||
|
|
|
|||
|
|
@ -60,10 +60,6 @@
|
|||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="complex.h" />
|
||||
<Unit filename="cotes-number.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="cotes-number.h" />
|
||||
<Unit filename="dual-number.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
|
|
@ -116,14 +112,18 @@
|
|||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="quaternion.h" />
|
||||
<Unit filename="rotation3.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="rotation3.h" />
|
||||
<Unit filename="slerp.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="slerp.h" />
|
||||
<Unit filename="turn2.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="turn2.h" />
|
||||
<Unit filename="turn3.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="turn3.h" />
|
||||
<Unit filename="utilities.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
|
|
@ -136,10 +136,6 @@
|
|||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="vector3.h" />
|
||||
<Unit filename="versor.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="versor.h" />
|
||||
<Extensions />
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
||||
|
|
|
|||
|
|
@ -18,15 +18,14 @@
|
|||
#include "./affine3.h"
|
||||
|
||||
#include "./complex.h"
|
||||
#include "./cotes-number.h"
|
||||
#include "./quaternion.h"
|
||||
|
||||
#include "./rotation3.h"
|
||||
#include "./turn2.h"
|
||||
#include "./turn3.h"
|
||||
|
||||
#include "./quaternion.h"
|
||||
#include "./versor.h"
|
||||
#include "./position2.h"
|
||||
#include "./position3.h"
|
||||
|
||||
#include "./slerp.h"
|
||||
|
||||
#include "./position2.h"
|
||||
#include "./position3.h"
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,91 +0,0 @@
|
|||
#include "./cotes-number.h"
|
||||
|
||||
const BGC_FP32_CotesNumber BGC_FP32_IDLE_COTES_NUMBER = { 1.0f, 0.0f };
|
||||
|
||||
const BGC_FP64_CotesNumber BGC_FP64_IDLE_COTES_NUMBER = { 1.0, 0.0 };
|
||||
|
||||
extern inline void bgc_fp32_cotes_number_reset(BGC_FP32_CotesNumber* number);
|
||||
extern inline void bgc_fp64_cotes_number_reset(BGC_FP64_CotesNumber* number);
|
||||
|
||||
extern inline void bgc_fp32_cotes_number_make(BGC_FP32_CotesNumber* number, const float x1, const float x2);
|
||||
extern inline void bgc_fp64_cotes_number_make(BGC_FP64_CotesNumber* number, const double x1, const double x2);
|
||||
|
||||
extern inline void bgc_fp32_cotes_number_make_for_angle(BGC_FP32_CotesNumber* number, const float angle, const int angle_unit);
|
||||
extern inline void bgc_fp64_cotes_number_make_for_angle(BGC_FP64_CotesNumber* number, const double angle, const int angle_unit);
|
||||
|
||||
extern inline int bgc_fp32_cotes_number_is_idle(const BGC_FP32_CotesNumber* number);
|
||||
extern inline int bgc_fp64_cotes_number_is_idle(const BGC_FP64_CotesNumber* number);
|
||||
|
||||
extern inline float bgc_fp32_cotes_number_get_angle(const BGC_FP32_CotesNumber* number, const int angle_unit);
|
||||
extern inline double bgc_fp64_cotes_number_get_angle(const BGC_FP64_CotesNumber* number, const int angle_unit);
|
||||
|
||||
extern inline void bgc_fp32_cotes_number_copy(BGC_FP32_CotesNumber* destination, const BGC_FP32_CotesNumber* source);
|
||||
extern inline void bgc_fp64_cotes_number_copy(BGC_FP64_CotesNumber* destination, const BGC_FP64_CotesNumber* source);
|
||||
|
||||
extern inline void bgc_fp32_cotes_number_swap(BGC_FP32_CotesNumber* number1, BGC_FP32_CotesNumber* number2);
|
||||
extern inline void bgc_fp64_cotes_number_swap(BGC_FP64_CotesNumber* number1, BGC_FP64_CotesNumber* number2);
|
||||
|
||||
extern inline void bgc_fp64_cotes_number_convert_to_fp32(BGC_FP32_CotesNumber* destination, const BGC_FP64_CotesNumber* source);
|
||||
extern inline void bgc_fp32_cotes_number_convert_to_fp64(BGC_FP64_CotesNumber* destination, const BGC_FP32_CotesNumber* source);
|
||||
|
||||
extern inline void bgc_fp32_cotes_number_revert(BGC_FP32_CotesNumber* number);
|
||||
extern inline void bgc_fp64_cotes_number_revert(BGC_FP64_CotesNumber* number);
|
||||
|
||||
extern inline void bgc_fp32_cotes_number_get_reverse(BGC_FP32_CotesNumber* reverse, const BGC_FP32_CotesNumber* number);
|
||||
extern inline void bgc_fp64_cotes_number_get_reverse(BGC_FP64_CotesNumber* reverse, const BGC_FP64_CotesNumber* number);
|
||||
|
||||
extern inline void bgc_fp32_cotes_number_get_exponation(BGC_FP32_CotesNumber* power, const BGC_FP32_CotesNumber* base, const float exponent);
|
||||
extern inline void bgc_fp64_cotes_number_get_exponation(BGC_FP64_CotesNumber* power, const BGC_FP64_CotesNumber* base, const double exponent);
|
||||
|
||||
extern inline void bgc_fp32_cotes_number_combine(BGC_FP32_CotesNumber* combination, const BGC_FP32_CotesNumber* number1, const BGC_FP32_CotesNumber* number2);
|
||||
extern inline void bgc_fp64_cotes_number_combine(BGC_FP64_CotesNumber* combination, const BGC_FP64_CotesNumber* number1, const BGC_FP64_CotesNumber* number2);
|
||||
|
||||
extern inline void bgc_fp32_cotes_number_exclude(BGC_FP32_CotesNumber* difference, const BGC_FP32_CotesNumber* base, const BGC_FP32_CotesNumber* excludant);
|
||||
extern inline void bgc_fp64_cotes_number_exclude(BGC_FP64_CotesNumber* difference, const BGC_FP64_CotesNumber* base, const BGC_FP64_CotesNumber* excludant);
|
||||
|
||||
extern inline void bgc_fp32_cotes_number_get_rotation_matrix(BGC_FP32_Matrix2x2* matrix, const BGC_FP32_CotesNumber* number);
|
||||
extern inline void bgc_fp64_cotes_number_get_rotation_matrix(BGC_FP64_Matrix2x2* matrix, const BGC_FP64_CotesNumber* number);
|
||||
|
||||
extern inline void bgc_fp32_cotes_number_get_reverse_matrix(BGC_FP32_Matrix2x2* matrix, const BGC_FP32_CotesNumber* number);
|
||||
extern inline void bgc_fp64_cotes_number_get_reverse_matrix(BGC_FP64_Matrix2x2* matrix, const BGC_FP64_CotesNumber* number);
|
||||
|
||||
extern inline void bgc_fp32_cotes_number_turn_vector(BGC_FP32_Vector2* turned_vector, const BGC_FP32_CotesNumber* number, const BGC_FP32_Vector2* vector);
|
||||
extern inline void bgc_fp64_cotes_number_turn_vector(BGC_FP64_Vector2* turned_vector, const BGC_FP64_CotesNumber* number, const BGC_FP64_Vector2* vector);
|
||||
|
||||
extern inline void bgc_fp32_cotes_number_turn_vector_back(BGC_FP32_Vector2* turned_vector, const BGC_FP32_CotesNumber* number, const BGC_FP32_Vector2* vector);
|
||||
extern inline void bgc_fp64_cotes_number_turn_vector_back(BGC_FP64_Vector2* turned_vector, const BGC_FP64_CotesNumber* number, const BGC_FP64_Vector2* vector);
|
||||
|
||||
extern inline int bgc_fp32_cotes_number_are_close(const BGC_FP32_CotesNumber* number1, const BGC_FP32_CotesNumber* number2);
|
||||
extern inline int bgc_fp64_cotes_number_are_close(const BGC_FP64_CotesNumber* number1, const BGC_FP64_CotesNumber* number2);
|
||||
|
||||
void _bgc_fp32_cotes_number_normalize(BGC_FP32_CotesNumber* number)
|
||||
{
|
||||
const float square_modulus = number->_cos * number->_cos + number->_sin * number->_sin;
|
||||
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
number->_cos = 1.0f;
|
||||
number->_sin = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
const float multiplier = sqrtf(1.0f / square_modulus);
|
||||
|
||||
number->_cos *= multiplier;
|
||||
number->_sin *= multiplier;
|
||||
}
|
||||
|
||||
void _bgc_fp64_cotes_number_normalize(BGC_FP64_CotesNumber* number)
|
||||
{
|
||||
const double square_modulus = number->_cos * number->_cos + number->_sin * number->_sin;
|
||||
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
number->_cos = 1.0;
|
||||
number->_sin = 0.0;
|
||||
return;
|
||||
}
|
||||
|
||||
const double multiplier = sqrt(1.0 / square_modulus);
|
||||
|
||||
number->_cos *= multiplier;
|
||||
number->_sin *= multiplier;
|
||||
}
|
||||
|
|
@ -1,343 +0,0 @@
|
|||
#ifndef _BGC_COTES_NUMBER_H_
|
||||
#define _BGC_COTES_NUMBER_H_
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "utilities.h"
|
||||
#include "angle.h"
|
||||
#include "vector2.h"
|
||||
#include "matrix2x2.h"
|
||||
|
||||
// =================== Types ==================== //
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float _cos, _sin;
|
||||
} BGC_FP32_CotesNumber;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double _cos, _sin;
|
||||
} BGC_FP64_CotesNumber;
|
||||
|
||||
// ================= Constants ================== //
|
||||
|
||||
extern const BGC_FP32_CotesNumber BGC_FP32_IDLE_COTES_NUMBER;
|
||||
extern const BGC_FP64_CotesNumber BGC_FP64_IDLE_COTES_NUMBER;
|
||||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
inline void bgc_fp32_cotes_number_reset(BGC_FP32_CotesNumber* number)
|
||||
{
|
||||
number->_cos = 1.0f;
|
||||
number->_sin = 0.0f;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_cotes_number_reset(BGC_FP64_CotesNumber* number)
|
||||
{
|
||||
number->_cos = 1.0;
|
||||
number->_sin = 0.0;
|
||||
}
|
||||
|
||||
// ================== Set Turn ================== //
|
||||
|
||||
inline void bgc_fp32_cotes_number_make_for_angle(BGC_FP32_CotesNumber* number, const float angle, const int angle_unit)
|
||||
{
|
||||
const float radians = bgc_fp32_angle_to_radians(angle, angle_unit);
|
||||
|
||||
number->_cos = cosf(radians);
|
||||
number->_sin = sinf(radians);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_cotes_number_make_for_angle(BGC_FP64_CotesNumber* number, const double angle, const int angle_unit)
|
||||
{
|
||||
const double radians = bgc_fp64_angle_to_radians(angle, angle_unit);
|
||||
|
||||
number->_cos = cos(radians);
|
||||
number->_sin = sin(radians);
|
||||
}
|
||||
|
||||
|
||||
// ================== Set Turn ================== //
|
||||
|
||||
inline int bgc_fp32_cotes_number_is_idle(const BGC_FP32_CotesNumber* number)
|
||||
{
|
||||
return bgc_fp32_is_unit(number->_cos) && bgc_fp32_is_zero(number->_sin);
|
||||
}
|
||||
|
||||
inline int bgc_fp64_cotes_number_is_idle(const BGC_FP64_CotesNumber* number)
|
||||
{
|
||||
return bgc_fp64_is_unit(number->_cos) && bgc_fp64_is_zero(number->_sin);
|
||||
}
|
||||
|
||||
// ==================== Set ===================== //
|
||||
|
||||
void _bgc_fp32_cotes_number_normalize(BGC_FP32_CotesNumber* twin);
|
||||
|
||||
void _bgc_fp64_cotes_number_normalize(BGC_FP64_CotesNumber* twin);
|
||||
|
||||
inline void bgc_fp32_cotes_number_make(BGC_FP32_CotesNumber* number, const float x1, const float x2)
|
||||
{
|
||||
const float square_modulus = x1 * x1 + x2 * x2;
|
||||
|
||||
number->_cos = x1;
|
||||
number->_sin = x2;
|
||||
|
||||
if (!bgc_fp32_is_square_unit(square_modulus)) {
|
||||
_bgc_fp32_cotes_number_normalize(number);
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_fp64_cotes_number_make(BGC_FP64_CotesNumber* number, const double x1, const double x2)
|
||||
{
|
||||
const double square_modulus = x1 * x1 + x2 * x2;
|
||||
|
||||
number->_cos = x1;
|
||||
number->_sin = x2;
|
||||
|
||||
if (!bgc_fp64_is_square_unit(square_modulus)) {
|
||||
_bgc_fp64_cotes_number_normalize(number);
|
||||
}
|
||||
}
|
||||
|
||||
// =================== Angle =================== //
|
||||
|
||||
inline float bgc_fp32_cotes_number_get_angle(const BGC_FP32_CotesNumber* number, const int angle_unit)
|
||||
{
|
||||
return bgc_fp32_radians_to_units(atan2f(number->_sin, number->_cos), angle_unit);
|
||||
}
|
||||
|
||||
inline double bgc_fp64_cotes_number_get_angle(const BGC_FP64_CotesNumber* number, const int angle_unit)
|
||||
{
|
||||
return bgc_fp64_radians_to_units(atan2(number->_sin, number->_cos), angle_unit);
|
||||
}
|
||||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
inline void bgc_fp32_cotes_number_copy(BGC_FP32_CotesNumber* destination, const BGC_FP32_CotesNumber* source)
|
||||
{
|
||||
destination->_cos = source->_cos;
|
||||
destination->_sin = source->_sin;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_cotes_number_copy(BGC_FP64_CotesNumber* destination, const BGC_FP64_CotesNumber* source)
|
||||
{
|
||||
destination->_cos = source->_cos;
|
||||
destination->_sin = source->_sin;
|
||||
}
|
||||
|
||||
// ==================== Swap ==================== //
|
||||
|
||||
inline void bgc_fp32_cotes_number_swap(BGC_FP32_CotesNumber* number1, BGC_FP32_CotesNumber* number2)
|
||||
{
|
||||
const float cos = number1->_cos;
|
||||
const float sin = number1->_sin;
|
||||
|
||||
number1->_cos = number2->_cos;
|
||||
number1->_sin = number2->_sin;
|
||||
|
||||
number2->_cos = cos;
|
||||
number2->_sin = sin;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_cotes_number_swap(BGC_FP64_CotesNumber* number1, BGC_FP64_CotesNumber* number2)
|
||||
{
|
||||
const double cos = number1->_cos;
|
||||
const double sin = number1->_sin;
|
||||
|
||||
number1->_cos = number2->_cos;
|
||||
number1->_sin = number2->_sin;
|
||||
|
||||
number2->_cos = cos;
|
||||
number2->_sin = sin;
|
||||
}
|
||||
|
||||
// ================== Convert =================== //
|
||||
|
||||
inline void bgc_fp64_cotes_number_convert_to_fp32(BGC_FP32_CotesNumber* destination, const BGC_FP64_CotesNumber* source)
|
||||
{
|
||||
bgc_fp32_cotes_number_make(destination, (float)source->_cos, (float)source->_sin);
|
||||
}
|
||||
|
||||
inline void bgc_fp32_cotes_number_convert_to_fp64(BGC_FP64_CotesNumber* destination, const BGC_FP32_CotesNumber* source)
|
||||
{
|
||||
bgc_fp64_cotes_number_make(destination, (double)source->_cos, (double)source->_sin);
|
||||
}
|
||||
|
||||
// =================== Revert =================== //
|
||||
|
||||
inline void bgc_fp32_cotes_number_revert(BGC_FP32_CotesNumber* number)
|
||||
{
|
||||
number->_sin = -number->_sin;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_cotes_number_revert(BGC_FP64_CotesNumber* number)
|
||||
{
|
||||
number->_sin = -number->_sin;
|
||||
}
|
||||
|
||||
inline void bgc_fp32_cotes_number_get_reverse(BGC_FP32_CotesNumber* reverse, const BGC_FP32_CotesNumber* number)
|
||||
{
|
||||
reverse->_cos = number->_cos;
|
||||
reverse->_sin = -number->_sin;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_cotes_number_get_reverse(BGC_FP64_CotesNumber* reverse, const BGC_FP64_CotesNumber* number)
|
||||
{
|
||||
reverse->_cos = number->_cos;
|
||||
reverse->_sin = -number->_sin;
|
||||
}
|
||||
|
||||
// ================= Exponation ================= //
|
||||
|
||||
inline void bgc_fp32_cotes_number_get_exponation(BGC_FP32_CotesNumber* power, const BGC_FP32_CotesNumber* base, const float exponent)
|
||||
{
|
||||
const float power_angle = exponent * atan2f(base->_sin, base->_cos);
|
||||
|
||||
power->_cos = cosf(power_angle);
|
||||
power->_sin = sinf(power_angle);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_cotes_number_get_exponation(BGC_FP64_CotesNumber* power, const BGC_FP64_CotesNumber* base, const double exponent)
|
||||
{
|
||||
const double power_angle = exponent * atan2(base->_sin, base->_cos);
|
||||
|
||||
power->_cos = cos(power_angle);
|
||||
power->_sin = sin(power_angle);
|
||||
}
|
||||
|
||||
// ================ Combination ================= //
|
||||
|
||||
inline void bgc_fp32_cotes_number_combine(BGC_FP32_CotesNumber* combination, const BGC_FP32_CotesNumber* number1, const BGC_FP32_CotesNumber* number2)
|
||||
{
|
||||
bgc_fp32_cotes_number_make(
|
||||
combination,
|
||||
number1->_cos * number2->_cos - number1->_sin * number2->_sin,
|
||||
number1->_cos * number2->_sin + number1->_sin * number2->_cos
|
||||
);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_cotes_number_combine(BGC_FP64_CotesNumber* combination, const BGC_FP64_CotesNumber* number1, const BGC_FP64_CotesNumber* number2)
|
||||
{
|
||||
bgc_fp64_cotes_number_make(
|
||||
combination,
|
||||
number1->_cos * number2->_cos - number1->_sin * number2->_sin,
|
||||
number1->_cos * number2->_sin + number1->_sin * number2->_cos
|
||||
);
|
||||
}
|
||||
|
||||
// ================= Exclusion ================== //
|
||||
|
||||
inline void bgc_fp32_cotes_number_exclude(BGC_FP32_CotesNumber* difference, const BGC_FP32_CotesNumber* base, const BGC_FP32_CotesNumber* excludant)
|
||||
{
|
||||
bgc_fp32_cotes_number_make(
|
||||
difference,
|
||||
base->_cos * excludant->_cos + base->_sin * excludant->_sin,
|
||||
base->_sin * excludant->_cos - base->_cos * excludant->_sin
|
||||
);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_cotes_number_exclude(BGC_FP64_CotesNumber* difference, const BGC_FP64_CotesNumber* base, const BGC_FP64_CotesNumber* excludant)
|
||||
{
|
||||
bgc_fp64_cotes_number_make(
|
||||
difference,
|
||||
base->_cos * excludant->_cos + base->_sin * excludant->_sin,
|
||||
base->_sin * excludant->_cos - base->_cos * excludant->_sin
|
||||
);
|
||||
}
|
||||
|
||||
// ============== Rotation Matrix =============== //
|
||||
|
||||
inline void bgc_fp32_cotes_number_get_rotation_matrix(BGC_FP32_Matrix2x2* matrix, const BGC_FP32_CotesNumber* number)
|
||||
{
|
||||
matrix->r1c1 = number->_cos;
|
||||
matrix->r1c2 = -number->_sin;
|
||||
matrix->r2c1 = number->_sin;
|
||||
matrix->r2c2 = number->_cos;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_cotes_number_get_rotation_matrix(BGC_FP64_Matrix2x2* matrix, const BGC_FP64_CotesNumber* number)
|
||||
{
|
||||
matrix->r1c1 = number->_cos;
|
||||
matrix->r1c2 = -number->_sin;
|
||||
matrix->r2c1 = number->_sin;
|
||||
matrix->r2c2 = number->_cos;
|
||||
}
|
||||
|
||||
// ============== Reverse Matrix ================ //
|
||||
|
||||
inline void bgc_fp32_cotes_number_get_reverse_matrix(BGC_FP32_Matrix2x2* matrix, const BGC_FP32_CotesNumber* number)
|
||||
{
|
||||
matrix->r1c1 = number->_cos;
|
||||
matrix->r1c2 = number->_sin;
|
||||
matrix->r2c1 = -number->_sin;
|
||||
matrix->r2c2 = number->_cos;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_cotes_number_get_reverse_matrix(BGC_FP64_Matrix2x2* matrix, const BGC_FP64_CotesNumber* number)
|
||||
{
|
||||
matrix->r1c1 = number->_cos;
|
||||
matrix->r1c2 = number->_sin;
|
||||
matrix->r2c1 = -number->_sin;
|
||||
matrix->r2c2 = number->_cos;
|
||||
}
|
||||
|
||||
// ================ Turn Vector ================= //
|
||||
|
||||
inline void bgc_fp32_cotes_number_turn_vector(BGC_FP32_Vector2* turned_vector, const BGC_FP32_CotesNumber* number, const BGC_FP32_Vector2* vector)
|
||||
{
|
||||
const float x1 = number->_cos * vector->x1 - number->_sin * vector->x2;
|
||||
const float x2 = number->_sin * vector->x1 + number->_cos * vector->x2;
|
||||
|
||||
turned_vector->x1 = x1;
|
||||
turned_vector->x2 = x2;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_cotes_number_turn_vector(BGC_FP64_Vector2* turned_vector, const BGC_FP64_CotesNumber* number, const BGC_FP64_Vector2* vector)
|
||||
{
|
||||
const double x1 = number->_cos * vector->x1 - number->_sin * vector->x2;
|
||||
const double x2 = number->_sin * vector->x1 + number->_cos * vector->x2;
|
||||
|
||||
turned_vector->x1 = x1;
|
||||
turned_vector->x2 = x2;
|
||||
}
|
||||
|
||||
// ============ Turn Vector Backward ============ //
|
||||
|
||||
inline void bgc_fp32_cotes_number_turn_vector_back(BGC_FP32_Vector2* turned_vector, const BGC_FP32_CotesNumber* number, const BGC_FP32_Vector2* vector)
|
||||
{
|
||||
const float x1 = number->_sin * vector->x2 + number->_cos * vector->x1;
|
||||
const float x2 = number->_cos * vector->x2 - number->_sin * vector->x1;
|
||||
|
||||
turned_vector->x1 = x1;
|
||||
turned_vector->x2 = x2;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_cotes_number_turn_vector_back(BGC_FP64_Vector2* turned_vector, const BGC_FP64_CotesNumber* number, const BGC_FP64_Vector2* vector)
|
||||
{
|
||||
const double x1 = number->_sin * vector->x2 + number->_cos * vector->x1;
|
||||
const double x2 = number->_cos * vector->x2 - number->_sin * vector->x1;
|
||||
|
||||
turned_vector->x1 = x1;
|
||||
turned_vector->x2 = x2;
|
||||
}
|
||||
|
||||
// ================== Are Close ================= //
|
||||
|
||||
inline int bgc_fp32_cotes_number_are_close(const BGC_FP32_CotesNumber* number1, const BGC_FP32_CotesNumber* number2)
|
||||
{
|
||||
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_FP32_SQUARE_EPSILON;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_cotes_number_are_close(const BGC_FP64_CotesNumber* number1, const BGC_FP64_CotesNumber* number2)
|
||||
{
|
||||
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_FP64_SQUARE_EPSILON;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -15,8 +15,8 @@ extern inline void bgc_fp64_dual_quaternion_convert_to_fp32(BGC_FP32_DualQuatern
|
|||
extern inline void bgc_fp32_dual_quaternion_add(BGC_FP32_DualQuaternion* sum, const BGC_FP32_DualQuaternion* first, const BGC_FP32_DualQuaternion* second);
|
||||
extern inline void bgc_fp64_dual_quaternion_add(BGC_FP64_DualQuaternion* sum, const BGC_FP64_DualQuaternion* first, const BGC_FP64_DualQuaternion* second);
|
||||
|
||||
extern inline void bgc_fp32_dual_quaternion_add(BGC_FP32_DualQuaternion* sum, const BGC_FP32_DualQuaternion* base_quaternion, const BGC_FP32_DualQuaternion* scalable_quaternion, const float scale);
|
||||
extern inline void bgc_fp64_dual_quaternion_add(BGC_FP64_DualQuaternion* sum, const BGC_FP64_DualQuaternion* base_quaternion, const BGC_FP64_DualQuaternion* scalable_quaternion, const double scale);
|
||||