Отказ от терминов 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);
|
||||
extern inline void bgc_fp32_dual_quaternion_add_scaled(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_scaled(BGC_FP64_DualQuaternion* sum, const BGC_FP64_DualQuaternion* base_quaternion, const BGC_FP64_DualQuaternion* scalable_quaternion, const double scale);
|
||||
|
||||
extern inline void bgc_fp32_dual_quaternion_subtract(BGC_FP32_DualQuaternion* difference, const BGC_FP32_DualQuaternion* minuend, const BGC_FP32_DualQuaternion* subtrahend);
|
||||
extern inline void bgc_fp64_dual_quaternion_subtract(BGC_FP64_DualQuaternion* difference, const BGC_FP64_DualQuaternion* minuend, const BGC_FP64_DualQuaternion* subtrahend);
|
||||
|
|
|
|||
|
|
@ -85,13 +85,13 @@ inline void bgc_fp64_dual_quaternion_add(BGC_FP64_DualQuaternion* sum, const BGC
|
|||
|
||||
// ================= Add Scaled ================= //
|
||||
|
||||
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)
|
||||
inline void bgc_fp32_dual_quaternion_add_scaled(BGC_FP32_DualQuaternion* sum, const BGC_FP32_DualQuaternion* base_quaternion, const BGC_FP32_DualQuaternion* scalable_quaternion, const float scale)
|
||||
{
|
||||
bgc_fp32_quaternion_add_scaled(&sum->real, &base_quaternion->real, &scalable_quaternion->real, scale);
|
||||
bgc_fp32_quaternion_add_scaled(&sum->dual, &base_quaternion->dual, &scalable_quaternion->dual, scale);
|
||||
}
|
||||
|
||||
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)
|
||||
inline void bgc_fp64_dual_quaternion_add_scaled(BGC_FP64_DualQuaternion* sum, const BGC_FP64_DualQuaternion* base_quaternion, const BGC_FP64_DualQuaternion* scalable_quaternion, const double scale)
|
||||
{
|
||||
bgc_fp64_quaternion_add_scaled(&sum->real, &base_quaternion->real, &scalable_quaternion->real, scale);
|
||||
bgc_fp64_quaternion_add_scaled(&sum->dual, &base_quaternion->dual, &scalable_quaternion->dual, scale);
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ extern inline void bgc_fp64_matrix2x2_make_identity(BGC_FP64_Matrix2x2* matrix);
|
|||
extern inline void bgc_fp32_matrix2x2_make_diagonal(BGC_FP32_Matrix2x2* matrix, const float d1, const float d2);
|
||||
extern inline void bgc_fp64_matrix2x2_make_diagonal(BGC_FP64_Matrix2x2* matrix, const double d1, const double d2);
|
||||
|
||||
extern inline void bgc_fp32_matrix2x2_make_for_turn(BGC_FP32_Matrix2x2* matrix, const float angle, const int angle_unit);
|
||||
extern inline void bgc_fp64_matrix2x2_make_for_turn(BGC_FP64_Matrix2x2* matrix, const double angle, const int angle_unit);
|
||||
extern inline void bgc_fp32_matrix2x2_set_turn(BGC_FP32_Matrix2x2* matrix, const float angle, const int angle_unit);
|
||||
extern inline void bgc_fp64_matrix2x2_set_turn(BGC_FP64_Matrix2x2* matrix, const double angle, const int angle_unit);
|
||||
|
||||
extern inline float bgc_fp32_matrix2x2_get_determinant(const BGC_FP32_Matrix2x2* matrix);
|
||||
extern inline double bgc_fp64_matrix2x2_get_determinant(const BGC_FP64_Matrix2x2* matrix);
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ inline void bgc_fp64_matrix2x2_make_diagonal(BGC_FP64_Matrix2x2* matrix, const d
|
|||
|
||||
// ============== Rotation Matrix =============== //
|
||||
|
||||
inline void bgc_fp32_matrix2x2_make_for_turn(BGC_FP32_Matrix2x2* matrix, const float angle, const int angle_unit)
|
||||
inline void bgc_fp32_matrix2x2_set_turn(BGC_FP32_Matrix2x2* matrix, const float angle, const int angle_unit)
|
||||
{
|
||||
const float radians = bgc_fp32_angle_to_radians(angle, angle_unit);
|
||||
const float cosine = cosf(radians);
|
||||
|
|
@ -73,7 +73,7 @@ inline void bgc_fp32_matrix2x2_make_for_turn(BGC_FP32_Matrix2x2* matrix, const f
|
|||
matrix->r2c2 = cosine;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_matrix2x2_make_for_turn(BGC_FP64_Matrix2x2* matrix, const double angle, const int angle_unit)
|
||||
inline void bgc_fp64_matrix2x2_set_turn(BGC_FP64_Matrix2x2* matrix, const double angle, const int angle_unit)
|
||||
{
|
||||
const double radians = bgc_fp64_angle_to_radians(angle, angle_unit);
|
||||
const double cosine = cos(radians);
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
extern inline void bgc_fp32_position2_reset(BGC_FP32_Position2* node);
|
||||
extern inline void bgc_fp64_position2_reset(BGC_FP64_Position2* node);
|
||||
|
||||
extern inline void bgc_fp32_position2_make(BGC_FP32_Position2* position, const BGC_FP32_CotesNumber* turn, const BGC_FP32_Vector2* shift);
|
||||
extern inline void bgc_fp64_position2_make(BGC_FP64_Position2* position, const BGC_FP64_CotesNumber* turn, const BGC_FP64_Vector2* shift);
|
||||
extern inline void bgc_fp32_position2_make(BGC_FP32_Position2* position, const BGC_FP32_Turn2* turn, const BGC_FP32_Vector2* shift);
|
||||
extern inline void bgc_fp64_position2_make(BGC_FP64_Position2* position, const BGC_FP64_Turn2* turn, const BGC_FP64_Vector2* shift);
|
||||
|
||||
extern inline void bgc_fp32_position2_copy(BGC_FP32_Position2* destination, const BGC_FP32_Position2* source);
|
||||
extern inline void bgc_fp64_position2_copy(BGC_FP64_Position2* destination, const BGC_FP64_Position2* source);
|
||||
|
|
|
|||
|
|
@ -3,17 +3,17 @@
|
|||
|
||||
#include "vector2.h"
|
||||
#include "affine2.h"
|
||||
#include "cotes-number.h"
|
||||
#include "turn2.h"
|
||||
|
||||
// ==================== Types ==================== //
|
||||
|
||||
typedef struct {
|
||||
BGC_FP32_CotesNumber turn;
|
||||
BGC_FP32_Turn2 turn;
|
||||
BGC_FP32_Vector2 shift;
|
||||
} BGC_FP32_Position2;
|
||||
|
||||
typedef struct {
|
||||
BGC_FP64_CotesNumber turn;
|
||||
BGC_FP64_Turn2 turn;
|
||||
BGC_FP64_Vector2 shift;
|
||||
} BGC_FP64_Position2;
|
||||
|
||||
|
|
@ -21,27 +21,27 @@ typedef struct {
|
|||
|
||||
inline void bgc_fp32_position2_reset(BGC_FP32_Position2* position)
|
||||
{
|
||||
bgc_fp32_cotes_number_reset(&position->turn);
|
||||
bgc_fp32_turn2_reset(&position->turn);
|
||||
bgc_fp32_vector2_reset(&position->shift);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position2_reset(BGC_FP64_Position2* position)
|
||||
{
|
||||
bgc_fp64_cotes_number_reset(&position->turn);
|
||||
bgc_fp64_turn2_reset(&position->turn);
|
||||
bgc_fp64_vector2_reset(&position->shift);
|
||||
}
|
||||
|
||||
// ==================== Make ===================== //
|
||||
|
||||
inline void bgc_fp32_position2_make(BGC_FP32_Position2* position, const BGC_FP32_CotesNumber* turn, const BGC_FP32_Vector2* shift)
|
||||
inline void bgc_fp32_position2_make(BGC_FP32_Position2* position, const BGC_FP32_Turn2* turn, const BGC_FP32_Vector2* shift)
|
||||
{
|
||||
bgc_fp32_cotes_number_copy(&position->turn, turn);
|
||||
bgc_fp32_turn2_copy(&position->turn, turn);
|
||||
bgc_fp32_vector2_copy(&position->shift, shift);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position2_make(BGC_FP64_Position2* position, const BGC_FP64_CotesNumber* turn, const BGC_FP64_Vector2* shift)
|
||||
inline void bgc_fp64_position2_make(BGC_FP64_Position2* position, const BGC_FP64_Turn2* turn, const BGC_FP64_Vector2* shift)
|
||||
{
|
||||
bgc_fp64_cotes_number_copy(&position->turn, turn);
|
||||
bgc_fp64_turn2_copy(&position->turn, turn);
|
||||
bgc_fp64_vector2_copy(&position->shift, shift);
|
||||
}
|
||||
|
||||
|
|
@ -50,13 +50,13 @@ inline void bgc_fp64_position2_make(BGC_FP64_Position2* position, const BGC_FP64
|
|||
|
||||
inline void bgc_fp32_position2_copy(BGC_FP32_Position2* destination, const BGC_FP32_Position2* source)
|
||||
{
|
||||
bgc_fp32_cotes_number_copy(&destination->turn, &source->turn);
|
||||
bgc_fp32_turn2_copy(&destination->turn, &source->turn);
|
||||
bgc_fp32_vector2_copy(&destination->shift, &source->shift);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position2_copy(BGC_FP64_Position2* destination, const BGC_FP64_Position2* source)
|
||||
{
|
||||
bgc_fp64_cotes_number_copy(&destination->turn, &source->turn);
|
||||
bgc_fp64_turn2_copy(&destination->turn, &source->turn);
|
||||
bgc_fp64_vector2_copy(&destination->shift, &source->shift);
|
||||
}
|
||||
|
||||
|
|
@ -64,13 +64,13 @@ inline void bgc_fp64_position2_copy(BGC_FP64_Position2* destination, const BGC_F
|
|||
|
||||
inline void bgc_fp32_position2_swap(BGC_FP32_Position2 * first, BGC_FP32_Position2 * second)
|
||||
{
|
||||
bgc_fp32_cotes_number_swap(&first->turn, &second->turn);
|
||||
bgc_fp32_turn2_swap(&first->turn, &second->turn);
|
||||
bgc_fp32_vector2_swap(&first->shift, &second->shift);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position2_swap(BGC_FP64_Position2 * first, BGC_FP64_Position2 * second)
|
||||
{
|
||||
bgc_fp64_cotes_number_swap(&first->turn, &second->turn);
|
||||
bgc_fp64_turn2_swap(&first->turn, &second->turn);
|
||||
bgc_fp64_vector2_swap(&first->shift, &second->shift);
|
||||
}
|
||||
|
||||
|
|
@ -78,13 +78,13 @@ inline void bgc_fp64_position2_swap(BGC_FP64_Position2 * first, BGC_FP64_Positio
|
|||
|
||||
inline void bgc_fp64_position2_convert_to_fp32(BGC_FP32_Position2* destination, const BGC_FP64_Position2 * source)
|
||||
{
|
||||
bgc_fp64_cotes_number_convert_to_fp32(&destination->turn, &source->turn);
|
||||
bgc_fp64_turn2_convert_to_fp32(&destination->turn, &source->turn);
|
||||
bgc_fp64_vector2_convert_to_fp32(&destination->shift, &source->shift);
|
||||
}
|
||||
|
||||
inline void bgc_fp32_position2_convert_to_fp64(BGC_FP64_Position2* destination, const BGC_FP32_Position2 * source)
|
||||
{
|
||||
bgc_fp32_cotes_number_convert_to_fp64(&destination->turn, &source->turn);
|
||||
bgc_fp32_turn2_convert_to_fp64(&destination->turn, &source->turn);
|
||||
bgc_fp32_vector2_convert_to_fp64(&destination->shift, &source->shift);
|
||||
}
|
||||
|
||||
|
|
@ -92,27 +92,27 @@ inline void bgc_fp32_position2_convert_to_fp64(BGC_FP64_Position2* destination,
|
|||
|
||||
inline int bgc_fp32_position2_is_idle(const BGC_FP32_Position2 * position)
|
||||
{
|
||||
return bgc_fp32_vector2_is_zero(&position->shift) && bgc_fp32_cotes_number_is_idle(&position->turn);
|
||||
return bgc_fp32_vector2_is_zero(&position->shift) && bgc_fp32_turn2_is_idle(&position->turn);
|
||||
}
|
||||
|
||||
inline int bgc_fp64_position2_is_idle(const BGC_FP64_Position2 * position)
|
||||
{
|
||||
return bgc_fp64_vector2_is_zero(&position->shift) && bgc_fp64_cotes_number_is_idle(&position->turn);
|
||||
return bgc_fp64_vector2_is_zero(&position->shift) && bgc_fp64_turn2_is_idle(&position->turn);
|
||||
}
|
||||
|
||||
// =================== Invert ==================== //
|
||||
|
||||
inline void bgc_fp32_position2_invert(BGC_FP32_Position2 * position)
|
||||
{
|
||||
bgc_fp32_cotes_number_turn_vector_back(&position->shift, &position->turn, &position->shift);
|
||||
bgc_fp32_cotes_number_revert(&position->turn);
|
||||
bgc_fp32_turn2_vector_back(&position->shift, &position->turn, &position->shift);
|
||||
bgc_fp32_turn2_revert(&position->turn);
|
||||
bgc_fp32_vector2_revert(&position->shift);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position2_invert(BGC_FP64_Position2 * position)
|
||||
{
|
||||
bgc_fp64_cotes_number_turn_vector_back(&position->shift, &position->turn, &position->shift);
|
||||
bgc_fp64_cotes_number_revert(&position->turn);
|
||||
bgc_fp64_turn2_vector_back(&position->shift, &position->turn, &position->shift);
|
||||
bgc_fp64_turn2_revert(&position->turn);
|
||||
bgc_fp64_vector2_revert(&position->shift);
|
||||
}
|
||||
|
||||
|
|
@ -120,15 +120,15 @@ inline void bgc_fp64_position2_invert(BGC_FP64_Position2 * position)
|
|||
|
||||
inline void bgc_fp32_position2_get_inverse(BGC_FP32_Position2* inverted, const BGC_FP32_Position2 * position)
|
||||
{
|
||||
bgc_fp32_cotes_number_turn_vector_back(&inverted->shift, &position->turn, &position->shift);
|
||||
bgc_fp32_cotes_number_get_reverse(&inverted->turn, &position->turn);
|
||||
bgc_fp32_turn2_vector_back(&inverted->shift, &position->turn, &position->shift);
|
||||
bgc_fp32_turn2_get_reverse(&inverted->turn, &position->turn);
|
||||
bgc_fp32_vector2_revert(&inverted->shift);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position2_get_inverse(BGC_FP64_Position2* inverted, const BGC_FP64_Position2 * position)
|
||||
{
|
||||
bgc_fp64_cotes_number_turn_vector_back(&inverted->shift, &position->turn, &position->shift);
|
||||
bgc_fp64_cotes_number_get_reverse(&inverted->turn, &position->turn);
|
||||
bgc_fp64_turn2_vector_back(&inverted->shift, &position->turn, &position->shift);
|
||||
bgc_fp64_turn2_get_reverse(&inverted->turn, &position->turn);
|
||||
bgc_fp64_vector2_revert(&inverted->shift);
|
||||
}
|
||||
|
||||
|
|
@ -137,16 +137,16 @@ inline void bgc_fp64_position2_get_inverse(BGC_FP64_Position2* inverted, const B
|
|||
inline void bgc_fp32_position2_combine(BGC_FP32_Position2* combination, const BGC_FP32_Position2 * first, const BGC_FP32_Position2 * second)
|
||||
{
|
||||
BGC_FP32_Vector2 relative_shift;
|
||||
bgc_fp32_cotes_number_turn_vector(&relative_shift, &second->turn, &first->shift);
|
||||
bgc_fp32_cotes_number_combine(&combination->turn, &first->turn, &second->turn);
|
||||
bgc_fp32_turn2_vector(&relative_shift, &second->turn, &first->shift);
|
||||
bgc_fp32_turn2_combine(&combination->turn, &first->turn, &second->turn);
|
||||
bgc_fp32_vector2_add(&combination->shift, &second->shift, &relative_shift);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position2_combine(BGC_FP64_Position2* combination, const BGC_FP64_Position2 * first, const BGC_FP64_Position2 * second)
|
||||
{
|
||||
BGC_FP64_Vector2 relative_shift;
|
||||
bgc_fp64_cotes_number_turn_vector(&relative_shift, &second->turn, &first->shift);
|
||||
bgc_fp64_cotes_number_combine(&combination->turn, &first->turn, &second->turn);
|
||||
bgc_fp64_turn2_vector(&relative_shift, &second->turn, &first->shift);
|
||||
bgc_fp64_turn2_combine(&combination->turn, &first->turn, &second->turn);
|
||||
bgc_fp64_vector2_add(&combination->shift, &second->shift, &relative_shift);
|
||||
}
|
||||
|
||||
|
|
@ -156,29 +156,29 @@ inline void bgc_fp32_position2_exclude(BGC_FP32_Position2* difference, const BGC
|
|||
{
|
||||
BGC_FP32_Vector2 relative_shift;
|
||||
bgc_fp32_vector2_subtract(&relative_shift, &base->shift, &excludand->shift);
|
||||
bgc_fp32_cotes_number_turn_vector_back(&difference->shift, &excludand->turn, &relative_shift);
|
||||
bgc_fp32_cotes_number_exclude(&difference->turn, &base->turn, &excludand->turn);
|
||||
bgc_fp32_turn2_vector_back(&difference->shift, &excludand->turn, &relative_shift);
|
||||
bgc_fp32_turn2_exclude(&difference->turn, &base->turn, &excludand->turn);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position2_exclude(BGC_FP64_Position2* difference, const BGC_FP64_Position2 * base, const BGC_FP64_Position2 * excludand)
|
||||
{
|
||||
BGC_FP64_Vector2 relative_shift;
|
||||
bgc_fp64_vector2_subtract(&relative_shift, &base->shift, &excludand->shift);
|
||||
bgc_fp64_cotes_number_turn_vector_back(&difference->shift, &excludand->turn, &relative_shift);
|
||||
bgc_fp64_cotes_number_exclude(&difference->turn, &base->turn, &excludand->turn);
|
||||
bgc_fp64_turn2_vector_back(&difference->shift, &excludand->turn, &relative_shift);
|
||||
bgc_fp64_turn2_exclude(&difference->turn, &base->turn, &excludand->turn);
|
||||
}
|
||||
|
||||
// ============= Get Outward Affine ============== //
|
||||
|
||||
inline void bgc_fp32_position2_get_outward_affine(BGC_FP32_Affine2* outward_affine_map, const BGC_FP32_Position2 * position)
|
||||
{
|
||||
bgc_fp32_cotes_number_get_rotation_matrix(&outward_affine_map->distortion, &position->turn);
|
||||
bgc_fp32_turn2_get_rotation_matrix(&outward_affine_map->distortion, &position->turn);
|
||||
bgc_fp32_vector2_copy(&outward_affine_map->shift, &position->shift);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position2_get_outward_affine(BGC_FP64_Affine2* outward_affine_map, const BGC_FP64_Position2 * position)
|
||||
{
|
||||
bgc_fp64_cotes_number_get_rotation_matrix(&outward_affine_map->distortion, &position->turn);
|
||||
bgc_fp64_turn2_get_rotation_matrix(&outward_affine_map->distortion, &position->turn);
|
||||
bgc_fp64_vector2_copy(&outward_affine_map->shift, &position->shift);
|
||||
}
|
||||
|
||||
|
|
@ -186,14 +186,14 @@ inline void bgc_fp64_position2_get_outward_affine(BGC_FP64_Affine2* outward_affi
|
|||
|
||||
inline void bgc_fp32_position2_get_inward_affine(BGC_FP32_Affine2* inward_affine_map, const BGC_FP32_Position2 * position)
|
||||
{
|
||||
bgc_fp32_cotes_number_get_reverse_matrix(&inward_affine_map->distortion, &position->turn);
|
||||
bgc_fp32_turn2_get_reverse_matrix(&inward_affine_map->distortion, &position->turn);
|
||||
bgc_fp32_multiply_matrix2x2_by_vector2(&inward_affine_map->shift, &inward_affine_map->distortion, &position->shift);
|
||||
bgc_fp32_vector2_revert(&inward_affine_map->shift);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position2_get_inward_affine(BGC_FP64_Affine2* inward_affine_map, const BGC_FP64_Position2 * position)
|
||||
{
|
||||
bgc_fp64_cotes_number_get_reverse_matrix(&inward_affine_map->distortion, &position->turn);
|
||||
bgc_fp64_turn2_get_reverse_matrix(&inward_affine_map->distortion, &position->turn);
|
||||
bgc_fp64_multiply_matrix2x2_by_vector2(&inward_affine_map->shift, &inward_affine_map->distortion, &position->shift);
|
||||
bgc_fp64_vector2_revert(&inward_affine_map->shift);
|
||||
}
|
||||
|
|
@ -203,14 +203,14 @@ inline void bgc_fp64_position2_get_inward_affine(BGC_FP64_Affine2* inward_affine
|
|||
inline void bgc_fp32_position2_transform_point_outwards(BGC_FP32_Vector2* outer_point, const BGC_FP32_Position2 * position, const BGC_FP32_Vector2 * inner_point)
|
||||
{
|
||||
BGC_FP32_Vector2 turned_point;
|
||||
bgc_fp32_cotes_number_turn_vector(&turned_point, &position->turn, inner_point);
|
||||
bgc_fp32_turn2_vector(&turned_point, &position->turn, inner_point);
|
||||
bgc_fp32_vector2_add(outer_point, &position->shift, &turned_point);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position2_transform_point_outwards(BGC_FP64_Vector2* outer_point, const BGC_FP64_Position2 * position, const BGC_FP64_Vector2 * inner_point)
|
||||
{
|
||||
BGC_FP64_Vector2 turned_point;
|
||||
bgc_fp64_cotes_number_turn_vector(&turned_point, &position->turn, inner_point);
|
||||
bgc_fp64_turn2_vector(&turned_point, &position->turn, inner_point);
|
||||
bgc_fp64_vector2_add(outer_point, &position->shift, &turned_point);
|
||||
}
|
||||
|
||||
|
|
@ -220,7 +220,7 @@ inline void bgc_fp32_position2_transform_point_inwards(BGC_FP32_Vector2* inner_p
|
|||
{
|
||||
BGC_FP32_Vector2 relative_point;
|
||||
bgc_fp32_vector2_subtract(&relative_point, outer_point, &position->shift);
|
||||
bgc_fp32_cotes_number_turn_vector_back(inner_point, &position->turn, &relative_point);
|
||||
bgc_fp32_turn2_vector_back(inner_point, &position->turn, &relative_point);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -228,7 +228,7 @@ inline void bgc_fp64_position2_transform_point_inwards(BGC_FP64_Vector2* inner_p
|
|||
{
|
||||
BGC_FP64_Vector2 relative_point;
|
||||
bgc_fp64_vector2_subtract(&relative_point, outer_point, &position->shift);
|
||||
bgc_fp64_cotes_number_turn_vector_back(inner_point, &position->turn, &relative_point);
|
||||
bgc_fp64_turn2_vector_back(inner_point, &position->turn, &relative_point);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -236,24 +236,24 @@ inline void bgc_fp64_position2_transform_point_inwards(BGC_FP64_Vector2* inner_p
|
|||
|
||||
inline void bgc_fp32_position2_transform_vector_outwards(BGC_FP32_Vector2* outer_vector, const BGC_FP32_Position2 * position, const BGC_FP32_Vector2 * inner_vector)
|
||||
{
|
||||
bgc_fp32_cotes_number_turn_vector(outer_vector, &position->turn, inner_vector);
|
||||
bgc_fp32_turn2_vector(outer_vector, &position->turn, inner_vector);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position2_transform_vector_outwards(BGC_FP64_Vector2* outer_vector, const BGC_FP64_Position2 * position, const BGC_FP64_Vector2 * inner_vector)
|
||||
{
|
||||
bgc_fp64_cotes_number_turn_vector(outer_vector, &position->turn, inner_vector);
|
||||
bgc_fp64_turn2_vector(outer_vector, &position->turn, inner_vector);
|
||||
}
|
||||
|
||||
// ========== Transform Vector Inwards =========== //
|
||||
|
||||
inline void bgc_fp32_position2_transform_vector_inwards(BGC_FP32_Vector2* inner_vector, const BGC_FP32_Position2 * position, const BGC_FP32_Vector2 * outer_vector)
|
||||
{
|
||||
bgc_fp32_cotes_number_turn_vector_back(inner_vector, &position->turn, outer_vector);
|
||||
bgc_fp32_turn2_vector_back(inner_vector, &position->turn, outer_vector);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position2_transform_vector_inwards(BGC_FP64_Vector2* inner_vector, const BGC_FP64_Position2 * position, const BGC_FP64_Vector2 * outer_vector)
|
||||
{
|
||||
bgc_fp64_cotes_number_turn_vector_back(inner_vector, &position->turn, outer_vector);
|
||||
bgc_fp64_turn2_vector_back(inner_vector, &position->turn, outer_vector);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
extern inline void bgc_fp32_position3_reset(BGC_FP32_Position3 * node);
|
||||
extern inline void bgc_fp64_position3_reset(BGC_FP64_Position3 * node);
|
||||
|
||||
extern inline void bgc_fp32_position3_make(BGC_FP32_Position3* position, const BGC_FP32_Versor* turn, const BGC_FP32_Vector3* shift);
|
||||
extern inline void bgc_fp64_position3_make(BGC_FP64_Position3* position, const BGC_FP64_Versor * turn, const BGC_FP64_Vector3 * shift);
|
||||
extern inline void bgc_fp32_position3_make(BGC_FP32_Position3* position, const BGC_FP32_Turn3* turn, const BGC_FP32_Vector3* shift);
|
||||
extern inline void bgc_fp64_position3_make(BGC_FP64_Position3* position, const BGC_FP64_Turn3 * turn, const BGC_FP64_Vector3 * shift);
|
||||
|
||||
extern inline void bgc_fp32_position3_copy(BGC_FP32_Position3* destination, const BGC_FP32_Position3* source);
|
||||
extern inline void bgc_fp64_position3_copy(BGC_FP64_Position3* destination, const BGC_FP64_Position3 * source);
|
||||
|
|
|
|||
|
|
@ -3,17 +3,17 @@
|
|||
|
||||
#include "vector3.h"
|
||||
#include "affine3.h"
|
||||
#include "versor.h"
|
||||
#include "turn3.h"
|
||||
|
||||
// ==================== Types ==================== //
|
||||
|
||||
typedef struct {
|
||||
BGC_FP32_Versor turn;
|
||||
BGC_FP32_Turn3 turn;
|
||||
BGC_FP32_Vector3 shift;
|
||||
} BGC_FP32_Position3;
|
||||
|
||||
typedef struct {
|
||||
BGC_FP64_Versor turn;
|
||||
BGC_FP64_Turn3 turn;
|
||||
BGC_FP64_Vector3 shift;
|
||||
} BGC_FP64_Position3;
|
||||
|
||||
|
|
@ -21,27 +21,27 @@ typedef struct {
|
|||
|
||||
inline void bgc_fp32_position3_reset(BGC_FP32_Position3 * position)
|
||||
{
|
||||
bgc_fp32_versor_reset(&position->turn);
|
||||
bgc_fp32_turn3_reset(&position->turn);
|
||||
bgc_fp32_vector3_reset(&position->shift);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position3_reset(BGC_FP64_Position3 * position)
|
||||
{
|
||||
bgc_fp64_versor_reset(&position->turn);
|
||||
bgc_fp64_turn3_reset(&position->turn);
|
||||
bgc_fp64_vector3_reset(&position->shift);
|
||||
}
|
||||
|
||||
// ==================== Make ===================== //
|
||||
|
||||
inline void bgc_fp32_position3_make(BGC_FP32_Position3* position, const BGC_FP32_Versor * turn, const BGC_FP32_Vector3 * shift)
|
||||
inline void bgc_fp32_position3_make(BGC_FP32_Position3* position, const BGC_FP32_Turn3 * turn, const BGC_FP32_Vector3 * shift)
|
||||
{
|
||||
bgc_fp32_versor_copy(&position->turn, turn);
|
||||
bgc_fp32_turn3_copy(&position->turn, turn);
|
||||
bgc_fp32_vector3_copy(&position->shift, shift);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position3_make(BGC_FP64_Position3* position, const BGC_FP64_Versor * turn, const BGC_FP64_Vector3 * shift)
|
||||
inline void bgc_fp64_position3_make(BGC_FP64_Position3* position, const BGC_FP64_Turn3 * turn, const BGC_FP64_Vector3 * shift)
|
||||
{
|
||||
bgc_fp64_versor_copy(&position->turn, turn);
|
||||
bgc_fp64_turn3_copy(&position->turn, turn);
|
||||
bgc_fp64_vector3_copy(&position->shift, shift);
|
||||
}
|
||||
|
||||
|
|
@ -49,13 +49,13 @@ inline void bgc_fp64_position3_make(BGC_FP64_Position3* position, const BGC_FP64
|
|||
|
||||
inline void bgc_fp32_position3_copy(BGC_FP32_Position3* destination, const BGC_FP32_Position3 * source)
|
||||
{
|
||||
bgc_fp32_versor_copy(&destination->turn, &source->turn);
|
||||
bgc_fp32_turn3_copy(&destination->turn, &source->turn);
|
||||
bgc_fp32_vector3_copy(&destination->shift, &source->shift);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position3_copy(BGC_FP64_Position3* destination, const BGC_FP64_Position3 * source)
|
||||
{
|
||||
bgc_fp64_versor_copy(&destination->turn, &source->turn);
|
||||
bgc_fp64_turn3_copy(&destination->turn, &source->turn);
|
||||
bgc_fp64_vector3_copy(&destination->shift, &source->shift);
|
||||
}
|
||||
|
||||
|
|
@ -63,13 +63,13 @@ inline void bgc_fp64_position3_copy(BGC_FP64_Position3* destination, const BGC_F
|
|||
|
||||
inline void bgc_fp32_position3_swap(BGC_FP32_Position3 * first, BGC_FP32_Position3 * second)
|
||||
{
|
||||
bgc_fp32_versor_swap(&first->turn, &second->turn);
|
||||
bgc_fp32_turn3_swap(&first->turn, &second->turn);
|
||||
bgc_fp32_vector3_swap(&first->shift, &second->shift);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position3_swap(BGC_FP64_Position3 * first, BGC_FP64_Position3 * second)
|
||||
{
|
||||
bgc_fp64_versor_swap(&first->turn, &second->turn);
|
||||
bgc_fp64_turn3_swap(&first->turn, &second->turn);
|
||||
bgc_fp64_vector3_swap(&first->shift, &second->shift);
|
||||
}
|
||||
|
||||
|
|
@ -77,13 +77,13 @@ inline void bgc_fp64_position3_swap(BGC_FP64_Position3 * first, BGC_FP64_Positio
|
|||
|
||||
inline void bgc_fp32_position3_convert_to_fp64(BGC_FP64_Position3* destination, const BGC_FP32_Position3 * source)
|
||||
{
|
||||
bgc_fp32_versor_convert_to_fp64(&destination->turn, &source->turn);
|
||||
bgc_fp32_turn3_convert_to_fp64(&destination->turn, &source->turn);
|
||||
bgc_fp32_vector3_convert_to_fp64(&destination->shift, &source->shift);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position3_convert_to_fp32(BGC_FP32_Position3* destination, const BGC_FP64_Position3* source)
|
||||
{
|
||||
bgc_fp64_versor_convert_to_fp32(&destination->turn, &source->turn);
|
||||
bgc_fp64_turn3_convert_to_fp32(&destination->turn, &source->turn);
|
||||
bgc_fp64_vector3_convert_to_fp32(&destination->shift, &source->shift);
|
||||
}
|
||||
|
||||
|
|
@ -91,27 +91,27 @@ inline void bgc_fp64_position3_convert_to_fp32(BGC_FP32_Position3* destination,
|
|||
|
||||
inline int bgc_fp32_position3_is_idle(const BGC_FP32_Position3 * position)
|
||||
{
|
||||
return bgc_fp32_vector3_is_zero(&position->shift) && bgc_fp32_versor_is_idle(&position->turn);
|
||||
return bgc_fp32_vector3_is_zero(&position->shift) && bgc_fp32_turn3_is_idle(&position->turn);
|
||||
}
|
||||
|
||||
inline int bgc_fp64_position3_is_idle(const BGC_FP64_Position3 * position)
|
||||
{
|
||||
return bgc_fp64_vector3_is_zero(&position->shift) && bgc_fp64_versor_is_idle(&position->turn);
|
||||
return bgc_fp64_vector3_is_zero(&position->shift) && bgc_fp64_turn3_is_idle(&position->turn);
|
||||
}
|
||||
|
||||
// =================== Invert ==================== //
|
||||
|
||||
inline void bgc_fp32_position3_invert(BGC_FP32_Position3 * position)
|
||||
{
|
||||
bgc_fp32_versor_turn_vector_back(&position->shift, &position->turn, &position->shift);
|
||||
bgc_fp32_versor_revert(&position->turn);
|
||||
bgc_fp32_turn3_vector_back(&position->shift, &position->turn, &position->shift);
|
||||
bgc_fp32_turn3_revert(&position->turn);
|
||||
bgc_fp32_vector3_revert(&position->shift);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position3_invert(BGC_FP64_Position3 * position)
|
||||
{
|
||||
bgc_fp64_versor_turn_vector_back(&position->shift, &position->turn, &position->shift);
|
||||
bgc_fp64_versor_revert(&position->turn);
|
||||
bgc_fp64_turn3_vector_back(&position->shift, &position->turn, &position->shift);
|
||||
bgc_fp64_turn3_revert(&position->turn);
|
||||
bgc_fp64_vector3_revert(&position->shift);
|
||||
}
|
||||
|
||||
|
|
@ -119,15 +119,15 @@ inline void bgc_fp64_position3_invert(BGC_FP64_Position3 * position)
|
|||
|
||||
inline void bgc_fp32_position3_get_inverse(BGC_FP32_Position3* inverse, const BGC_FP32_Position3 * position)
|
||||
{
|
||||
bgc_fp32_versor_turn_vector_back(&inverse->shift, &position->turn, &position->shift);
|
||||
bgc_fp32_versor_get_reverse(&inverse->turn, &position->turn);
|
||||
bgc_fp32_turn3_vector_back(&inverse->shift, &position->turn, &position->shift);
|
||||
bgc_fp32_turn3_get_reverse(&inverse->turn, &position->turn);
|
||||
bgc_fp32_vector3_revert(&inverse->shift);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position3_get_inverse(BGC_FP64_Position3* inverse, const BGC_FP64_Position3 * position)
|
||||
{
|
||||
bgc_fp64_versor_turn_vector_back(&inverse->shift, &position->turn, &position->shift);
|
||||
bgc_fp64_versor_get_reverse(&inverse->turn, &position->turn);
|
||||
bgc_fp64_turn3_vector_back(&inverse->shift, &position->turn, &position->shift);
|
||||
bgc_fp64_turn3_get_reverse(&inverse->turn, &position->turn);
|
||||
bgc_fp64_vector3_revert(&inverse->shift);
|
||||
}
|
||||
|
||||
|
|
@ -136,16 +136,16 @@ inline void bgc_fp64_position3_get_inverse(BGC_FP64_Position3* inverse, const BG
|
|||
inline void bgc_fp32_position3_combine(BGC_FP32_Position3* combination, const BGC_FP32_Position3 * first, const BGC_FP32_Position3 * second)
|
||||
{
|
||||
BGC_FP32_Vector3 relative_shift;
|
||||
bgc_fp32_versor_turn_vector(&relative_shift, &second->turn, &first->shift);
|
||||
bgc_fp32_versor_combine(&combination->turn, &first->turn, &second->turn);
|
||||
bgc_fp32_turn3_vector(&relative_shift, &second->turn, &first->shift);
|
||||
bgc_fp32_turn3_combine(&combination->turn, &first->turn, &second->turn);
|
||||
bgc_fp32_vector3_add(&combination->shift, &relative_shift, &second->shift);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position3_combine(BGC_FP64_Position3* combination, const BGC_FP64_Position3 * first, const BGC_FP64_Position3 * second)
|
||||
{
|
||||
BGC_FP64_Vector3 relative_shift;
|
||||
bgc_fp64_versor_turn_vector(&relative_shift, &second->turn, &first->shift);
|
||||
bgc_fp64_versor_combine(&combination->turn, &first->turn, &second->turn);
|
||||
bgc_fp64_turn3_vector(&relative_shift, &second->turn, &first->shift);
|
||||
bgc_fp64_turn3_combine(&combination->turn, &first->turn, &second->turn);
|
||||
bgc_fp64_vector3_add(&combination->shift, &relative_shift, &second->shift);
|
||||
}
|
||||
|
||||
|
|
@ -155,29 +155,29 @@ inline void bgc_fp32_position3_exclude(BGC_FP32_Position3* difference, const BGC
|
|||
{
|
||||
BGC_FP32_Vector3 relative_shift;
|
||||
bgc_fp32_vector3_subtract(&relative_shift, &base->shift, &excludant->shift);
|
||||
bgc_fp32_versor_turn_vector_back(&difference->shift, &excludant->turn, &relative_shift);
|
||||
bgc_fp32_versor_exclude(&difference->turn, &base->turn, &excludant->turn);
|
||||
bgc_fp32_turn3_vector_back(&difference->shift, &excludant->turn, &relative_shift);
|
||||
bgc_fp32_turn3_exclude(&difference->turn, &base->turn, &excludant->turn);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position3_exclude(BGC_FP64_Position3* difference, const BGC_FP64_Position3 * base, const BGC_FP64_Position3 * excludant)
|
||||
{
|
||||
BGC_FP64_Vector3 relative_shift;
|
||||
bgc_fp64_vector3_subtract(&relative_shift, &base->shift, &excludant->shift);
|
||||
bgc_fp64_versor_turn_vector_back(&difference->shift, &excludant->turn, &relative_shift);
|
||||
bgc_fp64_versor_exclude(&difference->turn, &base->turn, &excludant->turn);
|
||||
bgc_fp64_turn3_vector_back(&difference->shift, &excludant->turn, &relative_shift);
|
||||
bgc_fp64_turn3_exclude(&difference->turn, &base->turn, &excludant->turn);
|
||||
}
|
||||
|
||||
// ============= Get Outward Affine ============== //
|
||||
|
||||
inline void bgc_fp32_position3_get_outward_affine(BGC_FP32_Affine3* outward_affine_map, const BGC_FP32_Position3 * position)
|
||||
{
|
||||
bgc_fp32_versor_get_rotation_matrix(&outward_affine_map->distortion, &position->turn);
|
||||
bgc_fp32_turn3_get_rotation_matrix(&outward_affine_map->distortion, &position->turn);
|
||||
bgc_fp32_vector3_copy(&outward_affine_map->shift, &position->shift);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position3_get_outward_affine(BGC_FP64_Affine3* outward_affine_map, const BGC_FP64_Position3 * position)
|
||||
{
|
||||
bgc_fp64_versor_get_rotation_matrix(&outward_affine_map->distortion, &position->turn);
|
||||
bgc_fp64_turn3_get_rotation_matrix(&outward_affine_map->distortion, &position->turn);
|
||||
bgc_fp64_vector3_copy(&outward_affine_map->shift, &position->shift);
|
||||
}
|
||||
|
||||
|
|
@ -185,14 +185,14 @@ inline void bgc_fp64_position3_get_outward_affine(BGC_FP64_Affine3* outward_affi
|
|||
|
||||
inline void bgc_fp32_position3_get_inward_affine(BGC_FP32_Affine3* inward_affine_map, const BGC_FP32_Position3 * position)
|
||||
{
|
||||
bgc_fp32_versor_get_reverse_matrix(&inward_affine_map->distortion, &position->turn);
|
||||
bgc_fp32_turn3_get_reverse_matrix(&inward_affine_map->distortion, &position->turn);
|
||||
bgc_fp32_multiply_matrix3x3_by_vector3(&inward_affine_map->shift, &inward_affine_map->distortion, &position->shift);
|
||||
bgc_fp32_vector3_revert(&inward_affine_map->shift);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position3_get_inward_affine(BGC_FP64_Affine3* inward_affine_map, const BGC_FP64_Position3 * position)
|
||||
{
|
||||
bgc_fp64_versor_get_reverse_matrix(&inward_affine_map->distortion, &position->turn);
|
||||
bgc_fp64_turn3_get_reverse_matrix(&inward_affine_map->distortion, &position->turn);
|
||||
bgc_fp64_multiply_matrix3x3_by_vector3(&inward_affine_map->shift, &inward_affine_map->distortion, &position->shift);
|
||||
bgc_fp64_vector3_revert(&inward_affine_map->shift);
|
||||
}
|
||||
|
|
@ -202,14 +202,14 @@ inline void bgc_fp64_position3_get_inward_affine(BGC_FP64_Affine3* inward_affine
|
|||
inline void bgc_fp32_position3_transform_point_outwards(BGC_FP32_Vector3* outer_point, const BGC_FP32_Position3 * position, const BGC_FP32_Vector3 * inner_point)
|
||||
{
|
||||
BGC_FP32_Vector3 turned_point;
|
||||
bgc_fp32_versor_turn_vector(&turned_point, &position->turn, inner_point);
|
||||
bgc_fp32_turn3_vector(&turned_point, &position->turn, inner_point);
|
||||
bgc_fp32_vector3_add(outer_point, &position->shift, &turned_point);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position3_transform_point_outwards(BGC_FP64_Vector3* outer_point, const BGC_FP64_Position3 * position, const BGC_FP64_Vector3 * inner_point)
|
||||
{
|
||||
BGC_FP64_Vector3 turned_point;
|
||||
bgc_fp64_versor_turn_vector(&turned_point, &position->turn, inner_point);
|
||||
bgc_fp64_turn3_vector(&turned_point, &position->turn, inner_point);
|
||||
bgc_fp64_vector3_add(outer_point, &position->shift, &turned_point);
|
||||
}
|
||||
|
||||
|
|
@ -219,7 +219,7 @@ inline void bgc_fp32_position3_transform_point_inwards(BGC_FP32_Vector3* inner_p
|
|||
{
|
||||
BGC_FP32_Vector3 relative_point;
|
||||
bgc_fp32_vector3_subtract(&relative_point, outer_point, &position->shift);
|
||||
bgc_fp32_versor_turn_vector_back(inner_point, &position->turn, &relative_point);
|
||||
bgc_fp32_turn3_vector_back(inner_point, &position->turn, &relative_point);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -227,7 +227,7 @@ inline void bgc_fp64_position3_transform_point_inwards(BGC_FP64_Vector3* inner_p
|
|||
{
|
||||
BGC_FP64_Vector3 relative_point;
|
||||
bgc_fp64_vector3_subtract(&relative_point, outer_point, &position->shift);
|
||||
bgc_fp64_versor_turn_vector_back(inner_point, &position->turn, &relative_point);
|
||||
bgc_fp64_turn3_vector_back(inner_point, &position->turn, &relative_point);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -235,24 +235,24 @@ inline void bgc_fp64_position3_transform_point_inwards(BGC_FP64_Vector3* inner_p
|
|||
|
||||
inline void bgc_fp32_position3_transform_vector_outwards(BGC_FP32_Vector3* outer_vector, const BGC_FP32_Position3 * position, const BGC_FP32_Vector3 * inner_vector)
|
||||
{
|
||||
bgc_fp32_versor_turn_vector(outer_vector, &position->turn, inner_vector);
|
||||
bgc_fp32_turn3_vector(outer_vector, &position->turn, inner_vector);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position3_transform_vector_outwards(BGC_FP64_Vector3* outer_vector, const BGC_FP64_Position3 * position, const BGC_FP64_Vector3 * inner_vector)
|
||||
{
|
||||
bgc_fp64_versor_turn_vector(outer_vector, &position->turn, inner_vector);
|
||||
bgc_fp64_turn3_vector(outer_vector, &position->turn, inner_vector);
|
||||
}
|
||||
|
||||
// ========== Transform Vector Inwards =========== //
|
||||
|
||||
inline void bgc_fp32_position3_transform_vector_inwards(BGC_FP32_Vector3* inner_vector, const BGC_FP32_Position3 * position, const BGC_FP32_Vector3 * outer_vector)
|
||||
{
|
||||
bgc_fp32_versor_turn_vector_back(inner_vector, &position->turn, outer_vector);
|
||||
bgc_fp32_turn3_vector_back(inner_vector, &position->turn, outer_vector);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_position3_transform_vector_inwards(BGC_FP64_Vector3* inner_vector, const BGC_FP64_Position3 * position, const BGC_FP64_Vector3 * outer_vector)
|
||||
{
|
||||
bgc_fp64_versor_turn_vector_back(inner_vector, &position->turn, outer_vector);
|
||||
bgc_fp64_turn3_vector_back(inner_vector, &position->turn, outer_vector);
|
||||
}
|
||||
|
||||
#endif // _BGC_POSITION_H_INCLUDED_
|
||||
|
|
|
|||
|
|
@ -43,6 +43,9 @@ extern inline void bgc_fp64_quaternion_subtract(BGC_FP64_Quaternion* difference,
|
|||
extern inline void bgc_fp32_quaternion_get_product(BGC_FP32_Quaternion* product, const BGC_FP32_Quaternion* left, const BGC_FP32_Quaternion* right);
|
||||
extern inline void bgc_fp64_quaternion_get_product(BGC_FP64_Quaternion* product, const BGC_FP64_Quaternion* left, const BGC_FP64_Quaternion* right);
|
||||
|
||||
extern inline void bgc_fp32_quaternion_get_product_by_conjugate(BGC_FP32_Quaternion* product, const BGC_FP32_Quaternion* left, const BGC_FP32_Quaternion* right);
|
||||
extern inline void bgc_fp64_quaternion_get_product_by_conjugate(BGC_FP64_Quaternion* product, const BGC_FP64_Quaternion* left, const BGC_FP64_Quaternion* right);
|
||||
|
||||
extern inline void bgc_fp32_quaternion_multiply(BGC_FP32_Quaternion* product, const BGC_FP32_Quaternion* multiplicand, const float multipier);
|
||||
extern inline void bgc_fp64_quaternion_multiply(BGC_FP64_Quaternion* product, const BGC_FP64_Quaternion* multiplicand, const double multipier);
|
||||
|
||||
|
|
|
|||
|
|
@ -273,6 +273,32 @@ inline void bgc_fp64_quaternion_get_product(BGC_FP64_Quaternion* product, const
|
|||
product->x3 = x3;
|
||||
}
|
||||
|
||||
inline void bgc_fp32_quaternion_get_product_by_conjugate(BGC_FP32_Quaternion* product, const BGC_FP32_Quaternion* left, const BGC_FP32_Quaternion* 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_get_product_by_conjugate(BGC_FP64_Quaternion* product, const BGC_FP64_Quaternion* left, const BGC_FP64_Quaternion* 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;
|
||||
}
|
||||
|
||||
inline void bgc_fp32_quaternion_multiply(BGC_FP32_Quaternion* product, const BGC_FP32_Quaternion* multiplicand, const float multipier)
|
||||
{
|
||||
product->s0 = multiplicand->s0 * multipier;
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
#include "rotation3.h"
|
||||
|
||||
const BGC_FP32_Rotation3 BGC_FP32_IDLE_ROTATION3 = { {0.0f, 0.0f, 0.0f}, 0.0f};
|
||||
|
||||
const BGC_FP64_Rotation3 BGC_FP64_IDLE_ROTATION3 = { {0.0, 0.0, 0.0}, 0.0};
|
||||
|
||||
extern inline void bgc_fp32_rotation3_reset(BGC_FP32_Rotation3* rotation);
|
||||
extern inline void bgc_fp64_rotation3_reset(BGC_FP64_Rotation3* rotation);
|
||||
|
||||
extern inline void bgc_fp32_rotation3_make(const float x1, const float x2, const float x3, const float angle, const int unit, BGC_FP32_Rotation3* rotation);
|
||||
extern inline void bgc_fp64_rotation3_make(const double x1, const double x2, const double x3, const double angle, const int unit, BGC_FP64_Rotation3* rotation);
|
||||
|
||||
extern inline void bgc_fp32_rotation3_make_for_axis(const BGC_FP32_Vector3* axis, const float angle, const int unit, BGC_FP32_Rotation3* rotation);
|
||||
extern inline void bgc_fp64_rotation3_make_for_axis(const BGC_FP64_Vector3* axis, const double angle, const int unit, BGC_FP64_Rotation3* rotation);
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
#ifndef _BGC_ROTATION3_H_
|
||||
#define _BGC_ROTATION3_H_
|
||||
|
||||
#include "utilities.h"
|
||||
#include "angle.h"
|
||||
#include "vector3.h"
|
||||
|
||||
typedef struct {
|
||||
BGC_FP32_Vector3 axis;
|
||||
float radians;
|
||||
} BGC_FP32_Rotation3;
|
||||
|
||||
typedef struct {
|
||||
BGC_FP64_Vector3 axis;
|
||||
double radians;
|
||||
} BGC_FP64_Rotation3;
|
||||
|
||||
extern const BGC_FP32_Rotation3 BGC_FP32_IDLE_ROTATION3;
|
||||
|
||||
extern const BGC_FP64_Rotation3 BGC_FP64_IDLE_ROTATION3;
|
||||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
inline void bgc_fp32_rotation3_reset(BGC_FP32_Rotation3* rotation)
|
||||
{
|
||||
rotation->axis.x1 = 0.0f;
|
||||
rotation->axis.x2 = 0.0f;
|
||||
rotation->axis.x3 = 0.0f;
|
||||
|
||||
rotation->radians = 0.0f;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_rotation3_reset(BGC_FP64_Rotation3* rotation)
|
||||
{
|
||||
rotation->axis.x1 = 0.0;
|
||||
rotation->axis.x2 = 0.0;
|
||||
rotation->axis.x3 = 0.0;
|
||||
|
||||
rotation->radians = 0.0;
|
||||
}
|
||||
|
||||
// ================= Set Values ================= //
|
||||
|
||||
inline void bgc_fp32_rotation3_make(const float x1, const float x2, const float x3, const float angle, const int unit, BGC_FP32_Rotation3* rotation)
|
||||
{
|
||||
rotation->axis.x1 = x1;
|
||||
rotation->axis.x2 = x2;
|
||||
rotation->axis.x3 = x3;
|
||||
|
||||
if (bgc_fp32_vector3_normalize(&rotation->axis)) {
|
||||
rotation->radians = bgc_fp32_angle_to_radians(angle, unit);
|
||||
}
|
||||
else {
|
||||
rotation->radians = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void bgc_fp64_rotation3_make(const double x1, const double x2, const double x3, const double angle, const int unit, BGC_FP64_Rotation3* rotation)
|
||||
{
|
||||
rotation->axis.x1 = x1;
|
||||
rotation->axis.x2 = x2;
|
||||
rotation->axis.x3 = x3;
|
||||
|
||||
if (bgc_fp64_vector3_normalize(&rotation->axis)) {
|
||||
rotation->radians = bgc_fp64_angle_to_radians(angle, unit);
|
||||
}
|
||||
else {
|
||||
rotation->radians = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_fp32_rotation3_make_for_axis(const BGC_FP32_Vector3* axis, const float angle, const int unit, BGC_FP32_Rotation3* rotation)
|
||||
{
|
||||
if (bgc_fp32_vector3_get_normalized(&rotation->axis, axis)) {
|
||||
rotation->radians = bgc_fp32_angle_to_radians(angle, unit);
|
||||
}
|
||||
else {
|
||||
rotation->radians = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_fp64_rotation3_make_for_axis(const BGC_FP64_Vector3* axis, const double angle, const int unit, BGC_FP64_Rotation3* rotation)
|
||||
{
|
||||
if (bgc_fp64_vector3_get_normalized(&rotation->axis, axis)) {
|
||||
rotation->radians = bgc_fp64_angle_to_radians(angle, unit);
|
||||
}
|
||||
else {
|
||||
rotation->radians = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -3,18 +3,18 @@
|
|||
extern inline void bgc_fp32_slerp_reset(BGC_FP32_Slerp* slerp);
|
||||
extern inline void bgc_fp64_slerp_reset(BGC_FP64_Slerp* slerp);
|
||||
|
||||
extern inline void bgc_fp32_slerp_make_full(BGC_FP32_Slerp* slerp, const BGC_FP32_Versor* start, const BGC_FP32_Versor* end);
|
||||
extern inline void bgc_fp64_slerp_make_full(BGC_FP64_Slerp* slerp, const BGC_FP64_Versor* start, const BGC_FP64_Versor* end);
|
||||
extern inline void bgc_fp32_slerp_make_full(BGC_FP32_Slerp* slerp, const BGC_FP32_Turn3* start, const BGC_FP32_Turn3* end);
|
||||
extern inline void bgc_fp64_slerp_make_full(BGC_FP64_Slerp* slerp, const BGC_FP64_Turn3* start, const BGC_FP64_Turn3* end);
|
||||
|
||||
extern inline void bgc_fp32_slerp_make_shortened(BGC_FP32_Slerp* slerp, const BGC_FP32_Versor* start, const BGC_FP32_Versor* end);
|
||||
extern inline void bgc_fp64_slerp_make_shortened(BGC_FP64_Slerp* slerp, const BGC_FP64_Versor* start, const BGC_FP64_Versor* end);
|
||||
extern inline void bgc_fp32_slerp_make_shortened(BGC_FP32_Slerp* slerp, const BGC_FP32_Turn3* start, const BGC_FP32_Turn3* end);
|
||||
extern inline void bgc_fp64_slerp_make_shortened(BGC_FP64_Slerp* slerp, const BGC_FP64_Turn3* start, const BGC_FP64_Turn3* end);
|
||||
|
||||
extern inline void bgc_fp32_slerp_get_phase_versor(BGC_FP32_Versor* versor, const BGC_FP32_Slerp* slerp, const float phase);
|
||||
extern inline void bgc_fp64_slerp_get_phase_versor(BGC_FP64_Versor* versor, const BGC_FP64_Slerp* slerp, const double phase);
|
||||
extern inline void bgc_fp32_slerp_get_phase_versor(BGC_FP32_Turn3* versor, const BGC_FP32_Slerp* slerp, const float phase);
|
||||
extern inline void bgc_fp64_slerp_get_phase_versor(BGC_FP64_Turn3* versor, const BGC_FP64_Slerp* slerp, const double phase);
|
||||
|
||||
void bgc_fp32_slerp_make(BGC_FP32_Slerp* slerp, const BGC_FP32_Versor* start, const BGC_FP32_Versor* augment)
|
||||
void bgc_fp32_slerp_make(BGC_FP32_Slerp* slerp, const BGC_FP32_Turn3* start, const BGC_FP32_Turn3* augment)
|
||||
{
|
||||
const float square_vector = augment->_x1 * augment->_x1 + augment->_x2 * augment->_x2 + augment->_x3 * augment->_x3;
|
||||
const float square_vector = augment->_versor.x1 * augment->_versor.x1 + augment->_versor.x2 * augment->_versor.x2 + augment->_versor.x3 * augment->_versor.x3;
|
||||
|
||||
if (square_vector != square_vector) {
|
||||
bgc_fp32_slerp_reset(slerp);
|
||||
|
|
@ -22,10 +22,10 @@ void bgc_fp32_slerp_make(BGC_FP32_Slerp* slerp, const BGC_FP32_Versor* start, co
|
|||
}
|
||||
|
||||
if (square_vector <= BGC_FP32_SQUARE_EPSILON) {
|
||||
slerp->s0_cos_weight = start->_s0;
|
||||
slerp->x1_cos_weight = start->_x1;
|
||||
slerp->x2_cos_weight = start->_x2;
|
||||
slerp->x3_cos_weight = start->_x3;
|
||||
slerp->s0_cos_weight = start->_versor.s0;
|
||||
slerp->x1_cos_weight = start->_versor.x1;
|
||||
slerp->x2_cos_weight = start->_versor.x2;
|
||||
slerp->x3_cos_weight = start->_versor.x3;
|
||||
|
||||
slerp->s0_sin_weight = 0.0f;
|
||||
slerp->x1_sin_weight = 0.0f;
|
||||
|
|
@ -38,24 +38,24 @@ void bgc_fp32_slerp_make(BGC_FP32_Slerp* slerp, const BGC_FP32_Versor* start, co
|
|||
|
||||
const float vector_modulus = sqrtf(square_vector);
|
||||
|
||||
slerp->radians = atan2f(vector_modulus, augment->_s0);
|
||||
slerp->radians = atan2f(vector_modulus, augment->_versor.s0);
|
||||
|
||||
const float multiplier = 1.0f / vector_modulus;
|
||||
|
||||
slerp->s0_cos_weight = start->_s0;
|
||||
slerp->x1_cos_weight = start->_x1;
|
||||
slerp->x2_cos_weight = start->_x2;
|
||||
slerp->x3_cos_weight = start->_x3;
|
||||
slerp->s0_cos_weight = start->_versor.s0;
|
||||
slerp->x1_cos_weight = start->_versor.x1;
|
||||
slerp->x2_cos_weight = start->_versor.x2;
|
||||
slerp->x3_cos_weight = start->_versor.x3;
|
||||
|
||||
slerp->s0_sin_weight = -multiplier * (augment->_x1 * start->_x1 + augment->_x2 * start->_x2 + augment->_x3 * start->_x3);
|
||||
slerp->x1_sin_weight = multiplier * (augment->_x1 * start->_s0 + augment->_x2 * start->_x3 - augment->_x3 * start->_x2);
|
||||
slerp->x2_sin_weight = multiplier * (augment->_x2 * start->_s0 - augment->_x1 * start->_x3 + augment->_x3 * start->_x1);
|
||||
slerp->x3_sin_weight = multiplier * (augment->_x3 * start->_s0 - augment->_x2 * start->_x1 + augment->_x1 * start->_x2);
|
||||
slerp->s0_sin_weight = -multiplier * (augment->_versor.x1 * start->_versor.x1 + augment->_versor.x2 * start->_versor.x2 + augment->_versor.x3 * start->_versor.x3);
|
||||
slerp->x1_sin_weight = multiplier * (augment->_versor.x1 * start->_versor.s0 + augment->_versor.x2 * start->_versor.x3 - augment->_versor.x3 * start->_versor.x2);
|
||||
slerp->x2_sin_weight = multiplier * (augment->_versor.x2 * start->_versor.s0 - augment->_versor.x1 * start->_versor.x3 + augment->_versor.x3 * start->_versor.x1);
|
||||
slerp->x3_sin_weight = multiplier * (augment->_versor.x3 * start->_versor.s0 - augment->_versor.x2 * start->_versor.x1 + augment->_versor.x1 * start->_versor.x2);
|
||||
}
|
||||
|
||||
void bgc_fp64_slerp_make(BGC_FP64_Slerp* slerp, const BGC_FP64_Versor* start, const BGC_FP64_Versor* augment)
|
||||
void bgc_fp64_slerp_make(BGC_FP64_Slerp* slerp, const BGC_FP64_Turn3* start, const BGC_FP64_Turn3* augment)
|
||||
{
|
||||
const double square_vector = augment->_x1 * augment->_x1 + augment->_x2 * augment->_x2 + augment->_x3 * augment->_x3;
|
||||
const double square_vector = augment->_versor.x1 * augment->_versor.x1 + augment->_versor.x2 * augment->_versor.x2 + augment->_versor.x3 * augment->_versor.x3;
|
||||
|
||||
if (square_vector != square_vector) {
|
||||
bgc_fp64_slerp_reset(slerp);
|
||||
|
|
@ -63,10 +63,10 @@ void bgc_fp64_slerp_make(BGC_FP64_Slerp* slerp, const BGC_FP64_Versor* start, co
|
|||
}
|
||||
|
||||
if (square_vector <= BGC_FP64_SQUARE_EPSILON) {
|
||||
slerp->s0_cos_weight = start->_s0;
|
||||
slerp->x1_cos_weight = start->_x1;
|
||||
slerp->x2_cos_weight = start->_x2;
|
||||
slerp->x3_cos_weight = start->_x3;
|
||||
slerp->s0_cos_weight = start->_versor.s0;
|
||||
slerp->x1_cos_weight = start->_versor.x1;
|
||||
slerp->x2_cos_weight = start->_versor.x2;
|
||||
slerp->x3_cos_weight = start->_versor.x3;
|
||||
|
||||
slerp->s0_sin_weight = 0.0;
|
||||
slerp->x1_sin_weight = 0.0;
|
||||
|
|
@ -79,17 +79,17 @@ void bgc_fp64_slerp_make(BGC_FP64_Slerp* slerp, const BGC_FP64_Versor* start, co
|
|||
|
||||
const double vector_modulus = sqrt(square_vector);
|
||||
|
||||
slerp->radians = atan2(vector_modulus, augment->_s0);
|
||||
slerp->radians = atan2(vector_modulus, augment->_versor.s0);
|
||||
|
||||
const double multiplier = 1.0 / vector_modulus;
|
||||
|
||||
slerp->s0_cos_weight = start->_s0;
|
||||
slerp->x1_cos_weight = start->_x1;
|
||||
slerp->x2_cos_weight = start->_x2;
|
||||
slerp->x3_cos_weight = start->_x3;
|
||||
slerp->s0_cos_weight = start->_versor.s0;
|
||||
slerp->x1_cos_weight = start->_versor.x1;
|
||||
slerp->x2_cos_weight = start->_versor.x2;
|
||||
slerp->x3_cos_weight = start->_versor.x3;
|
||||
|
||||
slerp->s0_sin_weight = -multiplier * (augment->_x1 * start->_x1 + augment->_x2 * start->_x2 + augment->_x3 * start->_x3);
|
||||
slerp->x1_sin_weight = multiplier * (augment->_x1 * start->_s0 + augment->_x2 * start->_x3 - augment->_x3 * start->_x2);
|
||||
slerp->x2_sin_weight = multiplier * (augment->_x2 * start->_s0 - augment->_x1 * start->_x3 + augment->_x3 * start->_x1);
|
||||
slerp->x3_sin_weight = multiplier * (augment->_x3 * start->_s0 - augment->_x2 * start->_x1 + augment->_x1 * start->_x2);
|
||||
slerp->s0_sin_weight = -multiplier * (augment->_versor.x1 * start->_versor.x1 + augment->_versor.x2 * start->_versor.x2 + augment->_versor.x3 * start->_versor.x3);
|
||||
slerp->x1_sin_weight = multiplier * (augment->_versor.x1 * start->_versor.s0 + augment->_versor.x2 * start->_versor.x3 - augment->_versor.x3 * start->_versor.x2);
|
||||
slerp->x2_sin_weight = multiplier * (augment->_versor.x2 * start->_versor.s0 - augment->_versor.x1 * start->_versor.x3 + augment->_versor.x3 * start->_versor.x1);
|
||||
slerp->x3_sin_weight = multiplier * (augment->_versor.x3 * start->_versor.s0 - augment->_versor.x2 * start->_versor.x1 + augment->_versor.x1 * start->_versor.x2);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _BGC_VERSOR_SLERP_H_
|
||||
#define _BGC_VERSOR_SLERP_H_
|
||||
|
||||
#include "./versor.h"
|
||||
#include "./turn3.h"
|
||||
|
||||
typedef struct {
|
||||
float s0_cos_weight, s0_sin_weight;
|
||||
|
|
@ -53,54 +53,54 @@ inline void bgc_fp64_slerp_reset(BGC_FP64_Slerp* slerp)
|
|||
slerp->radians = 0.0;
|
||||
}
|
||||
|
||||
void bgc_fp32_slerp_make(BGC_FP32_Slerp* slerp, const BGC_FP32_Versor* start, const BGC_FP32_Versor* augment);
|
||||
void bgc_fp64_slerp_make(BGC_FP64_Slerp* slerp, const BGC_FP64_Versor* start, const BGC_FP64_Versor* augment);
|
||||
void bgc_fp32_slerp_make(BGC_FP32_Slerp* slerp, const BGC_FP32_Turn3* start, const BGC_FP32_Turn3* augment);
|
||||
void bgc_fp64_slerp_make(BGC_FP64_Slerp* slerp, const BGC_FP64_Turn3* start, const BGC_FP64_Turn3* augment);
|
||||
|
||||
inline void bgc_fp32_slerp_make_full(BGC_FP32_Slerp* slerp, const BGC_FP32_Versor* start, const BGC_FP32_Versor* end)
|
||||
inline void bgc_fp32_slerp_make_full(BGC_FP32_Slerp* slerp, const BGC_FP32_Turn3* start, const BGC_FP32_Turn3* end)
|
||||
{
|
||||
BGC_FP32_Versor augment;
|
||||
BGC_FP32_Turn3 augment;
|
||||
|
||||
bgc_fp32_versor_exclude(&augment, end, start);
|
||||
bgc_fp32_turn3_exclude(&augment, end, start);
|
||||
|
||||
bgc_fp32_slerp_make(slerp, start, &augment);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_slerp_make_full(BGC_FP64_Slerp* slerp, const BGC_FP64_Versor* start, const BGC_FP64_Versor* end)
|
||||
inline void bgc_fp64_slerp_make_full(BGC_FP64_Slerp* slerp, const BGC_FP64_Turn3* start, const BGC_FP64_Turn3* end)
|
||||
{
|
||||
BGC_FP64_Versor augment;
|
||||
BGC_FP64_Turn3 augment;
|
||||
|
||||
bgc_fp64_versor_exclude(&augment, end, start);
|
||||
bgc_fp64_turn3_exclude(&augment, end, start);
|
||||
|
||||
bgc_fp64_slerp_make(slerp, start, &augment);
|
||||
}
|
||||
|
||||
inline void bgc_fp32_slerp_make_shortened(BGC_FP32_Slerp* slerp, const BGC_FP32_Versor* start, const BGC_FP32_Versor* end)
|
||||
inline void bgc_fp32_slerp_make_shortened(BGC_FP32_Slerp* slerp, const BGC_FP32_Turn3* start, const BGC_FP32_Turn3* end)
|
||||
{
|
||||
BGC_FP32_Versor augment;
|
||||
BGC_FP32_Turn3 augment;
|
||||
|
||||
bgc_fp32_versor_exclude(&augment, end, start);
|
||||
bgc_fp32_versor_shorten(&augment);
|
||||
bgc_fp32_turn3_exclude(&augment, end, start);
|
||||
bgc_fp32_turn3_shorten(&augment);
|
||||
|
||||
bgc_fp32_slerp_make(slerp, start, &augment);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_slerp_make_shortened(BGC_FP64_Slerp* slerp, const BGC_FP64_Versor* start, const BGC_FP64_Versor* end)
|
||||
inline void bgc_fp64_slerp_make_shortened(BGC_FP64_Slerp* slerp, const BGC_FP64_Turn3* start, const BGC_FP64_Turn3* end)
|
||||
{
|
||||
BGC_FP64_Versor augment;
|
||||
BGC_FP64_Turn3 augment;
|
||||
|
||||
bgc_fp64_versor_exclude(&augment, end, start);
|
||||
bgc_fp64_versor_shorten(&augment);
|
||||
bgc_fp64_turn3_exclude(&augment, end, start);
|
||||
bgc_fp64_turn3_shorten(&augment);
|
||||
|
||||
bgc_fp64_slerp_make(slerp, start, &augment);
|
||||
}
|
||||
|
||||
inline void bgc_fp32_slerp_get_phase_versor(BGC_FP32_Versor* versor, const BGC_FP32_Slerp* slerp, const float phase)
|
||||
inline void bgc_fp32_slerp_get_phase_versor(BGC_FP32_Turn3* versor, const BGC_FP32_Slerp* slerp, const float phase)
|
||||
{
|
||||
const float angle = slerp->radians * phase;
|
||||
const float cosine = cosf(angle);
|
||||
const float sine = sinf(angle);
|
||||
|
||||
bgc_fp32_versor_make(
|
||||
bgc_fp32_turn3_set_raw_values(
|
||||
versor,
|
||||
slerp->s0_cos_weight * cosine + slerp->s0_sin_weight * sine,
|
||||
slerp->x1_cos_weight * cosine + slerp->x1_sin_weight * sine,
|
||||
|
|
@ -109,13 +109,13 @@ inline void bgc_fp32_slerp_get_phase_versor(BGC_FP32_Versor* versor, const BGC_F
|
|||
);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_slerp_get_phase_versor(BGC_FP64_Versor* versor, const BGC_FP64_Slerp* slerp, const double phase)
|
||||
inline void bgc_fp64_slerp_get_phase_versor(BGC_FP64_Turn3* versor, const BGC_FP64_Slerp* slerp, const double phase)
|
||||
{
|
||||
const double angle = slerp->radians * phase;
|
||||
const double cosine = cos(angle);
|
||||
const double sine = sin(angle);
|
||||
|
||||
bgc_fp64_versor_make(
|
||||
bgc_fp64_turn3_set_raw_values(
|
||||
versor,
|
||||
slerp->s0_cos_weight * cosine + slerp->s0_sin_weight * sine,
|
||||
slerp->x1_cos_weight * cosine + slerp->x1_sin_weight * sine,
|
||||
|
|
|
|||
91
basic-geometry/turn2.c
Normal file
91
basic-geometry/turn2.c
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#include "./turn2.h"
|
||||
|
||||
const BGC_FP32_Turn2 BGC_FP32_IDLE_TURN2 = { 1.0f, 0.0f };
|
||||
|
||||
const BGC_FP64_Turn2 BGC_FP64_IDLE_TURN2 = { 1.0, 0.0 };
|
||||
|
||||
extern inline void bgc_fp32_turn2_reset(BGC_FP32_Turn2* turn);
|
||||
extern inline void bgc_fp64_turn2_reset(BGC_FP64_Turn2* turn);
|
||||
|
||||
extern inline void bgc_fp32_turn2_make(BGC_FP32_Turn2* turn, const float x1, const float x2);
|
||||
extern inline void bgc_fp64_turn2_make(BGC_FP64_Turn2* turn, const double x1, const double x2);
|
||||
|
||||
extern inline void bgc_fp32_turn2_make_for_angle(BGC_FP32_Turn2* turn, const float angle, const int angle_unit);
|
||||
extern inline void bgc_fp64_turn2_make_for_angle(BGC_FP64_Turn2* turn, const double angle, const int angle_unit);
|
||||
|
||||
extern inline int bgc_fp32_turn2_is_idle(const BGC_FP32_Turn2* turn);
|
||||
extern inline int bgc_fp64_turn2_is_idle(const BGC_FP64_Turn2* turn);
|
||||
|
||||
extern inline float bgc_fp32_turn2_get_angle(const BGC_FP32_Turn2* turn, const int angle_unit);
|
||||
extern inline double bgc_fp64_turn2_get_angle(const BGC_FP64_Turn2* turn, const int angle_unit);
|
||||
|
||||
extern inline void bgc_fp32_turn2_copy(BGC_FP32_Turn2* destination, const BGC_FP32_Turn2* source);
|
||||
extern inline void bgc_fp64_turn2_copy(BGC_FP64_Turn2* destination, const BGC_FP64_Turn2* source);
|
||||
|
||||
extern inline void bgc_fp32_turn2_swap(BGC_FP32_Turn2* turn1, BGC_FP32_Turn2* turn2);
|
||||
extern inline void bgc_fp64_turn2_swap(BGC_FP64_Turn2* turn1, BGC_FP64_Turn2* turn2);
|
||||
|
||||
extern inline void bgc_fp64_turn2_convert_to_fp32(BGC_FP32_Turn2* destination, const BGC_FP64_Turn2* source);
|
||||
extern inline void bgc_fp32_turn2_convert_to_fp64(BGC_FP64_Turn2* destination, const BGC_FP32_Turn2* source);
|
||||
|
||||
extern inline void bgc_fp32_turn2_revert(BGC_FP32_Turn2* turn);
|
||||
extern inline void bgc_fp64_turn2_revert(BGC_FP64_Turn2* turn);
|
||||
|
||||
extern inline void bgc_fp32_turn2_get_reverse(BGC_FP32_Turn2* reverse, const BGC_FP32_Turn2* turn);
|
||||
extern inline void bgc_fp64_turn2_get_reverse(BGC_FP64_Turn2* reverse, const BGC_FP64_Turn2* turn);
|
||||
|
||||
extern inline void bgc_fp32_turn2_get_exponation(BGC_FP32_Turn2* power, const BGC_FP32_Turn2* base, const float exponent);
|
||||
extern inline void bgc_fp64_turn2_get_exponation(BGC_FP64_Turn2* power, const BGC_FP64_Turn2* base, const double exponent);
|
||||
|
||||
extern inline void bgc_fp32_turn2_combine(BGC_FP32_Turn2* combination, const BGC_FP32_Turn2* turn1, const BGC_FP32_Turn2* turn2);
|
||||
extern inline void bgc_fp64_turn2_combine(BGC_FP64_Turn2* combination, const BGC_FP64_Turn2* turn1, const BGC_FP64_Turn2* turn2);
|
||||
|
||||
extern inline void bgc_fp32_turn2_exclude(BGC_FP32_Turn2* difference, const BGC_FP32_Turn2* base, const BGC_FP32_Turn2* excludant);
|
||||
extern inline void bgc_fp64_turn2_exclude(BGC_FP64_Turn2* difference, const BGC_FP64_Turn2* base, const BGC_FP64_Turn2* excludant);
|
||||
|
||||
extern inline void bgc_fp32_turn2_get_rotation_matrix(BGC_FP32_Matrix2x2* matrix, const BGC_FP32_Turn2* turn);
|
||||
extern inline void bgc_fp64_turn2_get_rotation_matrix(BGC_FP64_Matrix2x2* matrix, const BGC_FP64_Turn2* turn);
|
||||
|
||||
extern inline void bgc_fp32_turn2_get_reverse_matrix(BGC_FP32_Matrix2x2* matrix, const BGC_FP32_Turn2* turn);
|
||||
extern inline void bgc_fp64_turn2_get_reverse_matrix(BGC_FP64_Matrix2x2* matrix, const BGC_FP64_Turn2* turn);
|
||||
|
||||
extern inline void bgc_fp32_turn2_vector(BGC_FP32_Vector2* turned_vector, const BGC_FP32_Turn2* turn, const BGC_FP32_Vector2* vector);
|
||||
extern inline void bgc_fp64_turn2_vector(BGC_FP64_Vector2* turned_vector, const BGC_FP64_Turn2* turn, const BGC_FP64_Vector2* vector);
|
||||
|
||||
extern inline void bgc_fp32_turn2_vector_back(BGC_FP32_Vector2* turned_vector, const BGC_FP32_Turn2* turn, const BGC_FP32_Vector2* vector);
|
||||
extern inline void bgc_fp64_turn2_vector_back(BGC_FP64_Vector2* turned_vector, const BGC_FP64_Turn2* turn, const BGC_FP64_Vector2* vector);
|
||||
|
||||
extern inline int bgc_fp32_turn2_are_close(const BGC_FP32_Turn2* turn1, const BGC_FP32_Turn2* turn2);
|
||||
extern inline int bgc_fp64_turn2_are_close(const BGC_FP64_Turn2* turn1, const BGC_FP64_Turn2* turn2);
|
||||
|
||||
void _bgc_fp32_turn2_normalize(BGC_FP32_Turn2* turn)
|
||||
{
|
||||
const float square_modulus = turn->_cos * turn->_cos + turn->_sin * turn->_sin;
|
||||
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
turn->_cos = 1.0f;
|
||||
turn->_sin = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
const float multiplier = sqrtf(1.0f / square_modulus);
|
||||
|
||||
turn->_cos *= multiplier;
|
||||
turn->_sin *= multiplier;
|
||||
}
|
||||
|
||||
void _bgc_fp64_turn2_normalize(BGC_FP64_Turn2* turn)
|
||||
{
|
||||
const double square_modulus = turn->_cos * turn->_cos + turn->_sin * turn->_sin;
|
||||
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
turn->_cos = 1.0;
|
||||
turn->_sin = 0.0;
|
||||
return;
|
||||
}
|
||||
|
||||
const double multiplier = sqrt(1.0 / square_modulus);
|
||||
|
||||
turn->_cos *= multiplier;
|
||||
turn->_sin *= multiplier;
|
||||
}
|
||||
343
basic-geometry/turn2.h
Normal file
343
basic-geometry/turn2.h
Normal file
|
|
@ -0,0 +1,343 @@
|
|||
#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_Turn2;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double _cos, _sin;
|
||||
} BGC_FP64_Turn2;
|
||||
|
||||
// ================= Constants ================== //
|
||||
|
||||
extern const BGC_FP32_Turn2 BGC_FP32_IDLE_TURN2;
|
||||
extern const BGC_FP64_Turn2 BGC_FP64_IDLE_TURN2;
|
||||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
inline void bgc_fp32_turn2_reset(BGC_FP32_Turn2* turn)
|
||||
{
|
||||
turn->_cos = 1.0f;
|
||||
turn->_sin = 0.0f;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn2_reset(BGC_FP64_Turn2* turn)
|
||||
{
|
||||
turn->_cos = 1.0;
|
||||
turn->_sin = 0.0;
|
||||
}
|
||||
|
||||
// ================== Set Turn ================== //
|
||||
|
||||
inline void bgc_fp32_turn2_make_for_angle(BGC_FP32_Turn2* turn, const float angle, const int angle_unit)
|
||||
{
|
||||
const float radians = bgc_fp32_angle_to_radians(angle, angle_unit);
|
||||
|
||||
turn->_cos = cosf(radians);
|
||||
turn->_sin = sinf(radians);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn2_make_for_angle(BGC_FP64_Turn2* turn, const double angle, const int angle_unit)
|
||||
{
|
||||
const double radians = bgc_fp64_angle_to_radians(angle, angle_unit);
|
||||
|
||||
turn->_cos = cos(radians);
|
||||
turn->_sin = sin(radians);
|
||||
}
|
||||
|
||||
|
||||
// ================== Set Turn ================== //
|
||||
|
||||
inline int bgc_fp32_turn2_is_idle(const BGC_FP32_Turn2* turn)
|
||||
{
|
||||
return bgc_fp32_is_unit(turn->_cos) && bgc_fp32_is_zero(turn->_sin);
|
||||
}
|
||||
|
||||
inline int bgc_fp64_turn2_is_idle(const BGC_FP64_Turn2* turn)
|
||||
{
|
||||
return bgc_fp64_is_unit(turn->_cos) && bgc_fp64_is_zero(turn->_sin);
|
||||
}
|
||||
|
||||
// ==================== Set ===================== //
|
||||
|
||||
void _bgc_fp32_turn2_normalize(BGC_FP32_Turn2* twin);
|
||||
|
||||
void _bgc_fp64_turn2_normalize(BGC_FP64_Turn2* twin);
|
||||
|
||||
inline void bgc_fp32_turn2_make(BGC_FP32_Turn2* turn, const float x1, const float x2)
|
||||
{
|
||||
const float square_modulus = x1 * x1 + x2 * x2;
|
||||
|
||||
turn->_cos = x1;
|
||||
turn->_sin = x2;
|
||||
|
||||
if (!bgc_fp32_is_square_unit(square_modulus)) {
|
||||
_bgc_fp32_turn2_normalize(turn);
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn2_make(BGC_FP64_Turn2* turn, const double x1, const double x2)
|
||||
{
|
||||
const double square_modulus = x1 * x1 + x2 * x2;
|
||||
|
||||
turn->_cos = x1;
|
||||
turn->_sin = x2;
|
||||
|
||||
if (!bgc_fp64_is_square_unit(square_modulus)) {
|
||||
_bgc_fp64_turn2_normalize(turn);
|
||||
}
|
||||
}
|
||||
|
||||
// =================== Angle =================== //
|
||||
|
||||
inline float bgc_fp32_turn2_get_angle(const BGC_FP32_Turn2* turn, const int angle_unit)
|
||||
{
|
||||
return bgc_fp32_radians_to_units(atan2f(turn->_sin, turn->_cos), angle_unit);
|
||||
}
|
||||
|
||||
inline double bgc_fp64_turn2_get_angle(const BGC_FP64_Turn2* turn, const int angle_unit)
|
||||
{
|
||||
return bgc_fp64_radians_to_units(atan2(turn->_sin, turn->_cos), angle_unit);
|
||||
}
|
||||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
inline void bgc_fp32_turn2_copy(BGC_FP32_Turn2* destination, const BGC_FP32_Turn2* source)
|
||||
{
|
||||
destination->_cos = source->_cos;
|
||||
destination->_sin = source->_sin;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn2_copy(BGC_FP64_Turn2* destination, const BGC_FP64_Turn2* source)
|
||||
{
|
||||
destination->_cos = source->_cos;
|
||||
destination->_sin = source->_sin;
|
||||
}
|
||||
|
||||
// ==================== Swap ==================== //
|
||||
|
||||
inline void bgc_fp32_turn2_swap(BGC_FP32_Turn2* turn1, BGC_FP32_Turn2* turn2)
|
||||
{
|
||||
const float cos = turn1->_cos;
|
||||
const float sin = turn1->_sin;
|
||||
|
||||
turn1->_cos = turn2->_cos;
|
||||
turn1->_sin = turn2->_sin;
|
||||
|
||||
turn2->_cos = cos;
|
||||
turn2->_sin = sin;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn2_swap(BGC_FP64_Turn2* turn1, BGC_FP64_Turn2* turn2)
|
||||
{
|
||||
const double cos = turn1->_cos;
|
||||
const double sin = turn1->_sin;
|
||||
|
||||
turn1->_cos = turn2->_cos;
|
||||
turn1->_sin = turn2->_sin;
|
||||
|
||||
turn2->_cos = cos;
|
||||
turn2->_sin = sin;
|
||||
}
|
||||
|
||||
// ================== Convert =================== //
|
||||
|
||||
inline void bgc_fp64_turn2_convert_to_fp32(BGC_FP32_Turn2* destination, const BGC_FP64_Turn2* source)
|
||||
{
|
||||
bgc_fp32_turn2_make(destination, (float)source->_cos, (float)source->_sin);
|
||||
}
|
||||
|
||||
inline void bgc_fp32_turn2_convert_to_fp64(BGC_FP64_Turn2* destination, const BGC_FP32_Turn2* source)
|
||||
{
|
||||
bgc_fp64_turn2_make(destination, (double)source->_cos, (double)source->_sin);
|
||||
}
|
||||
|
||||
// =================== Revert =================== //
|
||||
|
||||
inline void bgc_fp32_turn2_revert(BGC_FP32_Turn2* turn)
|
||||
{
|
||||
turn->_sin = -turn->_sin;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn2_revert(BGC_FP64_Turn2* turn)
|
||||
{
|
||||
turn->_sin = -turn->_sin;
|
||||
}
|
||||
|
||||
inline void bgc_fp32_turn2_get_reverse(BGC_FP32_Turn2* reverse, const BGC_FP32_Turn2* turn)
|
||||
{
|
||||
reverse->_cos = turn->_cos;
|
||||
reverse->_sin = -turn->_sin;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn2_get_reverse(BGC_FP64_Turn2* reverse, const BGC_FP64_Turn2* turn)
|
||||
{
|
||||
reverse->_cos = turn->_cos;
|
||||
reverse->_sin = -turn->_sin;
|
||||
}
|
||||
|
||||
// ================= Exponation ================= //
|
||||
|
||||
inline void bgc_fp32_turn2_get_exponation(BGC_FP32_Turn2* power, const BGC_FP32_Turn2* 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_turn2_get_exponation(BGC_FP64_Turn2* power, const BGC_FP64_Turn2* 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_turn2_combine(BGC_FP32_Turn2* combination, const BGC_FP32_Turn2* turn1, const BGC_FP32_Turn2* turn2)
|
||||
{
|
||||
bgc_fp32_turn2_make(
|
||||
combination,
|
||||
turn1->_cos * turn2->_cos - turn1->_sin * turn2->_sin,
|
||||
turn1->_cos * turn2->_sin + turn1->_sin * turn2->_cos
|
||||
);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn2_combine(BGC_FP64_Turn2* combination, const BGC_FP64_Turn2* turn1, const BGC_FP64_Turn2* turn2)
|
||||
{
|
||||
bgc_fp64_turn2_make(
|
||||
combination,
|
||||
turn1->_cos * turn2->_cos - turn1->_sin * turn2->_sin,
|
||||
turn1->_cos * turn2->_sin + turn1->_sin * turn2->_cos
|
||||
);
|
||||
}
|
||||
|
||||
// ================= Exclusion ================== //
|
||||
|
||||
inline void bgc_fp32_turn2_exclude(BGC_FP32_Turn2* difference, const BGC_FP32_Turn2* base, const BGC_FP32_Turn2* excludant)
|
||||
{
|
||||
bgc_fp32_turn2_make(
|
||||
difference,
|
||||
base->_cos * excludant->_cos + base->_sin * excludant->_sin,
|
||||
base->_sin * excludant->_cos - base->_cos * excludant->_sin
|
||||
);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn2_exclude(BGC_FP64_Turn2* difference, const BGC_FP64_Turn2* base, const BGC_FP64_Turn2* excludant)
|
||||
{
|
||||
bgc_fp64_turn2_make(
|
||||
difference,
|
||||
base->_cos * excludant->_cos + base->_sin * excludant->_sin,
|
||||
base->_sin * excludant->_cos - base->_cos * excludant->_sin
|
||||
);
|
||||
}
|
||||
|
||||
// ============== Rotation Matrix =============== //
|
||||
|
||||
inline void bgc_fp32_turn2_get_rotation_matrix(BGC_FP32_Matrix2x2* matrix, const BGC_FP32_Turn2* turn)
|
||||
{
|
||||
matrix->r1c1 = turn->_cos;
|
||||
matrix->r1c2 = -turn->_sin;
|
||||
matrix->r2c1 = turn->_sin;
|
||||
matrix->r2c2 = turn->_cos;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn2_get_rotation_matrix(BGC_FP64_Matrix2x2* matrix, const BGC_FP64_Turn2* turn)
|
||||
{
|
||||
matrix->r1c1 = turn->_cos;
|
||||
matrix->r1c2 = -turn->_sin;
|
||||
matrix->r2c1 = turn->_sin;
|
||||
matrix->r2c2 = turn->_cos;
|
||||
}
|
||||
|
||||
// ============== Reverse Matrix ================ //
|
||||
|
||||
inline void bgc_fp32_turn2_get_reverse_matrix(BGC_FP32_Matrix2x2* matrix, const BGC_FP32_Turn2* turn)
|
||||
{
|
||||
matrix->r1c1 = turn->_cos;
|
||||
matrix->r1c2 = turn->_sin;
|
||||
matrix->r2c1 = -turn->_sin;
|
||||
matrix->r2c2 = turn->_cos;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn2_get_reverse_matrix(BGC_FP64_Matrix2x2* matrix, const BGC_FP64_Turn2* turn)
|
||||
{
|
||||
matrix->r1c1 = turn->_cos;
|
||||
matrix->r1c2 = turn->_sin;
|
||||
matrix->r2c1 = -turn->_sin;
|
||||
matrix->r2c2 = turn->_cos;
|
||||
}
|
||||
|
||||
// ================ Turn Vector ================= //
|
||||
|
||||
inline void bgc_fp32_turn2_vector(BGC_FP32_Vector2* turned_vector, const BGC_FP32_Turn2* turn, const BGC_FP32_Vector2* vector)
|
||||
{
|
||||
const float x1 = turn->_cos * vector->x1 - turn->_sin * vector->x2;
|
||||
const float x2 = turn->_sin * vector->x1 + turn->_cos * vector->x2;
|
||||
|
||||
turned_vector->x1 = x1;
|
||||
turned_vector->x2 = x2;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn2_vector(BGC_FP64_Vector2* turned_vector, const BGC_FP64_Turn2* turn, const BGC_FP64_Vector2* vector)
|
||||
{
|
||||
const double x1 = turn->_cos * vector->x1 - turn->_sin * vector->x2;
|
||||
const double x2 = turn->_sin * vector->x1 + turn->_cos * vector->x2;
|
||||
|
||||
turned_vector->x1 = x1;
|
||||
turned_vector->x2 = x2;
|
||||
}
|
||||
|
||||
// ============ Turn Vector Backward ============ //
|
||||
|
||||
inline void bgc_fp32_turn2_vector_back(BGC_FP32_Vector2* turned_vector, const BGC_FP32_Turn2* turn, const BGC_FP32_Vector2* vector)
|
||||
{
|
||||
const float x1 = turn->_sin * vector->x2 + turn->_cos * vector->x1;
|
||||
const float x2 = turn->_cos * vector->x2 - turn->_sin * vector->x1;
|
||||
|
||||
turned_vector->x1 = x1;
|
||||
turned_vector->x2 = x2;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn2_vector_back(BGC_FP64_Vector2* turned_vector, const BGC_FP64_Turn2* turn, const BGC_FP64_Vector2* vector)
|
||||
{
|
||||
const double x1 = turn->_sin * vector->x2 + turn->_cos * vector->x1;
|
||||
const double x2 = turn->_cos * vector->x2 - turn->_sin * vector->x1;
|
||||
|
||||
turned_vector->x1 = x1;
|
||||
turned_vector->x2 = x2;
|
||||
}
|
||||
|
||||
// ================== Are Close ================= //
|
||||
|
||||
inline int bgc_fp32_turn2_are_close(const BGC_FP32_Turn2* turn1, const BGC_FP32_Turn2* turn2)
|
||||
{
|
||||
const float d_cos = turn1->_cos - turn2->_cos;
|
||||
const float d_sin = turn1->_sin - turn2->_sin;
|
||||
|
||||
return d_cos * d_cos + d_sin * d_sin <= BGC_FP32_SQUARE_EPSILON;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_turn2_are_close(const BGC_FP64_Turn2* turn1, const BGC_FP64_Turn2* turn2)
|
||||
{
|
||||
const double d_cos = turn1->_cos - turn2->_cos;
|
||||
const double d_sin = turn1->_sin - turn2->_sin;
|
||||
|
||||
return d_cos * d_cos + d_sin * d_sin <= BGC_FP64_SQUARE_EPSILON;
|
||||
}
|
||||
|
||||
#endif
|
||||
593
basic-geometry/turn3.c
Normal file
593
basic-geometry/turn3.c
Normal file
|
|
@ -0,0 +1,593 @@
|
|||
#include <math.h>
|
||||
|
||||
#include "angle.h"
|
||||
#include "turn3.h"
|
||||
|
||||
const BGC_FP32_Turn3 BGC_FP32_IDLE_TURN3 = {{ 1.0f, 0.0f, 0.0f, 0.0f }};
|
||||
|
||||
const BGC_FP64_Turn3 BGC_FP64_IDLE_TURN3 = {{ 1.0, 0.0, 0.0, 0.0 }};
|
||||
|
||||
extern inline void bgc_fp32_turn3_reset(BGC_FP32_Turn3* turn);
|
||||
extern inline void bgc_fp64_turn3_reset(BGC_FP64_Turn3* turn);
|
||||
|
||||
extern inline void bgc_fp32_turn3_set_raw_values(BGC_FP32_Turn3* turn, const float s0, const float x1, const float x2, const float x3);
|
||||
extern inline void bgc_fp64_turn3_set_raw_values(BGC_FP64_Turn3* turn, const double s0, const double x1, const double x2, const double x3);
|
||||
|
||||
extern inline void bgc_fp32_turn3_get_quaternion(BGC_FP32_Quaternion* quaternion, const BGC_FP32_Turn3* turn);
|
||||
extern inline void bgc_fp64_turn3_get_quaternion(BGC_FP64_Quaternion* quaternion, const BGC_FP64_Turn3* turn);
|
||||
|
||||
extern inline void bgc_fp32_turn3_set_quaternion(BGC_FP32_Turn3* turn, const BGC_FP32_Quaternion* quaternion);
|
||||
extern inline void bgc_fp64_turn3_set_quaternion(BGC_FP64_Turn3* turn, const BGC_FP64_Quaternion* quaternion);
|
||||
|
||||
extern inline void bgc_fp32_turn3_copy(BGC_FP32_Turn3* destination, const BGC_FP32_Turn3* source);
|
||||
extern inline void bgc_fp64_turn3_copy(BGC_FP64_Turn3* destination, const BGC_FP64_Turn3* source);
|
||||
|
||||
extern inline void bgc_fp32_turn3_swap(BGC_FP32_Turn3* turn1, BGC_FP32_Turn3* turn2);
|
||||
extern inline void bgc_fp64_turn3_swap(BGC_FP64_Turn3* turn1, BGC_FP64_Turn3* turn2);
|
||||
|
||||
extern inline int bgc_fp32_turn3_is_idle(const BGC_FP32_Turn3* turn);
|
||||
extern inline int bgc_fp64_turn3_is_idle(const BGC_FP64_Turn3* turn);
|
||||
|
||||
extern inline void bgc_fp32_turn3_convert_to_fp64(BGC_FP64_Turn3* destination, const BGC_FP32_Turn3* source);
|
||||
extern inline void bgc_fp64_turn3_convert_to_fp32(BGC_FP32_Turn3* destination, const BGC_FP64_Turn3* source);
|
||||
|
||||
extern inline void bgc_fp32_turn3_shorten(BGC_FP32_Turn3* turn);
|
||||
extern inline void bgc_fp64_turn3_shorten(BGC_FP64_Turn3* turn);
|
||||
|
||||
extern inline void bgc_fp32_turn3_get_shortened(BGC_FP32_Turn3* shortened, const BGC_FP32_Turn3* turn);
|
||||
extern inline void bgc_fp64_turn3_get_shortened(BGC_FP64_Turn3* shortened, const BGC_FP64_Turn3* turn);
|
||||
|
||||
extern inline void bgc_fp32_turn3_alternate(BGC_FP32_Turn3* turn);
|
||||
extern inline void bgc_fp64_turn3_alternate(BGC_FP64_Turn3* turn);
|
||||
|
||||
extern inline void bgc_fp32_turn3_get_alternative(BGC_FP32_Turn3* alternative, const BGC_FP32_Turn3* turn);
|
||||
extern inline void bgc_fp64_turn3_get_alternative(BGC_FP64_Turn3* alternative, const BGC_FP64_Turn3* turn);
|
||||
|
||||
extern inline void bgc_fp32_turn3_revert(BGC_FP32_Turn3* turn);
|
||||
extern inline void bgc_fp64_turn3_revert(BGC_FP64_Turn3* turn);
|
||||
|
||||
extern inline void bgc_fp32_turn3_get_reverse(BGC_FP32_Turn3* inverse, const BGC_FP32_Turn3* turn);
|
||||
extern inline void bgc_fp64_turn3_get_reverse(BGC_FP64_Turn3* inverse, const BGC_FP64_Turn3* turn);
|
||||
|
||||
extern inline void bgc_fp32_turn3_combine(BGC_FP32_Turn3* combination, const BGC_FP32_Turn3* first, const BGC_FP32_Turn3* second);
|
||||
extern inline void bgc_fp64_turn3_combine(BGC_FP64_Turn3* combination, const BGC_FP64_Turn3* first, const BGC_FP64_Turn3* second);
|
||||
|
||||
extern inline void bgc_fp32_turn3_combine3(BGC_FP32_Turn3* combination, const BGC_FP32_Turn3* first, const BGC_FP32_Turn3* second, const BGC_FP32_Turn3* third);
|
||||
extern inline void bgc_fp64_turn3_combine3(BGC_FP64_Turn3* combination, const BGC_FP64_Turn3* first, const BGC_FP64_Turn3* second, const BGC_FP64_Turn3* third);
|
||||
|
||||
extern inline void bgc_fp32_turn3_exclude(BGC_FP32_Turn3* difference, const BGC_FP32_Turn3* base, const BGC_FP32_Turn3* excludant);
|
||||
extern inline void bgc_fp64_turn3_exclude(BGC_FP64_Turn3* difference, const BGC_FP64_Turn3* base, const BGC_FP64_Turn3* excludant);
|
||||
|
||||
extern inline void bgc_fp32_turn3_get_rotation_matrix(BGC_FP32_Matrix3x3* matrix, const BGC_FP32_Turn3* turn);
|
||||
extern inline void bgc_fp64_turn3_get_rotation_matrix(BGC_FP64_Matrix3x3* matrix, const BGC_FP64_Turn3* turn);
|
||||
|
||||
extern inline void bgc_fp32_turn3_get_reverse_matrix(BGC_FP32_Matrix3x3* matrix, const BGC_FP32_Turn3* turn);
|
||||
extern inline void bgc_fp64_turn3_get_reverse_matrix(BGC_FP64_Matrix3x3* matrix, const BGC_FP64_Turn3* turn);
|
||||
|
||||
extern inline void bgc_fp32_turn3_get_both_matrices(BGC_FP32_Matrix3x3* rotation, BGC_FP32_Matrix3x3* reverse, const BGC_FP32_Turn3* turn);
|
||||
extern inline void bgc_fp64_turn3_get_both_matrices(BGC_FP64_Matrix3x3* rotation, BGC_FP64_Matrix3x3* reverse, const BGC_FP64_Turn3* turn);
|
||||
|
||||
extern inline void bgc_fp32_turn3_vector(BGC_FP32_Vector3* turned_vector, const BGC_FP32_Turn3* turn, const BGC_FP32_Vector3* vector);
|
||||
extern inline void bgc_fp64_turn3_vector(BGC_FP64_Vector3* turned_vector, const BGC_FP64_Turn3* turn, const BGC_FP64_Vector3* vector);
|
||||
|
||||
extern inline void bgc_fp32_turn3_vector_back(BGC_FP32_Vector3* turned_vector, const BGC_FP32_Turn3* turn, const BGC_FP32_Vector3* vector);
|
||||
extern inline void bgc_fp64_turn3_vector_back(BGC_FP64_Vector3* turned_vector, const BGC_FP64_Turn3* turn, const BGC_FP64_Vector3* vector);
|
||||
|
||||
extern inline int bgc_fp32_turn3_are_close(const BGC_FP32_Turn3* turn1, const BGC_FP32_Turn3* turn2);
|
||||
extern inline int bgc_fp64_turn3_are_close(const BGC_FP64_Turn3* turn1, const BGC_FP64_Turn3* turn2);
|
||||
|
||||
// ================= Normalize ================== //
|
||||
|
||||
void _bgc_fp32_turn3_normalize(BGC_FP32_Turn3* turn, const float square_modulus)
|
||||
{
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
bgc_fp32_turn3_reset(turn);
|
||||
return;
|
||||
}
|
||||
|
||||
bgc_fp32_quaternion_multiply(&turn->_versor, &turn->_versor, sqrtf(1.0f / square_modulus));
|
||||
}
|
||||
|
||||
void _bgc_fp64_turn3_normalize(BGC_FP64_Turn3* turn, const double square_modulus)
|
||||
{
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
bgc_fp64_turn3_reset(turn);
|
||||
return;
|
||||
}
|
||||
|
||||
bgc_fp64_quaternion_multiply(&turn->_versor, &turn->_versor, sqrt(1.0 / square_modulus));
|
||||
}
|
||||
|
||||
|
||||
// ================ Get Rotation ================ //
|
||||
|
||||
float bgc_fp32_turn3_get_rotation(BGC_FP32_Vector3* axis, const BGC_FP32_Turn3* turn, const int angle_unit)
|
||||
{
|
||||
const float square_vector_modulus = turn->_versor.x1 * turn->_versor.x1 + turn->_versor.x2 * turn->_versor.x2 + turn->_versor.x3 * turn->_versor.x3;
|
||||
|
||||
if (square_vector_modulus <= BGC_FP32_SQUARE_EPSILON) {
|
||||
bgc_fp32_vector3_reset(axis);
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
const float vector_modulus = sqrtf(square_vector_modulus);
|
||||
|
||||
const float multiplier = 1.0f / vector_modulus;
|
||||
|
||||
axis->x1 = turn->_versor.x1 * multiplier;
|
||||
axis->x2 = turn->_versor.x2 * multiplier;
|
||||
axis->x3 = turn->_versor.x3 * multiplier;
|
||||
|
||||
return 2.0f * atan2f(vector_modulus, turn->_versor.s0);
|
||||
}
|
||||
|
||||
double bgc_fp64_turn3_get_rotation(BGC_FP64_Vector3* axis, const BGC_FP64_Turn3* turn, const int angle_unit)
|
||||
{
|
||||
const double square_vector_modulus = turn->_versor.x1 * turn->_versor.x1 + turn->_versor.x2 * turn->_versor.x2 + turn->_versor.x3 * turn->_versor.x3;
|
||||
|
||||
if (square_vector_modulus <= BGC_FP64_SQUARE_EPSILON) {
|
||||
bgc_fp64_vector3_reset(axis);
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
const double vector_modulus = sqrt(square_vector_modulus);
|
||||
|
||||
const double multiplier = 1.0 / vector_modulus;
|
||||
|
||||
axis->x1 = turn->_versor.x1 * multiplier;
|
||||
axis->x2 = turn->_versor.x2 * multiplier;
|
||||
axis->x3 = turn->_versor.x3 * multiplier;
|
||||
|
||||
return 2.0 * atan2(vector_modulus, turn->_versor.s0);
|
||||
}
|
||||
|
||||
// ================ Set Rotation ================ //
|
||||
|
||||
void bgc_fp32_turn3_set_rotation(BGC_FP32_Turn3* turn, const float x1, const float x2, const float x3, const float angle, const int angle_unit)
|
||||
{
|
||||
const float square_vector = x1 * x1 + x2 * x2 + x3 * x3;
|
||||
|
||||
if (square_vector <= BGC_FP32_SQUARE_EPSILON) {
|
||||
bgc_fp32_turn3_reset(turn);
|
||||
return;
|
||||
}
|
||||
|
||||
const float half_angle = bgc_fp32_angle_to_radians(0.5f * angle, angle_unit);
|
||||
|
||||
const float sine = sinf(half_angle);
|
||||
|
||||
if (bgc_fp32_is_zero(sine)) {
|
||||
bgc_fp32_turn3_reset(turn);
|
||||
return;
|
||||
}
|
||||
|
||||
const float multiplier = sine / sqrtf(square_vector);
|
||||
|
||||
bgc_fp32_quaternion_make(&turn->_versor, cosf(half_angle), x1 * multiplier, x2 * multiplier, x3 * multiplier);
|
||||
|
||||
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(&turn->_versor);
|
||||
|
||||
if (!bgc_fp32_is_square_unit(square_modulus)) {
|
||||
_bgc_fp32_turn3_normalize(turn, square_modulus);
|
||||
}
|
||||
}
|
||||
|
||||
void bgc_fp64_turn3_set_rotation(BGC_FP64_Turn3* turn, const double x1, const double x2, const double x3, const double angle, const int angle_unit)
|
||||
{
|
||||
const double square_vector = x1 * x1 + x2 * x2 + x3 * x3;
|
||||
|
||||
if (square_vector <= BGC_FP64_SQUARE_EPSILON) {
|
||||
bgc_fp64_turn3_reset(turn);
|
||||
return;
|
||||
}
|
||||
|
||||
const double half_angle = bgc_fp64_angle_to_radians(0.5 * angle, angle_unit);
|
||||
|
||||
const double sine = sin(half_angle);
|
||||
|
||||
if (bgc_fp64_is_zero(sine)) {
|
||||
bgc_fp64_turn3_reset(turn);
|
||||
return;
|
||||
}
|
||||
|
||||
const double multiplier = sine / sqrt(square_vector);
|
||||
|
||||
bgc_fp64_quaternion_make(&turn->_versor, cosf(half_angle), x1 * multiplier, x2 * multiplier, x3 * multiplier);
|
||||
|
||||
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(&turn->_versor);
|
||||
|
||||
if (!bgc_fp64_is_square_unit(square_modulus)) {
|
||||
_bgc_fp64_turn3_normalize(turn, square_modulus);
|
||||
}
|
||||
}
|
||||
|
||||
// ========= Make Direction Difference ========== //
|
||||
|
||||
static int _bgc_fp32_turn3_make_direction_turn(BGC_FP32_Turn3* turn, const BGC_FP32_Vector3* start, const BGC_FP32_Vector3* end, const float square_modulus)
|
||||
{
|
||||
BGC_FP32_Vector3 orthogonal_axis;
|
||||
|
||||
bgc_fp32_vector3_get_cross_product(&orthogonal_axis, start, end);
|
||||
|
||||
const float scalar_product = bgc_fp32_vector3_get_dot_product(start, end);
|
||||
const float square_modulus = bgc_fp32_vector3_get_square_modulus(&orthogonal_axis);
|
||||
const float square_sine = square_modulus / square_modulus_product;
|
||||
|
||||
if (square_sine > BGC_FP64_SQUARE_EPSILON) {
|
||||
const float cosine = scalar_product / sqrtf(square_modulus_product);
|
||||
const float angle = 0.5 * atan2f(sqrtf(square_sine), cosine);
|
||||
|
||||
const float multiplier = sin(angle) * sqrtf(1.0f / square_modulus);
|
||||
|
||||
bgc_fp32_turn3_set_raw_values(versor, cosf(angle), orthogonal_axis.x1 * multiplier, orthogonal_axis.x2 * multiplier, orthogonal_axis.x3 * multiplier);
|
||||
return BGC_SOME_TURN;
|
||||
}
|
||||
|
||||
if (scalar_product < 0.0f) {
|
||||
return BGC_OPPOSITE;
|
||||
}
|
||||
|
||||
bgc_fp32_turn3_reset(versor);
|
||||
|
||||
return BGC_ZERO_TURN;
|
||||
}
|
||||
|
||||
static int _bgc_fp64_turn3_make_direction_turn(BGC_FP64_Turn3* versor, const BGC_FP64_Vector3* start, const BGC_FP64_Vector3* end, const double square_modulus_product)
|
||||
{
|
||||
BGC_FP64_Vector3 orthogonal_axis;
|
||||
|
||||
bgc_fp64_vector3_get_cross_product(&orthogonal_axis, start, end);
|
||||
|
||||
const double scalar_product = bgc_fp64_vector3_get_dot_product(start, end);
|
||||
const double square_modulus = bgc_fp64_vector3_get_square_modulus(&orthogonal_axis);
|
||||
const double square_sine = square_modulus / square_modulus_product;
|
||||
|
||||
if (square_sine > BGC_FP64_SQUARE_EPSILON) {
|
||||
const double cosine = scalar_product / sqrt(square_modulus_product);
|
||||
const double angle = 0.5 * atan2(sqrt(square_sine), cosine);
|
||||
|
||||
const double multiplier = sin(angle) * sqrt(1.0f / square_modulus);
|
||||
|
||||
bgc_fp64_turn3_set_raw_values(versor, cos(angle), orthogonal_axis.x1 * multiplier, orthogonal_axis.x2 * multiplier, orthogonal_axis.x3 * multiplier);
|
||||
return BGC_SOME_TURN;
|
||||
}
|
||||
|
||||
if (scalar_product < 0.0) {
|
||||
return BGC_OPPOSITE;
|
||||
}
|
||||
|
||||
bgc_fp64_turn3_reset(versor);
|
||||
|
||||
return BGC_ZERO_TURN;
|
||||
}
|
||||
|
||||
// ========= Find Direction Difference ========== //
|
||||
|
||||
int bgc_fp32_turn3_find_direction_difference(BGC_FP32_Turn3* difference, const BGC_FP32_Vector3* start, const BGC_FP32_Vector3* end)
|
||||
{
|
||||
const float start_square_modulus = bgc_fp32_vector3_get_square_modulus(start);
|
||||
const float end_square_modulus = bgc_fp32_vector3_get_square_modulus(end);
|
||||
|
||||
if (start_square_modulus <= BGC_FP32_SQUARE_EPSILON || end_square_modulus <= BGC_FP32_SQUARE_EPSILON) {
|
||||
bgc_fp32_turn3_reset(difference);
|
||||
return BGC_ZERO_TURN;
|
||||
}
|
||||
|
||||
const double scalar_product = bgc_fp64_vector3_get_dot_product(start, end);
|
||||
|
||||
if () {
|
||||
}
|
||||
|
||||
BGC_FP64_Vector3 orthogonal_axis;
|
||||
|
||||
bgc_fp64_vector3_get_cross_product(&orthogonal_axis, start, end);
|
||||
|
||||
return _bgc_fp32_turn3_make_direction_turn(difference, start, end, start_square_modulus * end_square_modulus);
|
||||
}
|
||||
|
||||
int bgc_fp64_turn3_find_direction_difference(BGC_FP64_Turn3* difference, const BGC_FP64_Vector3* start, const BGC_FP64_Vector3* end)
|
||||
{
|
||||
const double start_square_modulus = bgc_fp64_vector3_get_square_modulus(start);
|
||||
const double end_square_modulus = bgc_fp64_vector3_get_square_modulus(end);
|
||||
|
||||
if (start_square_modulus <= BGC_FP64_SQUARE_EPSILON || end_square_modulus <= BGC_FP64_SQUARE_EPSILON) {
|
||||
bgc_fp64_turn3_reset(difference);
|
||||
return BGC_ZERO_TURN;
|
||||
}
|
||||
|
||||
return _bgc_fp64_turn3_make_direction_turn(difference, start, end, start_square_modulus * end_square_modulus);
|
||||
}
|
||||
|
||||
// =============== Set Directions =============== //
|
||||
|
||||
static int _bgc_fp32_turn3_validate_basis(const float primary_square_modulus, const float auxiliary_square_modulus, const float orthogonal_square_modulus)
|
||||
{
|
||||
if (primary_square_modulus <= BGC_FP32_SQUARE_EPSILON) {
|
||||
//TODO: add error code for: primary_vector is zero
|
||||
return BGC_FAILED;
|
||||
}
|
||||
|
||||
if (auxiliary_square_modulus <= BGC_FP32_SQUARE_EPSILON) {
|
||||
//TODO: add error code for: auxiliary_vector is zero
|
||||
return BGC_FAILED;
|
||||
}
|
||||
|
||||
if (orthogonal_square_modulus <= BGC_FP32_SQUARE_EPSILON * primary_square_modulus * auxiliary_square_modulus) {
|
||||
//TODO: add error code for: primary_vector and auxiliary_vector are parallel
|
||||
return BGC_FAILED;
|
||||
}
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
static int _bgc_fp64_turn3_validate_basis(const double primary_square_modulus, const double auxiliary_square_modulus, const double orthogonal_square_modulus)
|
||||
{
|
||||
if (primary_square_modulus <= BGC_FP64_SQUARE_EPSILON) {
|
||||
//TODO: add error code for: primary_vector is zero
|
||||
return BGC_FAILED;
|
||||
}
|
||||
|
||||
if (auxiliary_square_modulus <= BGC_FP64_SQUARE_EPSILON) {
|
||||
//TODO: add error code for: auxiliary_vector is zero
|
||||
return BGC_FAILED;
|
||||
}
|
||||
|
||||
if (orthogonal_square_modulus <= BGC_FP64_SQUARE_EPSILON * primary_square_modulus * auxiliary_square_modulus) {
|
||||
//TODO: add error code for: primary_vector and auxiliary_vector are parallel
|
||||
return BGC_FAILED;
|
||||
}
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
int bgc_fp32_turn3_make_basis_difference(
|
||||
BGC_FP32_Turn3* versor,
|
||||
const BGC_FP32_Vector3* initial_primary_direction,
|
||||
const BGC_FP32_Vector3* initial_auxiliary_direction,
|
||||
const BGC_FP32_Vector3* final_primary_direction,
|
||||
const BGC_FP32_Vector3* final_auxiliary_direction
|
||||
)
|
||||
{
|
||||
BGC_FP32_Vector3 initial_orthogonal_direction, turned_orthogonal_direction, final_orthogonal_direction;
|
||||
|
||||
// Step 1: Validate initial basis:
|
||||
bgc_fp32_vector3_get_cross_product(&initial_orthogonal_direction, initial_primary_direction, initial_auxiliary_direction);
|
||||
|
||||
const float initial_primary_square_modulus = bgc_fp32_vector3_get_square_modulus(initial_primary_direction);
|
||||
const float initial_auxiliary_square_modulus = bgc_fp32_vector3_get_square_modulus(initial_auxiliary_direction);
|
||||
const float initial_orthogonal_square_modulus = bgc_fp32_vector3_get_square_modulus(&initial_orthogonal_direction);
|
||||
|
||||
const int initial_basis_valudation = _bgc_fp32_turn3_validate_basis(initial_primary_square_modulus, initial_auxiliary_square_modulus, initial_orthogonal_square_modulus);
|
||||
|
||||
if (initial_basis_valudation != BGC_SUCCESS) {
|
||||
return initial_basis_valudation;
|
||||
}
|
||||
|
||||
// Step 1: Validate final basis:
|
||||
bgc_fp32_vector3_get_cross_product(&final_orthogonal_direction, final_primary_direction, final_auxiliary_direction);
|
||||
|
||||
const float final_primary_square_modulus = bgc_fp32_vector3_get_square_modulus(final_primary_direction);
|
||||
const float final_auxiliary_square_modulus = bgc_fp32_vector3_get_square_modulus(final_auxiliary_direction);
|
||||
const float final_orthogonal_square_modulus = bgc_fp32_vector3_get_square_modulus(&final_orthogonal_direction);
|
||||
|
||||
const int final_basis_valudation = _bgc_fp32_turn3_validate_basis(final_primary_square_modulus, final_auxiliary_square_modulus, final_orthogonal_square_modulus);
|
||||
|
||||
if (final_basis_valudation != BGC_SUCCESS) {
|
||||
return final_basis_valudation;
|
||||
}
|
||||
|
||||
// Step 3: Validate normalize orthogonal vectors:
|
||||
bgc_fp32_vector3_divide(&initial_orthogonal_direction, &initial_orthogonal_direction, sqrtf(initial_orthogonal_square_modulus));
|
||||
bgc_fp32_vector3_divide(&final_orthogonal_direction, &final_orthogonal_direction, sqrtf(final_orthogonal_square_modulus));
|
||||
|
||||
BGC_FP32_Turn3 turn1, turn2;
|
||||
|
||||
// Step 4: Find turn1
|
||||
int turn1_code = _bgc_fp32_turn3_make_direction_turn(&turn1, initial_primary_direction, final_primary_direction, initial_primary_square_modulus * final_primary_square_modulus);
|
||||
|
||||
if (turn1_code == BGC_OPPOSITE) {
|
||||
bgc_fp32_turn3_set_raw_values(&turn1, 0.0f, initial_orthogonal_direction.x1, initial_orthogonal_direction.x2, initial_orthogonal_direction.x3);
|
||||
}
|
||||
|
||||
bgc_fp32_turn3_vector(&turned_orthogonal_direction, &turn1, &initial_orthogonal_direction);
|
||||
|
||||
// Step 5: Find turn2:
|
||||
int turn2_code = _bgc_fp32_turn3_make_direction_turn(&turn2, &turned_orthogonal_direction, &final_orthogonal_direction, 1.0f);
|
||||
|
||||
if (turn2_code == BGC_OPPOSITE) {
|
||||
const float turn2_multiplier = sqrtf(1.0f / final_primary_square_modulus);
|
||||
|
||||
bgc_fp32_turn3_set_raw_values(&turn2,
|
||||
0.0f,
|
||||
final_primary_direction->x1 * turn2_multiplier,
|
||||
final_primary_direction->x2 * turn2_multiplier,
|
||||
final_primary_direction->x3 * turn2_multiplier
|
||||
);
|
||||
}
|
||||
|
||||
// Step 6: Combine turn1 and turn2:
|
||||
bgc_fp32_turn3_combine(versor, &turn1, &turn2);
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
int bgc_fp64_turn3_make_basis_difference(
|
||||
BGC_FP64_Turn3* versor,
|
||||
const BGC_FP64_Vector3* initial_primary_direction,
|
||||
const BGC_FP64_Vector3* initial_auxiliary_direction,
|
||||
const BGC_FP64_Vector3* final_primary_direction,
|
||||
const BGC_FP64_Vector3* final_auxiliary_direction
|
||||
)
|
||||
{
|
||||
BGC_FP64_Vector3 initial_orthogonal_direction, turned_orthogonal_direction, final_orthogonal_direction;
|
||||
|
||||
// Step 1: Validate initial basis:
|
||||
bgc_fp64_vector3_get_cross_product(&initial_orthogonal_direction, initial_primary_direction, initial_auxiliary_direction);
|
||||
|
||||
const double initial_primary_square_modulus = bgc_fp64_vector3_get_square_modulus(initial_primary_direction);
|
||||
const double initial_auxiliary_square_modulus = bgc_fp64_vector3_get_square_modulus(initial_auxiliary_direction);
|
||||
const double initial_orthogonal_square_modulus = bgc_fp64_vector3_get_square_modulus(&initial_orthogonal_direction);
|
||||
|
||||
const int initial_basis_valudation = _bgc_fp64_turn3_validate_basis(initial_primary_square_modulus, initial_auxiliary_square_modulus, initial_orthogonal_square_modulus);
|
||||
|
||||
if (initial_basis_valudation != BGC_SUCCESS) {
|
||||
return initial_basis_valudation;
|
||||
}
|
||||
|
||||
// Step 1: Validate final basis:
|
||||
bgc_fp64_vector3_get_cross_product(&final_orthogonal_direction, final_primary_direction, final_auxiliary_direction);
|
||||
|
||||
const double final_primary_square_modulus = bgc_fp64_vector3_get_square_modulus(final_primary_direction);
|
||||
const double final_auxiliary_square_modulus = bgc_fp64_vector3_get_square_modulus(final_auxiliary_direction);
|
||||
const double final_orthogonal_square_modulus = bgc_fp64_vector3_get_square_modulus(&final_orthogonal_direction);
|
||||
|
||||
const int final_basis_valudation = _bgc_fp64_turn3_validate_basis(final_primary_square_modulus, final_auxiliary_square_modulus, final_orthogonal_square_modulus);
|
||||
|
||||
if (final_basis_valudation != BGC_SUCCESS) {
|
||||
return final_basis_valudation;
|
||||
}
|
||||
|
||||
// Step 3: Validate normalize orthogonal vectors:
|
||||
bgc_fp64_vector3_divide(&initial_orthogonal_direction, &initial_orthogonal_direction, sqrt(initial_orthogonal_square_modulus));
|
||||
bgc_fp64_vector3_divide(&final_orthogonal_direction, &final_orthogonal_direction, sqrt(final_orthogonal_square_modulus));
|
||||
|
||||
BGC_FP64_Turn3 turn1, turn2;
|
||||
|
||||
// Step 4: Find turn1
|
||||
int turn1_code = _bgc_fp64_turn3_make_direction_turn(&turn1, initial_primary_direction, final_primary_direction, initial_primary_square_modulus * final_primary_square_modulus);
|
||||
|
||||
if (turn1_code == BGC_OPPOSITE) {
|
||||
bgc_fp64_turn3_set_raw_values(&turn1, 0.0, initial_orthogonal_direction.x1, initial_orthogonal_direction.x2, initial_orthogonal_direction.x3);
|
||||
}
|
||||
|
||||
bgc_fp64_turn3_vector(&turned_orthogonal_direction, &turn1, &initial_orthogonal_direction);
|
||||
|
||||
// Step 5: Find turn2:
|
||||
int turn2_code = _bgc_fp64_turn3_make_direction_turn(&turn2, &turned_orthogonal_direction, &final_orthogonal_direction, 1.0f);
|
||||
|
||||
if (turn2_code == BGC_OPPOSITE) {
|
||||
const double turn2_multiplier = sqrt(1.0 / final_primary_square_modulus);
|
||||
|
||||
bgc_fp64_turn3_set_raw_values(&turn2,
|
||||
0.0,
|
||||
final_primary_direction->x1 * turn2_multiplier,
|
||||
final_primary_direction->x2 * turn2_multiplier,
|
||||
final_primary_direction->x3 * turn2_multiplier
|
||||
);
|
||||
}
|
||||
|
||||
// Step 6: Combine turn1 and turn2:
|
||||
bgc_fp64_turn3_combine(versor, &turn1, &turn2);
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// =============== Get Exponation =============== //
|
||||
|
||||
void bgc_fp32_turn3_get_exponation(BGC_FP32_Turn3* power, const BGC_FP32_Turn3* base, const float exponent)
|
||||
{
|
||||
const float square_vector = base->_versor.x1 * base->_versor.x1 + base->_versor.x2 * base->_versor.x2 + base->_versor.x3 * base->_versor.x3;
|
||||
|
||||
if (square_vector <= BGC_FP32_SQUARE_EPSILON || square_vector != square_vector) {
|
||||
bgc_fp32_turn3_reset(power);
|
||||
return;
|
||||
}
|
||||
|
||||
const float vector_modulus = sqrtf(square_vector);
|
||||
|
||||
const float angle = atan2f(vector_modulus, base->_versor.s0) * exponent;
|
||||
|
||||
const float multiplier = sinf(angle) / vector_modulus;
|
||||
|
||||
bgc_fp32_turn3_set_raw_values(power, cosf(angle), base->_versor.x1 * multiplier, base->_versor.x2 * multiplier, base->_versor.x3 * multiplier);
|
||||
}
|
||||
|
||||
void bgc_fp64_turn3_get_exponation(BGC_FP64_Turn3* power, const BGC_FP64_Turn3* base, const double exponent)
|
||||
{
|
||||
const double square_vector = base->_versor.x1 * base->_versor.x1 + base->_versor.x2 * base->_versor.x2 + base->_versor.x3 * base->_versor.x3;
|
||||
|
||||
if (square_vector <= BGC_FP64_SQUARE_EPSILON || square_vector != square_vector) {
|
||||
bgc_fp64_turn3_reset(power);
|
||||
return;
|
||||
}
|
||||
|
||||
const double vector_modulus = sqrt(square_vector);
|
||||
|
||||
const double angle = atan2(vector_modulus, base->_versor.s0) * exponent;
|
||||
|
||||
const double multiplier = sin(angle) / vector_modulus;
|
||||
|
||||
bgc_fp64_turn3_set_raw_values(power, cos(angle), base->_versor.x1 * multiplier, base->_versor.x2 * multiplier, base->_versor.x3 * multiplier);
|
||||
}
|
||||
|
||||
// ============ Sphere Interpolation ============ //
|
||||
|
||||
void bgc_fp32_turn3_spherically_interpolate(BGC_FP32_Turn3* interpolation, const BGC_FP32_Turn3* start, const BGC_FP32_Turn3* end, const float phase)
|
||||
{
|
||||
const float delta_s0 = (end->_versor.s0 * start->_versor.s0 + end->_versor.x1 * start->_versor.x1) + (end->_versor.x2 * start->_versor.x2 + end->_versor.x3 * start->_versor.x3);
|
||||
const float delta_x1 = (end->_versor.x1 * start->_versor.s0 + end->_versor.x3 * start->_versor.x2) - (end->_versor.s0 * start->_versor.x1 + end->_versor.x2 * start->_versor.x3);
|
||||
const float delta_x2 = (end->_versor.x2 * start->_versor.s0 + end->_versor.x1 * start->_versor.x3) - (end->_versor.s0 * start->_versor.x2 + end->_versor.x3 * start->_versor.x1);
|
||||
const float delta_x3 = (end->_versor.x3 * start->_versor.s0 + end->_versor.x2 * start->_versor.x1) - (end->_versor.s0 * start->_versor.x3 + end->_versor.x1 * start->_versor.x2);
|
||||
|
||||
const float square_vector = delta_x1 * delta_x1 + delta_x2 * delta_x2 + delta_x3 * delta_x3;
|
||||
|
||||
// square_vector != square_vector means checking for NaN value at square_vector
|
||||
if (square_vector <= BGC_FP32_SQUARE_EPSILON || isnan(square_vector)) {
|
||||
bgc_fp32_turn3_copy(interpolation, end);
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculating of the turning which fits the phase:
|
||||
const float vector_modulus = sqrtf(square_vector);
|
||||
const float angle = atan2f(vector_modulus, delta_s0) * phase;
|
||||
const float multiplier = sinf(angle) / vector_modulus;
|
||||
|
||||
const float turn_s0 = cosf(angle);
|
||||
const float turn_x1 = delta_x1 * multiplier;
|
||||
const float turn_x2 = delta_x2 * multiplier;
|
||||
const float turn_x3 = delta_x3 * multiplier;
|
||||
|
||||
// Combining of starting orientation with the turning
|
||||
bgc_fp32_turn3_set_raw_values(
|
||||
interpolation,
|
||||
(turn_s0 * start->_versor.s0 - turn_x1 * start->_versor.x1) - (turn_x2 * start->_versor.x2 + turn_x3 * start->_versor.x3),
|
||||
(turn_x1 * start->_versor.s0 + turn_s0 * start->_versor.x1) - (turn_x3 * start->_versor.x2 - turn_x2 * start->_versor.x3),
|
||||
(turn_x2 * start->_versor.s0 + turn_s0 * start->_versor.x2) - (turn_x1 * start->_versor.x3 - turn_x3 * start->_versor.x1),
|
||||
(turn_x3 * start->_versor.s0 + turn_s0 * start->_versor.x3) - (turn_x2 * start->_versor.x1 - turn_x1 * start->_versor.x2)
|
||||
);
|
||||
}
|
||||
|
||||
void bgc_fp64_turn3_spherically_interpolate(BGC_FP64_Turn3* interpolation, const BGC_FP64_Turn3* start, const BGC_FP64_Turn3* end, const double phase)
|
||||
{
|
||||
const double delta_s0 = (end->_versor.s0 * start->_versor.s0 + end->_versor.x1 * start->_versor.x1) + (end->_versor.x2 * start->_versor.x2 + end->_versor.x3 * start->_versor.x3);
|
||||
const double delta_x1 = (end->_versor.x1 * start->_versor.s0 + end->_versor.x3 * start->_versor.x2) - (end->_versor.s0 * start->_versor.x1 + end->_versor.x2 * start->_versor.x3);
|
||||
const double delta_x2 = (end->_versor.x2 * start->_versor.s0 + end->_versor.x1 * start->_versor.x3) - (end->_versor.s0 * start->_versor.x2 + end->_versor.x3 * start->_versor.x1);
|
||||
const double delta_x3 = (end->_versor.x3 * start->_versor.s0 + end->_versor.x2 * start->_versor.x1) - (end->_versor.s0 * start->_versor.x3 + end->_versor.x1 * start->_versor.x2);
|
||||
|
||||
const double square_vector = delta_x1 * delta_x1 + delta_x2 * delta_x2 + delta_x3 * delta_x3;
|
||||
|
||||
// square_vector != square_vector means checking for NaN value at square_vector
|
||||
if (square_vector <= BGC_FP64_SQUARE_EPSILON || isnan(square_vector)) {
|
||||
bgc_fp64_turn3_copy(interpolation, end);
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculating of the turning which fits the phase:
|
||||
const double vector_modulus = sqrt(square_vector);
|
||||
const double angle = atan2(vector_modulus, delta_s0) * phase;
|
||||
const double multiplier = sin(angle) / vector_modulus;
|
||||
|
||||
const double turn_s0 = cos(angle);
|
||||
const double turn_x1 = delta_x1 * multiplier;
|
||||
const double turn_x2 = delta_x2 * multiplier;
|
||||
const double turn_x3 = delta_x3 * multiplier;
|
||||
|
||||
// Combining of starting orientation with the turning
|
||||
bgc_fp64_turn3_set_raw_values(
|
||||
interpolation,
|
||||
(turn_s0 * start->_versor.s0 - turn_x1 * start->_versor.x1) - (turn_x2 * start->_versor.x2 + turn_x3 * start->_versor.x3),
|
||||
(turn_x1 * start->_versor.s0 + turn_s0 * start->_versor.x1) - (turn_x3 * start->_versor.x2 - turn_x2 * start->_versor.x3),
|
||||
(turn_x2 * start->_versor.s0 + turn_s0 * start->_versor.x2) - (turn_x1 * start->_versor.x3 - turn_x3 * start->_versor.x1),
|
||||
(turn_x3 * start->_versor.s0 + turn_s0 * start->_versor.x3) - (turn_x2 * start->_versor.x1 - turn_x1 * start->_versor.x2)
|
||||
);
|
||||
}
|
||||
502
basic-geometry/turn3.h
Normal file
502
basic-geometry/turn3.h
Normal file
|
|
@ -0,0 +1,502 @@
|
|||
#ifndef _BGC_VERSOR_H_
|
||||
#define _BGC_VERSOR_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "utilities.h"
|
||||
#include "angle.h"
|
||||
#include "vector3.h"
|
||||
#include "matrix3x3.h"
|
||||
#include "quaternion.h"
|
||||
|
||||
#define BGC_SOME_TURN 1
|
||||
#define BGC_ZERO_TURN 0
|
||||
#define BGC_OPPOSITE -1
|
||||
|
||||
#define BGC_ERROR_PRIMARY_DIRECTION_UNKNOWN -3001
|
||||
#define BGC_ERROR_PRIMARY_VECTOR_IS_ZERO -3002
|
||||
|
||||
#define BGC_ERROR_AUXILIARY_DIRECTION_UNKNOWN -3011
|
||||
#define BGC_ERROR_AUXILIARY_VECTOR_IS_ZERO -3012
|
||||
|
||||
#define BGC_ERROR_DIRECTIONS_PARALLEL -3021
|
||||
#define BGC_ERROR_VECTORS_PARALLEL -3022
|
||||
|
||||
// =================== Types ==================== //
|
||||
|
||||
typedef struct {
|
||||
BGC_FP32_Quaternion _versor;
|
||||
} BGC_FP32_Turn3;
|
||||
|
||||
typedef struct {
|
||||
BGC_FP64_Quaternion _versor;
|
||||
} BGC_FP64_Turn3;
|
||||
|
||||
// ================= Constants ================== //
|
||||
|
||||
extern const BGC_FP32_Turn3 BGC_FP32_IDLE_TURN3;
|
||||
extern const BGC_FP64_Turn3 BGC_FP64_IDLE_TURN3;
|
||||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
inline void bgc_fp32_turn3_reset(BGC_FP32_Turn3* turn)
|
||||
{
|
||||
bgc_fp32_quaternion_make(&turn->_versor, 1.0f, 0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_reset(BGC_FP64_Turn3* turn)
|
||||
{
|
||||
bgc_fp64_quaternion_make(&turn->_versor, 1.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
// ============= Private: Normalize ============= //
|
||||
|
||||
void _bgc_fp32_turn3_normalize(BGC_FP32_Turn3* turn, const float square_modulus);
|
||||
|
||||
void _bgc_fp64_turn3_normalize(BGC_FP64_Turn3* turn, const double square_modulus);
|
||||
|
||||
// ================= Set Values ================= //
|
||||
|
||||
inline void bgc_fp32_turn3_set_raw_values(BGC_FP32_Turn3* turn, const float s0, const float x1, const float x2, const float x3)
|
||||
{
|
||||
bgc_fp32_quaternion_make(&turn->_versor, s0, x1, x2, x3);
|
||||
|
||||
const float square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
|
||||
|
||||
if (!bgc_fp32_is_square_unit(square_modulus)) {
|
||||
_bgc_fp32_turn3_normalize(turn, square_modulus);
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_set_raw_values(BGC_FP64_Turn3* turn, const double s0, const double x1, const double x2, const double x3)
|
||||
{
|
||||
bgc_fp64_quaternion_make(&turn->_versor, s0, x1, x2, x3);
|
||||
|
||||
const double square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
|
||||
|
||||
if (!bgc_fp64_is_square_unit(square_modulus)) {
|
||||
_bgc_fp64_turn3_normalize(turn, square_modulus);
|
||||
}
|
||||
}
|
||||
|
||||
// =============== Get Quaternion =============== //
|
||||
|
||||
inline void bgc_fp32_turn3_get_quaternion(BGC_FP32_Quaternion* quaternion, const BGC_FP32_Turn3* turn)
|
||||
{
|
||||
bgc_fp32_quaternion_copy(quaternion, &turn->_versor);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_get_quaternion(BGC_FP64_Quaternion* quaternion, const BGC_FP64_Turn3* turn)
|
||||
{
|
||||
bgc_fp64_quaternion_copy(quaternion, &turn->_versor);
|
||||
}
|
||||
|
||||
// =============== Set Quaternion =============== //
|
||||
|
||||
inline void bgc_fp32_turn3_set_quaternion(BGC_FP32_Turn3* turn, const BGC_FP32_Quaternion* quaternion)
|
||||
{
|
||||
bgc_fp32_quaternion_copy(&turn->_versor, quaternion);
|
||||
|
||||
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(quaternion);
|
||||
|
||||
if (!bgc_fp32_is_square_unit(square_modulus)) {
|
||||
_bgc_fp32_turn3_normalize(turn, square_modulus);
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_set_quaternion(BGC_FP64_Turn3* turn, const BGC_FP64_Quaternion* quaternion)
|
||||
{
|
||||
bgc_fp64_quaternion_copy(&turn->_versor, quaternion);
|
||||
|
||||
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(quaternion);
|
||||
|
||||
if (!bgc_fp64_is_square_unit(square_modulus)) {
|
||||
_bgc_fp64_turn3_normalize(turn, square_modulus);
|
||||
}
|
||||
}
|
||||
|
||||
// ================ Get Rotation ================ //
|
||||
|
||||
float bgc_fp32_turn3_get_rotation(BGC_FP32_Vector3* axis, const BGC_FP32_Turn3* turn, const int angle_unit);
|
||||
|
||||
double bgc_fp64_turn3_get_rotation(BGC_FP64_Vector3* axis, const BGC_FP64_Turn3* turn, const int angle_unit);
|
||||
|
||||
// ================ Set Rotation ================ //
|
||||
|
||||
void bgc_fp32_turn3_set_rotation(BGC_FP32_Turn3* turn, const float x1, const float x2, const float x3, const float angle, const int angle_unit);
|
||||
|
||||
void bgc_fp64_turn3_set_rotation(BGC_FP64_Turn3* turn, const double x1, const double x2, const double x3, const double angle, const int angle_unit);
|
||||
|
||||
// ========= Find Direction Difference ========== //
|
||||
|
||||
int bgc_fp32_turn3_find_direction_difference(BGC_FP32_Turn3* difference, const BGC_FP32_Vector3* start, const BGC_FP32_Vector3* end);
|
||||
|
||||
int bgc_fp64_turn3_find_direction_difference(BGC_FP64_Turn3* difference, const BGC_FP64_Vector3* start, const BGC_FP64_Vector3* end);
|
||||
|
||||
// =============== Set Directions =============== //
|
||||
|
||||
int bgc_fp32_turn3_make_basis_difference(
|
||||
BGC_FP32_Turn3* turn,
|
||||
const BGC_FP32_Vector3* initial_primary_direction,
|
||||
const BGC_FP32_Vector3* initial_auxiliary_direction,
|
||||
const BGC_FP32_Vector3* final_primary_direction,
|
||||
const BGC_FP32_Vector3* final_auxiliary_direction
|
||||
);
|
||||
|
||||
int bgc_fp64_turn3_make_basis_difference(
|
||||
BGC_FP64_Turn3* turn,
|
||||
const BGC_FP64_Vector3* initial_primary_direction,
|
||||
const BGC_FP64_Vector3* initial_auxiliary_direction,
|
||||
const BGC_FP64_Vector3* final_primary_direction,
|
||||
const BGC_FP64_Vector3* final_auxiliary_direction
|
||||
);
|
||||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
inline void bgc_fp32_turn3_copy(BGC_FP32_Turn3* destination, const BGC_FP32_Turn3* source)
|
||||
{
|
||||
bgc_fp32_quaternion_copy(&destination->_versor, &source->_versor);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_copy(BGC_FP64_Turn3* destination, const BGC_FP64_Turn3* source)
|
||||
{
|
||||
bgc_fp64_quaternion_copy(&destination->_versor, &source->_versor);
|
||||
}
|
||||
|
||||
// ==================== Swap ==================== //
|
||||
|
||||
inline void bgc_fp32_turn3_swap(BGC_FP32_Turn3* turn1, BGC_FP32_Turn3* turn2)
|
||||
{
|
||||
bgc_fp32_quaternion_swap(&turn1->_versor, &turn2->_versor);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_swap(BGC_FP64_Turn3* turn1, BGC_FP64_Turn3* turn2)
|
||||
{
|
||||
bgc_fp64_quaternion_swap(&turn1->_versor, &turn2->_versor);
|
||||
}
|
||||
|
||||
// ================= Comparison ================= //
|
||||
|
||||
inline int bgc_fp32_turn3_is_idle(const BGC_FP32_Turn3* turn)
|
||||
{
|
||||
return turn->_versor.x1 * turn->_versor.x1 + turn->_versor.x2 * turn->_versor.x2 + turn->_versor.x3 * turn->_versor.x3 <= BGC_FP32_SQUARE_EPSILON;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_turn3_is_idle(const BGC_FP64_Turn3* turn)
|
||||
{
|
||||
return turn->_versor.x1 * turn->_versor.x1 + turn->_versor.x2 * turn->_versor.x2 + turn->_versor.x3 * turn->_versor.x3 <= BGC_FP64_SQUARE_EPSILON;
|
||||
}
|
||||
|
||||
// ================== Convert =================== //
|
||||
|
||||
inline void bgc_fp32_turn3_convert_to_fp64(BGC_FP64_Turn3* destination, const BGC_FP32_Turn3* source)
|
||||
{
|
||||
bgc_fp32_quaternion_convert_to_fp64(&destination->_versor, &source->_versor);
|
||||
|
||||
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(&destination->_versor);
|
||||
|
||||
if (!bgc_fp64_is_square_unit(square_modulus)) {
|
||||
_bgc_fp64_turn3_normalize(destination, square_modulus);
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_convert_to_fp32(BGC_FP32_Turn3* destination, const BGC_FP64_Turn3* source)
|
||||
{
|
||||
bgc_fp64_quaternion_convert_to_fp32(&destination->_versor, &source->_versor);
|
||||
|
||||
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(&destination->_versor);
|
||||
|
||||
if (!bgc_fp32_is_square_unit(square_modulus)) {
|
||||
_bgc_fp32_turn3_normalize(destination, square_modulus);
|
||||
}
|
||||
}
|
||||
|
||||
// ================== Shorten =================== //
|
||||
|
||||
inline void bgc_fp32_turn3_shorten(BGC_FP32_Turn3* turn)
|
||||
{
|
||||
if (turn->_versor.s0 < 0.0f) {
|
||||
bgc_fp32_quaternion_revert(&turn->_versor);
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_shorten(BGC_FP64_Turn3* turn)
|
||||
{
|
||||
if (turn->_versor.s0 < 0.0) {
|
||||
bgc_fp64_quaternion_revert(&turn->_versor);
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_fp32_turn3_get_shortened(BGC_FP32_Turn3* shortened, const BGC_FP32_Turn3* turn)
|
||||
{
|
||||
if (turn->_versor.s0 >= 0.0f) {
|
||||
bgc_fp32_quaternion_copy(&shortened->_versor, &turn->_versor);
|
||||
}
|
||||
else {
|
||||
bgc_fp32_quaternion_get_reverse(&shortened->_versor, &turn->_versor);
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_get_shortened(BGC_FP64_Turn3* shortened, const BGC_FP64_Turn3* turn)
|
||||
{
|
||||
if (turn->_versor.s0 >= 0.0) {
|
||||
bgc_fp64_quaternion_copy(&shortened->_versor, &turn->_versor);
|
||||
}
|
||||
else {
|
||||
bgc_fp64_quaternion_get_reverse(&shortened->_versor, &turn->_versor);
|
||||
}
|
||||
}
|
||||
|
||||
// ================= Alternate ================== //
|
||||
|
||||
inline void bgc_fp32_turn3_alternate(BGC_FP32_Turn3* turn)
|
||||
{
|
||||
bgc_fp32_quaternion_revert(&turn->_versor);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_alternate(BGC_FP64_Turn3* turn)
|
||||
{
|
||||
bgc_fp64_quaternion_revert(&turn->_versor);
|
||||
}
|
||||
|
||||
inline void bgc_fp32_turn3_get_alternative(BGC_FP32_Turn3* alternative, const BGC_FP32_Turn3* turn)
|
||||
{
|
||||
bgc_fp32_quaternion_get_reverse(&alternative->_versor, &turn->_versor);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_get_alternative(BGC_FP64_Turn3* alternative, const BGC_FP64_Turn3* turn)
|
||||
{
|
||||
bgc_fp64_quaternion_get_reverse(&alternative->_versor, &turn->_versor);
|
||||
}
|
||||
|
||||
// =================== Revert =================== //
|
||||
|
||||
inline void bgc_fp32_turn3_revert(BGC_FP32_Turn3* turn)
|
||||
{
|
||||
bgc_fp32_quaternion_conjugate(&turn->_versor);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_revert(BGC_FP64_Turn3* turn)
|
||||
{
|
||||
bgc_fp64_quaternion_conjugate(&turn->_versor);
|
||||
}
|
||||
|
||||
inline void bgc_fp32_turn3_get_reverse(BGC_FP32_Turn3* inverse, const BGC_FP32_Turn3* turn)
|
||||
{
|
||||
bgc_fp32_quaternion_get_conjugate(&inverse->_versor, &turn->_versor);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_get_reverse(BGC_FP64_Turn3* inverse, const BGC_FP64_Turn3* turn)
|
||||
{
|
||||
bgc_fp64_quaternion_get_conjugate(&inverse->_versor, &turn->_versor);
|
||||
}
|
||||
|
||||
// =============== Get Exponation =============== //
|
||||
|
||||
void bgc_fp32_turn3_get_exponation(BGC_FP32_Turn3* power, const BGC_FP32_Turn3* base, const float exponent);
|
||||
|
||||
void bgc_fp64_turn3_get_exponation(BGC_FP64_Turn3* power, const BGC_FP64_Turn3* base, const double exponent);
|
||||
|
||||
// ================ Combination ================= //
|
||||
|
||||
inline void bgc_fp32_turn3_combine(BGC_FP32_Turn3* combination, const BGC_FP32_Turn3* first, const BGC_FP32_Turn3* second)
|
||||
{
|
||||
bgc_fp32_quaternion_get_product(&combination->_versor, &second->_versor, &first->_versor);
|
||||
|
||||
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(&combination->_versor);
|
||||
|
||||
if (!bgc_fp32_is_square_unit(square_modulus)) {
|
||||
_bgc_fp32_turn3_normalize(combination, square_modulus);
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_combine(BGC_FP64_Turn3* combination, const BGC_FP64_Turn3* first, const BGC_FP64_Turn3* second)
|
||||
{
|
||||
bgc_fp64_quaternion_get_product(&combination->_versor, &second->_versor, &first->_versor);
|
||||
|
||||
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(&combination->_versor);
|
||||
|
||||
if (!bgc_fp64_is_square_unit(square_modulus)) {
|
||||
_bgc_fp64_turn3_normalize(combination, square_modulus);
|
||||
}
|
||||
}
|
||||
|
||||
// ============ Combination of three ============ //
|
||||
|
||||
inline void bgc_fp32_turn3_combine3(BGC_FP32_Turn3* combination, const BGC_FP32_Turn3* first, const BGC_FP32_Turn3* second, const BGC_FP32_Turn3* third)
|
||||
{
|
||||
BGC_FP32_Quaternion product;
|
||||
|
||||
bgc_fp32_quaternion_get_product(&product, &second->_versor, &first->_versor);
|
||||
|
||||
bgc_fp32_quaternion_get_product(&combination->_versor, &third->_versor, &product);
|
||||
|
||||
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(&combination->_versor);
|
||||
|
||||
if (!bgc_fp32_is_square_unit(square_modulus)) {
|
||||
_bgc_fp32_turn3_normalize(combination, square_modulus);
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_combine3(BGC_FP64_Turn3* combination, const BGC_FP64_Turn3* first, const BGC_FP64_Turn3* second, const BGC_FP64_Turn3* third)
|
||||
{
|
||||
BGC_FP64_Quaternion product;
|
||||
|
||||
bgc_fp64_quaternion_get_product(&product, &second->_versor, &first->_versor);
|
||||
|
||||
bgc_fp64_quaternion_get_product(&combination->_versor, &third->_versor, &product);
|
||||
|
||||
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(&combination->_versor);
|
||||
|
||||
if (!bgc_fp64_is_square_unit(square_modulus)) {
|
||||
_bgc_fp64_turn3_normalize(combination, square_modulus);
|
||||
}
|
||||
}
|
||||
|
||||
// ================= Exclusion ================== //
|
||||
|
||||
inline void bgc_fp32_turn3_exclude(BGC_FP32_Turn3* difference, const BGC_FP32_Turn3* base, const BGC_FP32_Turn3* excludant)
|
||||
{
|
||||
bgc_fp32_quaternion_get_product_by_conjugate(&difference->_versor, &base->_versor, &excludant->_versor);
|
||||
|
||||
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(&difference->_versor);
|
||||
|
||||
if (!bgc_fp32_is_square_unit(square_modulus)) {
|
||||
_bgc_fp32_turn3_normalize(difference, square_modulus);
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_exclude(BGC_FP64_Turn3* difference, const BGC_FP64_Turn3* base, const BGC_FP64_Turn3* excludant)
|
||||
{
|
||||
bgc_fp64_quaternion_get_product_by_conjugate(&difference->_versor, &base->_versor, &excludant->_versor);
|
||||
|
||||
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(&difference->_versor);
|
||||
|
||||
if (!bgc_fp64_is_square_unit(square_modulus)) {
|
||||
_bgc_fp64_turn3_normalize(difference, square_modulus);
|
||||
}
|
||||
}
|
||||
|
||||
// ============ Sphere Interpolation ============ //
|
||||
|
||||
void bgc_fp32_turn3_spherically_interpolate(BGC_FP32_Turn3* interpolation, const BGC_FP32_Turn3* start, const BGC_FP32_Turn3* end, const float phase);
|
||||
|
||||
void bgc_fp64_turn3_spherically_interpolate(BGC_FP64_Turn3* interpolation, const BGC_FP64_Turn3* start, const BGC_FP64_Turn3* end, const double phase);
|
||||
|
||||
// ============ Get Rotation Matrix ============= //
|
||||
|
||||
inline void bgc_fp32_turn3_get_rotation_matrix(BGC_FP32_Matrix3x3* matrix, const BGC_FP32_Turn3* turn)
|
||||
{
|
||||
bgc_fp32_quaternion_get_rotation_matrix(matrix, &turn->_versor);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_get_rotation_matrix(BGC_FP64_Matrix3x3* matrix, const BGC_FP64_Turn3* turn)
|
||||
{
|
||||
bgc_fp64_quaternion_get_rotation_matrix(matrix, &turn->_versor);
|
||||
}
|
||||
|
||||
// ============= Get Reverse Matrix ============= //
|
||||
|
||||
inline void bgc_fp32_turn3_get_reverse_matrix(BGC_FP32_Matrix3x3* matrix, const BGC_FP32_Turn3* turn)
|
||||
{
|
||||
bgc_fp32_quaternion_get_reverse_matrix(matrix, &turn->_versor);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_get_reverse_matrix(BGC_FP64_Matrix3x3* matrix, const BGC_FP64_Turn3* turn)
|
||||
{
|
||||
bgc_fp64_quaternion_get_reverse_matrix(matrix, &turn->_versor);
|
||||
}
|
||||
|
||||
// ============= Get Both Matrixes ============== //
|
||||
|
||||
inline void bgc_fp32_turn3_get_both_matrices(BGC_FP32_Matrix3x3* rotation, BGC_FP32_Matrix3x3* reverse, const BGC_FP32_Turn3* turn)
|
||||
{
|
||||
bgc_fp32_quaternion_get_both_matrices(rotation, reverse, &turn->_versor);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_get_both_matrices(BGC_FP64_Matrix3x3* rotation, BGC_FP64_Matrix3x3* reverse, const BGC_FP64_Turn3* turn)
|
||||
{
|
||||
bgc_fp64_quaternion_get_both_matrices(rotation, reverse, &turn->_versor);
|
||||
}
|
||||
|
||||
// ================ Turn Vector ================= //
|
||||
|
||||
inline void bgc_fp32_turn3_vector(BGC_FP32_Vector3* turned_vector, const BGC_FP32_Turn3* versor, const BGC_FP32_Vector3* vector)
|
||||
{
|
||||
const float tx1 = 2.0f * (versor->_versor.x2 * vector->x3 - versor->_versor.x3 * vector->x2);
|
||||
const float tx2 = 2.0f * (versor->_versor.x3 * vector->x1 - versor->_versor.x1 * vector->x3);
|
||||
const float tx3 = 2.0f * (versor->_versor.x1 * vector->x2 - versor->_versor.x2 * vector->x1);
|
||||
|
||||
const float x1 = (vector->x1 + tx1 * versor->_versor.s0) + (versor->_versor.x2 * tx3 - versor->_versor.x3 * tx2);
|
||||
const float x2 = (vector->x2 + tx2 * versor->_versor.s0) + (versor->_versor.x3 * tx1 - versor->_versor.x1 * tx3);
|
||||
const float x3 = (vector->x3 + tx3 * versor->_versor.s0) + (versor->_versor.x1 * tx2 - versor->_versor.x2 * tx1);
|
||||
|
||||
turned_vector->x1 = x1;
|
||||
turned_vector->x2 = x2;
|
||||
turned_vector->x3 = x3;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_vector(BGC_FP64_Vector3* turned_vector, const BGC_FP64_Turn3* turn, const BGC_FP64_Vector3* vector)
|
||||
{
|
||||
const double tx1 = 2.0 * (turn->_versor.x2 * vector->x3 - turn->_versor.x3 * vector->x2);
|
||||
const double tx2 = 2.0 * (turn->_versor.x3 * vector->x1 - turn->_versor.x1 * vector->x3);
|
||||
const double tx3 = 2.0 * (turn->_versor.x1 * vector->x2 - turn->_versor.x2 * vector->x1);
|
||||
|
||||
const double x1 = (vector->x1 + tx1 * turn->_versor.s0) + (turn->_versor.x2 * tx3 - turn->_versor.x3 * tx2);
|
||||
const double x2 = (vector->x2 + tx2 * turn->_versor.s0) + (turn->_versor.x3 * tx1 - turn->_versor.x1 * tx3);
|
||||
const double x3 = (vector->x3 + tx3 * turn->_versor.s0) + (turn->_versor.x1 * tx2 - turn->_versor.x2 * tx1);
|
||||
|
||||
turned_vector->x1 = x1;
|
||||
turned_vector->x2 = x2;
|
||||
turned_vector->x3 = x3;
|
||||
}
|
||||
|
||||
// ============== Turn Vector Back ============== //
|
||||
|
||||
inline void bgc_fp32_turn3_vector_back(BGC_FP32_Vector3* turned_vector, const BGC_FP32_Turn3* turn, const BGC_FP32_Vector3* vector)
|
||||
{
|
||||
const float tx1 = 2.0f * (turn->_versor.x2 * vector->x3 - turn->_versor.x3 * vector->x2);
|
||||
const float tx2 = 2.0f * (turn->_versor.x3 * vector->x1 - turn->_versor.x1 * vector->x3);
|
||||
const float tx3 = 2.0f * (turn->_versor.x1 * vector->x2 - turn->_versor.x2 * vector->x1);
|
||||
|
||||
const float x1 = (vector->x1 - tx1 * turn->_versor.s0) + (turn->_versor.x2 * tx3 - turn->_versor.x3 * tx2);
|
||||
const float x2 = (vector->x2 - tx2 * turn->_versor.s0) + (turn->_versor.x3 * tx1 - turn->_versor.x1 * tx3);
|
||||
const float x3 = (vector->x3 - tx3 * turn->_versor.s0) + (turn->_versor.x1 * tx2 - turn->_versor.x2 * tx1);
|
||||
|
||||
turned_vector->x1 = x1;
|
||||
turned_vector->x2 = x2;
|
||||
turned_vector->x3 = x3;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_turn3_vector_back(BGC_FP64_Vector3* turned_vector, const BGC_FP64_Turn3* turn, const BGC_FP64_Vector3* vector)
|
||||
{
|
||||
const double tx1 = 2.0 * (turn->_versor.x2 * vector->x3 - turn->_versor.x3 * vector->x2);
|
||||
const double tx2 = 2.0 * (turn->_versor.x3 * vector->x1 - turn->_versor.x1 * vector->x3);
|
||||
const double tx3 = 2.0 * (turn->_versor.x1 * vector->x2 - turn->_versor.x2 * vector->x1);
|
||||
|
||||
const double x1 = (vector->x1 - tx1 * turn->_versor.s0) + (turn->_versor.x2 * tx3 - turn->_versor.x3 * tx2);
|
||||
const double x2 = (vector->x2 - tx2 * turn->_versor.s0) + (turn->_versor.x3 * tx1 - turn->_versor.x1 * tx3);
|
||||
const double x3 = (vector->x3 - tx3 * turn->_versor.s0) + (turn->_versor.x1 * tx2 - turn->_versor.x2 * tx1);
|
||||
|
||||
turned_vector->x1 = x1;
|
||||
turned_vector->x2 = x2;
|
||||
turned_vector->x3 = x3;
|
||||
}
|
||||
|
||||
// ================== Are Close ================= //
|
||||
|
||||
inline int bgc_fp32_turn3_are_close(const BGC_FP32_Turn3* turn1, const BGC_FP32_Turn3* turn2)
|
||||
{
|
||||
BGC_FP32_Quaternion difference;
|
||||
bgc_fp32_quaternion_subtract(&difference, &turn1->_versor, &turn2->_versor);
|
||||
return bgc_fp32_quaternion_get_square_modulus(&difference) <= BGC_FP32_SQUARE_EPSILON;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_turn3_are_close(const BGC_FP64_Turn3* turn1, const BGC_FP64_Turn3* turn2)
|
||||
{
|
||||
BGC_FP64_Quaternion difference;
|
||||
bgc_fp64_quaternion_subtract(&difference, &turn1->_versor, &turn2->_versor);
|
||||
return bgc_fp64_quaternion_get_square_modulus(&difference) <= BGC_FP64_SQUARE_EPSILON;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,584 +0,0 @@
|
|||
#include <math.h>
|
||||
|
||||
#include "angle.h"
|
||||
#include "versor.h"
|
||||
|
||||
const BGC_FP32_Versor BGC_FP32_IDLE_VERSOR = { 1.0f, 0.0f, 0.0f, 0.0f };
|
||||
|
||||
const BGC_FP64_Versor BGC_FP64_IDLE_VERSOR = { 1.0, 0.0, 0.0, 0.0 };
|
||||
|
||||
extern inline void bgc_fp32_versor_reset(BGC_FP32_Versor* versor);
|
||||
extern inline void bgc_fp64_versor_reset(BGC_FP64_Versor* versor);
|
||||
|
||||
extern inline void bgc_fp32_versor_make(BGC_FP32_Versor* versor, const float s0, const float x1, const float x2, const float x3);
|
||||
extern inline void bgc_fp64_versor_make(BGC_FP64_Versor* versor, const double s0, const double x1, const double x2, const double x3);
|
||||
|
||||
extern inline void bgc_fp32_versor_make_for_rotation(BGC_FP32_Versor* versor, const BGC_FP32_Rotation3* rotation);
|
||||
extern inline void bgc_fp64_versor_make_for_rotation(BGC_FP64_Versor* versor, const BGC_FP64_Rotation3* rotation);
|
||||
|
||||
extern inline void bgc_fp32_versor_copy(BGC_FP32_Versor* destination, const BGC_FP32_Versor* source);
|
||||
extern inline void bgc_fp64_versor_copy(BGC_FP64_Versor* destination, const BGC_FP64_Versor* source);
|
||||
|
||||
extern inline void bgc_fp32_versor_swap(BGC_FP32_Versor* versor1, BGC_FP32_Versor* versor2);
|
||||
extern inline void bgc_fp64_versor_swap(BGC_FP64_Versor* versor1, BGC_FP64_Versor* versor2);
|
||||
|
||||
extern inline int bgc_fp32_versor_is_idle(const BGC_FP32_Versor* versor);
|
||||
extern inline int bgc_fp64_versor_is_idle(const BGC_FP64_Versor* versor);
|
||||
|
||||
extern inline void bgc_fp32_versor_convert_to_fp64(BGC_FP64_Versor* destination, const BGC_FP32_Versor* source);
|
||||
extern inline void bgc_fp64_versor_convert_to_fp32(BGC_FP32_Versor* destination, const BGC_FP64_Versor* source);
|
||||
|
||||
extern inline void bgc_fp32_versor_shorten(BGC_FP32_Versor* versor);
|
||||
extern inline void bgc_fp64_versor_shorten(BGC_FP64_Versor* versor);
|
||||
|
||||
extern inline void bgc_fp32_versor_get_shortened(BGC_FP32_Versor* shortened, const BGC_FP32_Versor* versor);
|
||||
extern inline void bgc_fp64_versor_get_shortened(BGC_FP64_Versor* shortened, const BGC_FP64_Versor* versor);
|
||||
|
||||
extern inline void bgc_fp32_versor_alternate(BGC_FP32_Versor* versor);
|
||||
extern inline void bgc_fp64_versor_alternate(BGC_FP64_Versor* versor);
|
||||
|
||||
extern inline void bgc_fp32_versor_get_alternative(BGC_FP32_Versor* alternative, const BGC_FP32_Versor* versor);
|
||||
extern inline void bgc_fp64_versor_get_alternative(BGC_FP64_Versor* alternative, const BGC_FP64_Versor* versor);
|
||||
|
||||
extern inline void bgc_fp32_versor_revert(BGC_FP32_Versor* versor);
|
||||
extern inline void bgc_fp64_versor_revert(BGC_FP64_Versor* versor);
|
||||
|
||||
extern inline void bgc_fp32_versor_get_reverse(BGC_FP32_Versor* inverse, const BGC_FP32_Versor* versor);
|
||||
extern inline void bgc_fp64_versor_get_reverse(BGC_FP64_Versor* inverse, const BGC_FP64_Versor* versor);
|
||||
|
||||
extern inline void bgc_fp32_versor_combine(BGC_FP32_Versor* combination, const BGC_FP32_Versor* first, const BGC_FP32_Versor* second);
|
||||
extern inline void bgc_fp64_versor_combine(BGC_FP64_Versor* combination, const BGC_FP64_Versor* first, const BGC_FP64_Versor* second);
|
||||
|
||||
extern inline void bgc_fp32_versor_combine3(BGC_FP32_Versor* combination, const BGC_FP32_Versor* first, const BGC_FP32_Versor* second, const BGC_FP32_Versor* third);
|
||||
extern inline void bgc_fp64_versor_combine3(BGC_FP64_Versor* combination, const BGC_FP64_Versor* first, const BGC_FP64_Versor* second, const BGC_FP64_Versor* third);
|
||||
|
||||
extern inline void bgc_fp32_versor_exclude(BGC_FP32_Versor* difference, const BGC_FP32_Versor* base, const BGC_FP32_Versor* excludant);
|
||||
extern inline void bgc_fp64_versor_exclude(BGC_FP64_Versor* difference, const BGC_FP64_Versor* base, const BGC_FP64_Versor* excludant);
|
||||
|
||||
extern inline void bgc_fp32_versor_get_rotation_matrix(BGC_FP32_Matrix3x3* matrix, const BGC_FP32_Versor* versor);
|
||||
extern inline void bgc_fp64_versor_get_rotation_matrix(BGC_FP64_Matrix3x3* matrix, const BGC_FP64_Versor* versor);
|
||||
|
||||
extern inline void bgc_fp32_versor_get_reverse_matrix(BGC_FP32_Matrix3x3* matrix, const BGC_FP32_Versor* versor);
|
||||
extern inline void bgc_fp64_versor_get_reverse_matrix(BGC_FP64_Matrix3x3* matrix, const BGC_FP64_Versor* versor);
|
||||
|
||||
extern inline void bgc_fp32_versor_get_both_matrices(BGC_FP32_Matrix3x3* rotation, BGC_FP32_Matrix3x3* reverse, const BGC_FP32_Versor* versor);
|
||||
extern inline void bgc_fp64_versor_get_both_matrices(BGC_FP64_Matrix3x3* rotation, BGC_FP64_Matrix3x3* reverse, const BGC_FP64_Versor* versor);
|
||||
|
||||
extern inline void bgc_fp32_versor_turn_vector(BGC_FP32_Vector3* turned_vector, const BGC_FP32_Versor* versor, const BGC_FP32_Vector3* vector);
|
||||
extern inline void bgc_fp64_versor_turn_vector(BGC_FP64_Vector3* turned_vector, const BGC_FP64_Versor* versor, const BGC_FP64_Vector3* vector);
|
||||
|
||||
extern inline void bgc_fp32_versor_turn_vector_back(BGC_FP32_Vector3* turned_vector, const BGC_FP32_Versor* versor, const BGC_FP32_Vector3* vector);
|
||||
extern inline void bgc_fp64_versor_turn_vector_back(BGC_FP64_Vector3* turned_vector, const BGC_FP64_Versor* versor, const BGC_FP64_Vector3* vector);
|
||||
|
||||
extern inline int bgc_fp32_versor_are_close(const BGC_FP32_Versor* versor1, const BGC_FP32_Versor* versor2);
|
||||
extern inline int bgc_fp64_versor_are_close(const BGC_FP64_Versor* versor1, const BGC_FP64_Versor* versor2);
|
||||
|
||||
// ================= Normalize ================== //
|
||||
|
||||
void _bgc_fp32_versor_normalize(BGC_FP32_Versor* versor)
|
||||
{
|
||||
const float square_modulus = (versor->_s0 * versor->_s0 + versor->_x1 * versor->_x1) + (versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3);
|
||||
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
versor->_s0 = 1.0f;
|
||||
versor->_x1 = 0.0f;
|
||||
versor->_x2 = 0.0f;
|
||||
versor->_x3 = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
const float multiplier = sqrtf(1.0f / square_modulus);
|
||||
|
||||
versor->_s0 *= multiplier;
|
||||
versor->_x1 *= multiplier;
|
||||
versor->_x2 *= multiplier;
|
||||
versor->_x3 *= multiplier;
|
||||
}
|
||||
|
||||
void _bgc_fp64_versor_normalize(BGC_FP64_Versor* versor)
|
||||
{
|
||||
const double square_modulus = (versor->_s0 * versor->_s0 + versor->_x1 * versor->_x1) + (versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3);
|
||||
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
versor->_s0 = 1.0;
|
||||
versor->_x1 = 0.0;
|
||||
versor->_x2 = 0.0;
|
||||
versor->_x3 = 0.0;
|
||||
return;
|
||||
}
|
||||
|
||||
const double multiplier = sqrt(1.0 / square_modulus);
|
||||
|
||||
versor->_s0 *= multiplier;
|
||||
versor->_x1 *= multiplier;
|
||||
versor->_x2 *= multiplier;
|
||||
versor->_x3 *= multiplier;
|
||||
}
|
||||
|
||||
// ================== Set Turn ================== //
|
||||
|
||||
void bgc_fp32_versor_make_for_turn(BGC_FP32_Versor* versor, const float x1, const float x2, const float x3, const float angle, const int unit)
|
||||
{
|
||||
const float square_vector = x1 * x1 + x2 * x2 + x3 * x3;
|
||||
|
||||
if (square_vector <= BGC_FP32_SQUARE_EPSILON) {
|
||||
bgc_fp32_versor_reset(versor);
|
||||
return;
|
||||
}
|
||||
|
||||
const float half_angle = bgc_fp32_angle_to_radians(0.5f * angle, unit);
|
||||
|
||||
const float sine = sinf(half_angle);
|
||||
|
||||
if (bgc_fp32_is_zero(sine)) {
|
||||
bgc_fp32_versor_reset(versor);
|
||||
return;
|
||||
}
|
||||
|
||||
const float multiplier = sine / sqrtf(square_vector);
|
||||
|
||||
bgc_fp32_versor_make(versor, cosf(half_angle), x1 * multiplier, x2 * multiplier, x3 * multiplier);
|
||||
}
|
||||
|
||||
void bgc_fp64_versor_make_for_turn(BGC_FP64_Versor* versor, const double x1, const double x2, const double x3, const double angle, const int unit)
|
||||
{
|
||||
const double square_vector = x1 * x1 + x2 * x2 + x3 * x3;
|
||||
|
||||
if (square_vector <= BGC_FP64_SQUARE_EPSILON) {
|
||||
bgc_fp64_versor_reset(versor);
|
||||
return;
|
||||
}
|
||||
|
||||
const double half_angle = bgc_fp64_angle_to_radians(0.5 * angle, unit);
|
||||
|
||||
const double sine = sin(half_angle);
|
||||
|
||||
if (bgc_fp64_is_zero(sine)) {
|
||||
bgc_fp64_versor_reset(versor);
|
||||
return;
|
||||
}
|
||||
|
||||
const double multiplier = sine / sqrt(square_vector);
|
||||
|
||||
bgc_fp64_versor_make(versor, cos(half_angle), x1 * multiplier, x2 * multiplier, x3 * multiplier);
|
||||
}
|
||||
|
||||
// ========= Make Direction Difference ========== //
|
||||
|
||||
static int _bgc_fp32_versor_make_direction_turn(BGC_FP32_Versor* versor, const BGC_FP32_Vector3* start, const BGC_FP32_Vector3* end, const float square_modulus_product)
|
||||
{
|
||||
BGC_FP32_Vector3 orthogonal_axis;
|
||||
|
||||
bgc_fp32_vector3_get_cross_product(&orthogonal_axis, start, end);
|
||||
|
||||
const float scalar_product = bgc_fp32_vector3_get_dot_product(start, end);
|
||||
const float square_modulus = bgc_fp32_vector3_get_square_modulus(&orthogonal_axis);
|
||||
const float square_sine = square_modulus / square_modulus_product;
|
||||
|
||||
if (square_sine > BGC_FP32_SQUARE_EPSILON) {
|
||||
const float cosine = scalar_product / sqrtf(square_modulus_product);
|
||||
const float angle = 0.5f * atan2f(sqrtf(square_sine), cosine);
|
||||
|
||||
const float multiplier = sinf(angle) * sqrtf(1.0f / square_modulus);
|
||||
|
||||
bgc_fp32_versor_make(versor, cosf(angle), orthogonal_axis.x1 * multiplier, orthogonal_axis.x2 * multiplier, orthogonal_axis.x3 * multiplier);
|
||||
return BGC_SOME_TURN;
|
||||
}
|
||||
|
||||
if (scalar_product < 0.0f) {
|
||||
return BGC_OPPOSITE;
|
||||
}
|
||||
|
||||
bgc_fp32_versor_reset(versor);
|
||||
return BGC_ZERO_TURN;
|
||||
}
|
||||
|
||||
static int _bgc_fp64_versor_make_direction_turn(BGC_FP64_Versor* versor, const BGC_FP64_Vector3* start, const BGC_FP64_Vector3* end, const double square_modulus_product)
|
||||
{
|
||||
BGC_FP64_Vector3 orthogonal_axis;
|
||||
|
||||
bgc_fp64_vector3_get_cross_product(&orthogonal_axis, start, end);
|
||||
|
||||
const double scalar_product = bgc_fp64_vector3_get_dot_product(start, end);
|
||||
const double square_modulus = bgc_fp64_vector3_get_square_modulus(&orthogonal_axis);
|
||||
const double square_sine = square_modulus / square_modulus_product;
|
||||
|
||||
if (square_sine > BGC_FP64_SQUARE_EPSILON) {
|
||||
const double cosine = scalar_product / sqrt(square_modulus_product);
|
||||
const double angle = 0.5 * atan2(sqrt(square_sine), cosine);
|
||||
|
||||
const double multiplier = sin(angle) * sqrt(1.0f / square_modulus);
|
||||
|
||||
bgc_fp64_versor_make(versor, cos(angle), orthogonal_axis.x1 * multiplier, orthogonal_axis.x2 * multiplier, orthogonal_axis.x3 * multiplier);
|
||||
return BGC_SOME_TURN;
|
||||
}
|
||||
|
||||
if (scalar_product < 0.0) {
|
||||
return BGC_OPPOSITE;
|
||||
}
|
||||
|
||||
bgc_fp64_versor_reset(versor);
|
||||
return BGC_ZERO_TURN;
|
||||
}
|
||||
|
||||
int bgc_fp32_versor_make_direction_difference(BGC_FP32_Versor* versor, const BGC_FP32_Vector3* start, const BGC_FP32_Vector3* end)
|
||||
{
|
||||
const float start_square_modulus = bgc_fp32_vector3_get_square_modulus(start);
|
||||
const float end_square_modulus = bgc_fp32_vector3_get_square_modulus(end);
|
||||
|
||||
if (start_square_modulus <= BGC_FP32_SQUARE_EPSILON || end_square_modulus <= BGC_FP32_SQUARE_EPSILON) {
|
||||
bgc_fp32_versor_reset(versor);
|
||||
return BGC_ZERO_TURN;
|
||||
}
|
||||
|
||||
return _bgc_fp32_versor_make_direction_turn(versor, start, end, start_square_modulus * end_square_modulus);
|
||||
}
|
||||
|
||||
int bgc_fp64_versor_make_direction_difference(BGC_FP64_Versor* versor, const BGC_FP64_Vector3* start, const BGC_FP64_Vector3* end)
|
||||
{
|
||||
const double start_square_modulus = bgc_fp64_vector3_get_square_modulus(start);
|
||||
const double end_square_modulus = bgc_fp64_vector3_get_square_modulus(end);
|
||||
|
||||
if (start_square_modulus <= BGC_FP64_SQUARE_EPSILON || end_square_modulus <= BGC_FP64_SQUARE_EPSILON) {
|
||||
bgc_fp64_versor_reset(versor);
|
||||
return BGC_ZERO_TURN;
|
||||
}
|
||||
|
||||
return _bgc_fp64_versor_make_direction_turn(versor, start, end, start_square_modulus * end_square_modulus);
|
||||
}
|
||||
|
||||
// =============== Set Directions =============== //
|
||||
|
||||
static int _bgc_fp32_versor_validate_basis(const float primary_square_modulus, const float auxiliary_square_modulus, const float orthogonal_square_modulus)
|
||||
{
|
||||
if (primary_square_modulus <= BGC_FP32_SQUARE_EPSILON) {
|
||||
//TODO: add error code for: primary_vector is zero
|
||||
return BGC_FAILED;
|
||||
}
|
||||
|
||||
if (auxiliary_square_modulus <= BGC_FP32_SQUARE_EPSILON) {
|
||||
//TODO: add error code for: auxiliary_vector is zero
|
||||
return BGC_FAILED;
|
||||
}
|
||||
|
||||
if (orthogonal_square_modulus <= BGC_FP32_SQUARE_EPSILON * primary_square_modulus * auxiliary_square_modulus) {
|
||||
//TODO: add error code for: primary_vector and auxiliary_vector are parallel
|
||||
return BGC_FAILED;
|
||||
}
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
static int _bgc_fp64_versor_validate_basis(const double primary_square_modulus, const double auxiliary_square_modulus, const double orthogonal_square_modulus)
|
||||
{
|
||||
if (primary_square_modulus <= BGC_FP64_SQUARE_EPSILON) {
|
||||
//TODO: add error code for: primary_vector is zero
|
||||
return BGC_FAILED;
|
||||
}
|
||||
|
||||
if (auxiliary_square_modulus <= BGC_FP64_SQUARE_EPSILON) {
|
||||
//TODO: add error code for: auxiliary_vector is zero
|
||||
return BGC_FAILED;
|
||||
}
|
||||
|
||||
if (orthogonal_square_modulus <= BGC_FP64_SQUARE_EPSILON * primary_square_modulus * auxiliary_square_modulus) {
|
||||
//TODO: add error code for: primary_vector and auxiliary_vector are parallel
|
||||
return BGC_FAILED;
|
||||
}
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
int bgc_fp32_versor_make_basis_difference(
|
||||
BGC_FP32_Versor* versor,
|
||||
const BGC_FP32_Vector3* initial_primary_direction,
|
||||
const BGC_FP32_Vector3* initial_auxiliary_direction,
|
||||
const BGC_FP32_Vector3* final_primary_direction,
|
||||
const BGC_FP32_Vector3* final_auxiliary_direction
|
||||
)
|
||||
{
|
||||
BGC_FP32_Vector3 initial_orthogonal_direction, turned_orthogonal_direction, final_orthogonal_direction;
|
||||
|
||||
// Step 1: Validate initial basis:
|
||||
bgc_fp32_vector3_get_cross_product(&initial_orthogonal_direction, initial_primary_direction, initial_auxiliary_direction);
|
||||
|
||||
const float initial_primary_square_modulus = bgc_fp32_vector3_get_square_modulus(initial_primary_direction);
|
||||
const float initial_auxiliary_square_modulus = bgc_fp32_vector3_get_square_modulus(initial_auxiliary_direction);
|
||||
const float initial_orthogonal_square_modulus = bgc_fp32_vector3_get_square_modulus(&initial_orthogonal_direction);
|
||||
|
||||
const int initial_basis_valudation = _bgc_fp32_versor_validate_basis(initial_primary_square_modulus, initial_auxiliary_square_modulus, initial_orthogonal_square_modulus);
|
||||
|
||||
if (initial_basis_valudation != BGC_SUCCESS) {
|
||||
return initial_basis_valudation;
|
||||
}
|
||||
|
||||
// Step 1: Validate final basis:
|
||||
bgc_fp32_vector3_get_cross_product(&final_orthogonal_direction, final_primary_direction, final_auxiliary_direction);
|
||||
|
||||
const float final_primary_square_modulus = bgc_fp32_vector3_get_square_modulus(final_primary_direction);
|
||||
const float final_auxiliary_square_modulus = bgc_fp32_vector3_get_square_modulus(final_auxiliary_direction);
|
||||
const float final_orthogonal_square_modulus = bgc_fp32_vector3_get_square_modulus(&final_orthogonal_direction);
|
||||
|
||||
const int final_basis_valudation = _bgc_fp32_versor_validate_basis(final_primary_square_modulus, final_auxiliary_square_modulus, final_orthogonal_square_modulus);
|
||||
|
||||
if (final_basis_valudation != BGC_SUCCESS) {
|
||||
return final_basis_valudation;
|
||||
}
|
||||
|
||||
// Step 3: Validate normalize orthogonal vectors:
|
||||
bgc_fp32_vector3_divide(&initial_orthogonal_direction, &initial_orthogonal_direction, sqrtf(initial_orthogonal_square_modulus));
|
||||
bgc_fp32_vector3_divide(&final_orthogonal_direction, &final_orthogonal_direction, sqrtf(final_orthogonal_square_modulus));
|
||||
|
||||
BGC_FP32_Versor turn1, turn2;
|
||||
|
||||
// Step 4: Find turn1
|
||||
int turn1_code = _bgc_fp32_versor_make_direction_turn(&turn1, initial_primary_direction, final_primary_direction, initial_primary_square_modulus * final_primary_square_modulus);
|
||||
|
||||
if (turn1_code == BGC_OPPOSITE) {
|
||||
bgc_fp32_versor_make(&turn1, 0.0f, initial_orthogonal_direction.x1, initial_orthogonal_direction.x2, initial_orthogonal_direction.x3);
|
||||
}
|
||||
|
||||
bgc_fp32_versor_turn_vector(&turned_orthogonal_direction, &turn1, &initial_orthogonal_direction);
|
||||
|
||||
// Step 5: Find turn2:
|
||||
int turn2_code = _bgc_fp32_versor_make_direction_turn(&turn2, &turned_orthogonal_direction, &final_orthogonal_direction, 1.0f);
|
||||
|
||||
if (turn2_code == BGC_OPPOSITE) {
|
||||
const float turn2_multiplier = sqrtf(1.0f / final_primary_square_modulus);
|
||||
|
||||
bgc_fp32_versor_make(&turn2,
|
||||
0.0f,
|
||||
final_primary_direction->x1 * turn2_multiplier,
|
||||
final_primary_direction->x2 * turn2_multiplier,
|
||||
final_primary_direction->x3 * turn2_multiplier
|
||||
);
|
||||
}
|
||||
|
||||
// Step 6: Combine turn1 and turn2:
|
||||
bgc_fp32_versor_combine(versor, &turn1, &turn2);
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
int bgc_fp64_versor_make_basis_difference(
|
||||
BGC_FP64_Versor* versor,
|
||||
const BGC_FP64_Vector3* initial_primary_direction,
|
||||
const BGC_FP64_Vector3* initial_auxiliary_direction,
|
||||
const BGC_FP64_Vector3* final_primary_direction,
|
||||
const BGC_FP64_Vector3* final_auxiliary_direction
|
||||
)
|
||||
{
|
||||
BGC_FP64_Vector3 initial_orthogonal_direction, turned_orthogonal_direction, final_orthogonal_direction;
|
||||
|
||||
// Step 1: Validate initial basis:
|
||||
bgc_fp64_vector3_get_cross_product(&initial_orthogonal_direction, initial_primary_direction, initial_auxiliary_direction);
|
||||
|
||||
const double initial_primary_square_modulus = bgc_fp64_vector3_get_square_modulus(initial_primary_direction);
|
||||
const double initial_auxiliary_square_modulus = bgc_fp64_vector3_get_square_modulus(initial_auxiliary_direction);
|
||||
const double initial_orthogonal_square_modulus = bgc_fp64_vector3_get_square_modulus(&initial_orthogonal_direction);
|
||||
|
||||
const int initial_basis_valudation = _bgc_fp64_versor_validate_basis(initial_primary_square_modulus, initial_auxiliary_square_modulus, initial_orthogonal_square_modulus);
|
||||
|
||||
if (initial_basis_valudation != BGC_SUCCESS) {
|
||||
return initial_basis_valudation;
|
||||
}
|
||||
|
||||
// Step 1: Validate final basis:
|
||||
bgc_fp64_vector3_get_cross_product(&final_orthogonal_direction, final_primary_direction, final_auxiliary_direction);
|
||||
|
||||
const double final_primary_square_modulus = bgc_fp64_vector3_get_square_modulus(final_primary_direction);
|
||||
const double final_auxiliary_square_modulus = bgc_fp64_vector3_get_square_modulus(final_auxiliary_direction);
|
||||
const double final_orthogonal_square_modulus = bgc_fp64_vector3_get_square_modulus(&final_orthogonal_direction);
|
||||
|
||||
const int final_basis_valudation = _bgc_fp64_versor_validate_basis(final_primary_square_modulus, final_auxiliary_square_modulus, final_orthogonal_square_modulus);
|
||||
|
||||
if (final_basis_valudation != BGC_SUCCESS) {
|
||||
return final_basis_valudation;
|
||||
}
|
||||
|
||||
// Step 3: Validate normalize orthogonal vectors:
|
||||
bgc_fp64_vector3_divide(&initial_orthogonal_direction, &initial_orthogonal_direction, sqrt(initial_orthogonal_square_modulus));
|
||||
bgc_fp64_vector3_divide(&final_orthogonal_direction, &final_orthogonal_direction, sqrt(final_orthogonal_square_modulus));
|
||||
|
||||
BGC_FP64_Versor turn1, turn2;
|
||||
|
||||
// Step 4: Find turn1
|
||||
int turn1_code = _bgc_fp64_versor_make_direction_turn(&turn1, initial_primary_direction, final_primary_direction, initial_primary_square_modulus * final_primary_square_modulus);
|
||||
|
||||
if (turn1_code == BGC_OPPOSITE) {
|
||||
bgc_fp64_versor_make(&turn1, 0.0, initial_orthogonal_direction.x1, initial_orthogonal_direction.x2, initial_orthogonal_direction.x3);
|
||||
}
|
||||
|
||||
bgc_fp64_versor_turn_vector(&turned_orthogonal_direction, &turn1, &initial_orthogonal_direction);
|
||||
|
||||
// Step 5: Find turn2:
|
||||
int turn2_code = _bgc_fp64_versor_make_direction_turn(&turn2, &turned_orthogonal_direction, &final_orthogonal_direction, 1.0f);
|
||||
|
||||
if (turn2_code == BGC_OPPOSITE) {
|
||||
const double turn2_multiplier = sqrt(1.0 / final_primary_square_modulus);
|
||||
|
||||
bgc_fp64_versor_make(&turn2,
|
||||
0.0,
|
||||
final_primary_direction->x1 * turn2_multiplier,
|
||||
final_primary_direction->x2 * turn2_multiplier,
|
||||
final_primary_direction->x3 * turn2_multiplier
|
||||
);
|
||||
}
|
||||
|
||||
// Step 6: Combine turn1 and turn2:
|
||||
bgc_fp64_versor_combine(versor, &turn1, &turn2);
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// =============== Get Exponation =============== //
|
||||
|
||||
void bgc_fp32_versor_get_exponation(BGC_FP32_Versor* power, const BGC_FP32_Versor* base, const float exponent)
|
||||
{
|
||||
const float square_vector = base->_x1 * base->_x1 + base->_x2 * base->_x2 + base->_x3 * base->_x3;
|
||||
|
||||
if (square_vector <= BGC_FP32_SQUARE_EPSILON || square_vector != square_vector) {
|
||||
bgc_fp32_versor_reset(power);
|
||||
return;
|
||||
}
|
||||
|
||||
const float vector_modulus = sqrtf(square_vector);
|
||||
|
||||
const float angle = atan2f(vector_modulus, base->_s0) * exponent;
|
||||
|
||||
const float multiplier = sinf(angle) / vector_modulus;
|
||||
|
||||
bgc_fp32_versor_make(power, cosf(angle), base->_x1 * multiplier, base->_x2 * multiplier, base->_x3 * multiplier);
|
||||
}
|
||||
|
||||
void bgc_fp64_versor_get_exponation(BGC_FP64_Versor* power, const BGC_FP64_Versor* base, const double exponent)
|
||||
{
|
||||
const double square_vector = base->_x1 * base->_x1 + base->_x2 * base->_x2 + base->_x3 * base->_x3;
|
||||
|
||||
if (square_vector <= BGC_FP64_SQUARE_EPSILON || square_vector != square_vector) {
|
||||
bgc_fp64_versor_reset(power);
|
||||
return;
|
||||
}
|
||||
|
||||
const double vector_modulus = sqrt(square_vector);
|
||||
|
||||
const double angle = atan2(vector_modulus, base->_s0) * exponent;
|
||||
|
||||
const double multiplier = sin(angle) / vector_modulus;
|
||||
|
||||
bgc_fp64_versor_make(power, cos(angle), base->_x1 * multiplier, base->_x2 * multiplier, base->_x3 * multiplier);
|
||||
}
|
||||
|
||||
// ============ Sphere Interpolation ============ //
|
||||
|
||||
void bgc_fp32_versor_spherically_interpolate(BGC_FP32_Versor* interpolation, const BGC_FP32_Versor* start, const BGC_FP32_Versor* end, const float phase)
|
||||
{
|
||||
const float delta_s0 = (end->_s0 * start->_s0 + end->_x1 * start->_x1) + (end->_x2 * start->_x2 + end->_x3 * start->_x3);
|
||||
const float delta_x1 = (end->_x1 * start->_s0 + end->_x3 * start->_x2) - (end->_s0 * start->_x1 + end->_x2 * start->_x3);
|
||||
const float delta_x2 = (end->_x2 * start->_s0 + end->_x1 * start->_x3) - (end->_s0 * start->_x2 + end->_x3 * start->_x1);
|
||||
const float delta_x3 = (end->_x3 * start->_s0 + end->_x2 * start->_x1) - (end->_s0 * start->_x3 + end->_x1 * start->_x2);
|
||||
|
||||
const float square_vector = delta_x1 * delta_x1 + delta_x2 * delta_x2 + delta_x3 * delta_x3;
|
||||
|
||||
// square_vector != square_vector means checking for NaN value at square_vector
|
||||
if (square_vector <= BGC_FP32_SQUARE_EPSILON || isnan(square_vector)) {
|
||||
bgc_fp32_versor_copy(interpolation, end);
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculating of the turning which fits the phase:
|
||||
const float vector_modulus = sqrtf(square_vector);
|
||||
const float angle = atan2f(vector_modulus, delta_s0) * phase;
|
||||
const float multiplier = sinf(angle) / vector_modulus;
|
||||
|
||||
const float turn_s0 = cosf(angle);
|
||||
const float turn_x1 = delta_x1 * multiplier;
|
||||
const float turn_x2 = delta_x2 * multiplier;
|
||||
const float turn_x3 = delta_x3 * multiplier;
|
||||
|
||||
// Combining of starting orientation with the turning
|
||||
bgc_fp32_versor_make(
|
||||
interpolation,
|
||||
(turn_s0 * start->_s0 - turn_x1 * start->_x1) - (turn_x2 * start->_x2 + turn_x3 * start->_x3),
|
||||
(turn_x1 * start->_s0 + turn_s0 * start->_x1) - (turn_x3 * start->_x2 - turn_x2 * start->_x3),
|
||||
(turn_x2 * start->_s0 + turn_s0 * start->_x2) - (turn_x1 * start->_x3 - turn_x3 * start->_x1),
|
||||
(turn_x3 * start->_s0 + turn_s0 * start->_x3) - (turn_x2 * start->_x1 - turn_x1 * start->_x2)
|
||||
);
|
||||
}
|
||||
|
||||
void bgc_fp64_versor_spherically_interpolate(BGC_FP64_Versor* interpolation, const BGC_FP64_Versor* start, const BGC_FP64_Versor* end, const double phase)
|
||||
{
|
||||
const double delta_s0 = (end->_s0 * start->_s0 + end->_x1 * start->_x1) + (end->_x2 * start->_x2 + end->_x3 * start->_x3);
|
||||
const double delta_x1 = (end->_x1 * start->_s0 + end->_x3 * start->_x2) - (end->_s0 * start->_x1 + end->_x2 * start->_x3);
|
||||
const double delta_x2 = (end->_x2 * start->_s0 + end->_x1 * start->_x3) - (end->_s0 * start->_x2 + end->_x3 * start->_x1);
|
||||
const double delta_x3 = (end->_x3 * start->_s0 + end->_x2 * start->_x1) - (end->_s0 * start->_x3 + end->_x1 * start->_x2);
|
||||
|
||||
const double square_vector = delta_x1 * delta_x1 + delta_x2 * delta_x2 + delta_x3 * delta_x3;
|
||||
|
||||
// square_vector != square_vector means checking for NaN value at square_vector
|
||||
if (square_vector <= BGC_FP64_SQUARE_EPSILON || isnan(square_vector)) {
|
||||
bgc_fp64_versor_copy(interpolation, end);
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculating of the turning which fits the phase:
|
||||
const double vector_modulus = sqrt(square_vector);
|
||||
const double angle = atan2(vector_modulus, delta_s0) * phase;
|
||||
const double multiplier = sin(angle) / vector_modulus;
|
||||
|
||||
const double turn_s0 = cos(angle);
|
||||
const double turn_x1 = delta_x1 * multiplier;
|
||||
const double turn_x2 = delta_x2 * multiplier;
|
||||
const double turn_x3 = delta_x3 * multiplier;
|
||||
|
||||
// Combining of starting orientation with the turning
|
||||
bgc_fp64_versor_make(
|
||||
interpolation,
|
||||
(turn_s0 * start->_s0 - turn_x1 * start->_x1) - (turn_x2 * start->_x2 + turn_x3 * start->_x3),
|
||||
(turn_x1 * start->_s0 + turn_s0 * start->_x1) - (turn_x3 * start->_x2 - turn_x2 * start->_x3),
|
||||
(turn_x2 * start->_s0 + turn_s0 * start->_x2) - (turn_x1 * start->_x3 - turn_x3 * start->_x1),
|
||||
(turn_x3 * start->_s0 + turn_s0 * start->_x3) - (turn_x2 * start->_x1 - turn_x1 * start->_x2)
|
||||
);
|
||||
}
|
||||
|
||||
// ================ Get Rotation ================ //
|
||||
|
||||
void bgc_fp32_versor_get_rotation(BGC_FP32_Rotation3* rotation, const BGC_FP32_Versor* versor)
|
||||
{
|
||||
const float square_modulus = versor->_x1 * versor->_x1 + versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3;
|
||||
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON) {
|
||||
bgc_fp32_rotation3_reset(rotation);
|
||||
return;
|
||||
}
|
||||
|
||||
const float vector_modulus = sqrtf(square_modulus);
|
||||
|
||||
const float multiplier = 1.0f / vector_modulus;
|
||||
|
||||
rotation->radians = 2.0f * atan2f(vector_modulus, versor->_s0);
|
||||
|
||||
rotation->axis.x1 = versor->_x1 * multiplier;
|
||||
rotation->axis.x2 = versor->_x2 * multiplier;
|
||||
rotation->axis.x3 = versor->_x3 * multiplier;
|
||||
}
|
||||
|
||||
void bgc_fp64_versor_get_rotation(BGC_FP64_Rotation3* rotation, const BGC_FP64_Versor* versor)
|
||||
{
|
||||
const double square_modulus = versor->_x1 * versor->_x1 + versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3;
|
||||
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON) {
|
||||
bgc_fp64_rotation3_reset(rotation);
|
||||
return;
|
||||
}
|
||||
|
||||
const double vector_modulus = sqrt(square_modulus);
|
||||
|
||||
const double multiplier = 1.0 / vector_modulus;
|
||||
|
||||
rotation->radians = 2.0 * atan2(vector_modulus, versor->_s0);
|
||||
|
||||
rotation->axis.x1 = versor->_x1 * multiplier;
|
||||
rotation->axis.x2 = versor->_x2 * multiplier;
|
||||
rotation->axis.x3 = versor->_x3 * multiplier;
|
||||
}
|
||||
|
|
@ -1,659 +0,0 @@
|
|||
#ifndef _BGC_VERSOR_H_
|
||||
#define _BGC_VERSOR_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "utilities.h"
|
||||
#include "angle.h"
|
||||
#include "vector3.h"
|
||||
#include "rotation3.h"
|
||||
#include "matrix3x3.h"
|
||||
#include "quaternion.h"
|
||||
|
||||
#define BGC_SOME_TURN 1
|
||||
#define BGC_ZERO_TURN 0
|
||||
#define BGC_OPPOSITE -1
|
||||
|
||||
#define BGC_ERROR_PRIMARY_DIRECTION_UNKNOWN -3001
|
||||
#define BGC_ERROR_PRIMARY_VECTOR_IS_ZERO -3002
|
||||
|
||||
#define BGC_ERROR_AUXILIARY_DIRECTION_UNKNOWN -3011
|
||||
#define BGC_ERROR_AUXILIARY_VECTOR_IS_ZERO -3012
|
||||
|
||||
#define BGC_ERROR_DIRECTIONS_PARALLEL -3021
|
||||
#define BGC_ERROR_VECTORS_PARALLEL -3022
|
||||
|
||||
// =================== Types ==================== //
|
||||
|
||||
typedef struct {
|
||||
float _s0, _x1, _x2, _x3;
|
||||
} BGC_FP32_Versor;
|
||||
|
||||
typedef struct {
|
||||
double _s0, _x1, _x2, _x3;
|
||||
} BGC_FP64_Versor;
|
||||
|
||||
// ================= Constants ================== //
|
||||
|
||||
extern const BGC_FP32_Versor BGC_FP32_IDLE_VERSOR;
|
||||
extern const BGC_FP64_Versor BGC_FP64_IDLE_VERSOR;
|
||||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
inline void bgc_fp32_versor_reset(BGC_FP32_Versor* versor)
|
||||
{
|
||||
versor->_s0 = 1.0f;
|
||||
versor->_x1 = 0.0f;
|
||||
versor->_x2 = 0.0f;
|
||||
versor->_x3 = 0.0f;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_versor_reset(BGC_FP64_Versor* versor)
|
||||
{
|
||||
versor->_s0 = 1.0;
|
||||
versor->_x1 = 0.0;
|
||||
versor->_x2 = 0.0;
|
||||
versor->_x3 = 0.0;
|
||||
}
|
||||
|
||||
// ==================== Set ===================== //
|
||||
|
||||
void _bgc_fp32_versor_normalize(BGC_FP32_Versor* twin);
|
||||
|
||||
void _bgc_fp64_versor_normalize(BGC_FP64_Versor* twin);
|
||||
|
||||
inline void bgc_fp32_versor_make(BGC_FP32_Versor* versor, const float s0, const float x1, const float x2, const float x3)
|
||||
{
|
||||
versor->_s0 = s0;
|
||||
versor->_x1 = x1;
|
||||
versor->_x2 = x2;
|
||||
versor->_x3 = x3;
|
||||
|
||||
const float square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
|
||||
|
||||
if (!bgc_fp32_is_square_unit(square_modulus)) {
|
||||
_bgc_fp32_versor_normalize(versor);
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_fp64_versor_make(BGC_FP64_Versor* versor, const double s0, const double x1, const double x2, const double x3)
|
||||
{
|
||||
versor->_s0 = s0;
|
||||
versor->_x1 = x1;
|
||||
versor->_x2 = x2;
|
||||
versor->_x3 = x3;
|
||||
|
||||
const double square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
|
||||
|
||||
if (!bgc_fp64_is_square_unit(square_modulus)) {
|
||||
_bgc_fp64_versor_normalize(versor);
|
||||
}
|
||||
}
|
||||
|
||||
// ================== Set Turn ================== //
|
||||
|
||||
void bgc_fp32_versor_make_for_turn(BGC_FP32_Versor* versor, const float x1, const float x2, const float x3, const float angle, const int unit);
|
||||
|
||||
void bgc_fp64_versor_make_for_turn(BGC_FP64_Versor* versor, const double x1, const double x2, const double x3, const double angle, const int unit);
|
||||
|
||||
// ================ Set Rotation ================ //
|
||||
|
||||
inline void bgc_fp32_versor_make_for_rotation(BGC_FP32_Versor* versor, const BGC_FP32_Rotation3* rotation)
|
||||
{
|
||||
bgc_fp32_versor_make_for_turn(versor, rotation->axis.x1, rotation->axis.x2, rotation->axis.x3, rotation->radians, BGC_ANGLE_UNIT_RADIANS);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_versor_make_for_rotation(BGC_FP64_Versor* versor, const BGC_FP64_Rotation3* rotation)
|
||||
{
|
||||
bgc_fp64_versor_make_for_turn(versor, rotation->axis.x1, rotation->axis.x2, rotation->axis.x3, rotation->radians, BGC_ANGLE_UNIT_RADIANS);
|
||||
}
|
||||
|
||||
// ========= Make Direction Difference ========== //
|
||||
|
||||
int bgc_fp32_versor_make_direction_difference(BGC_FP32_Versor* difference, const BGC_FP32_Vector3* start, const BGC_FP32_Vector3* end);
|
||||
|
||||
int bgc_fp64_versor_make_direction_difference(BGC_FP64_Versor* difference, const BGC_FP64_Vector3* start, const BGC_FP64_Vector3* end);
|
||||
|
||||
// =============== Set Directions =============== //
|
||||
|
||||
int bgc_fp32_versor_make_basis_difference(
|
||||
BGC_FP32_Versor* versor,
|
||||
const BGC_FP32_Vector3* initial_primary_direction,
|
||||
const BGC_FP32_Vector3* initial_auxiliary_direction,
|
||||
const BGC_FP32_Vector3* final_primary_direction,
|
||||
const BGC_FP32_Vector3* final_auxiliary_direction
|
||||
);
|
||||
|
||||
int bgc_fp64_versor_make_basis_difference(
|
||||
BGC_FP64_Versor* versor,
|
||||
const BGC_FP64_Vector3* initial_primary_direction,
|
||||
const BGC_FP64_Vector3* initial_auxiliary_direction,
|
||||
const BGC_FP64_Vector3* final_primary_direction,
|
||||
const BGC_FP64_Vector3* final_auxiliary_direction
|
||||
);
|
||||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
inline void bgc_fp32_versor_copy(BGC_FP32_Versor* destination, const BGC_FP32_Versor* source)
|
||||
{
|
||||
destination->_s0 = source->_s0;
|
||||
destination->_x1 = source->_x1;
|
||||
destination->_x2 = source->_x2;
|
||||
destination->_x3 = source->_x3;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_versor_copy(BGC_FP64_Versor* destination, const BGC_FP64_Versor* source)
|
||||
{
|
||||
destination->_s0 = source->_s0;
|
||||
destination->_x1 = source->_x1;
|
||||
destination->_x2 = source->_x2;
|
||||
destination->_x3 = source->_x3;
|
||||
}
|
||||
|
||||
// ==================== Swap ==================== //
|
||||
|
||||
inline void bgc_fp32_versor_swap(BGC_FP32_Versor* versor1, BGC_FP32_Versor* versor2)
|
||||
{
|
||||
const float s0 = versor1->_s0;
|
||||
const float x1 = versor1->_x1;
|
||||
const float x2 = versor1->_x2;
|
||||
const float x3 = versor1->_x3;
|
||||
|
||||
versor1->_s0 = versor2->_s0;
|
||||
versor1->_x1 = versor2->_x1;
|
||||
versor1->_x2 = versor2->_x2;
|
||||
versor1->_x3 = versor2->_x3;
|
||||
|
||||
versor2->_s0 = s0;
|
||||
versor2->_x1 = x1;
|
||||
versor2->_x2 = x2;
|
||||
versor2->_x3 = x3;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_versor_swap(BGC_FP64_Versor* versor1, BGC_FP64_Versor* versor2)
|
||||
{
|
||||
const double s0 = versor1->_s0;
|
||||
const double x1 = versor1->_x1;
|
||||
const double x2 = versor1->_x2;
|
||||
const double x3 = versor1->_x3;
|
||||
|
||||
versor1->_s0 = versor2->_s0;
|
||||
versor1->_x1 = versor2->_x1;
|
||||
versor1->_x2 = versor2->_x2;
|
||||
versor1->_x3 = versor2->_x3;
|
||||
|
||||
versor2->_s0 = s0;
|
||||
versor2->_x1 = x1;
|
||||
versor2->_x2 = x2;
|
||||
versor2->_x3 = x3;
|
||||
}
|
||||
|
||||
// ================= Comparison ================= //
|
||||
|
||||
inline int bgc_fp32_versor_is_idle(const BGC_FP32_Versor* versor)
|
||||
{
|
||||
return versor->_x1 * versor->_x1 + versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3 <= BGC_FP32_SQUARE_EPSILON;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_versor_is_idle(const BGC_FP64_Versor* versor)
|
||||
{
|
||||
return versor->_x1 * versor->_x1 + versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3 <= BGC_FP64_SQUARE_EPSILON;
|
||||
}
|
||||
|
||||
// ================== Convert =================== //
|
||||
|
||||
inline void bgc_fp32_versor_convert_to_fp64(BGC_FP64_Versor* destination, const BGC_FP32_Versor* source)
|
||||
{
|
||||
bgc_fp64_versor_make(
|
||||
destination,
|
||||
source->_s0,
|
||||
source->_x1,
|
||||
source->_x2,
|
||||
source->_x3
|
||||
);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_versor_convert_to_fp32(BGC_FP32_Versor* destination, const BGC_FP64_Versor* source)
|
||||
{
|
||||
bgc_fp32_versor_make(
|
||||
destination,
|
||||
(float)source->_s0,
|
||||
(float)source->_x1,
|
||||
(float)source->_x2,
|
||||
(float)source->_x3
|
||||
);
|
||||
}
|
||||
|
||||
// ================== Shorten =================== //
|
||||
|
||||
inline void bgc_fp32_versor_shorten(BGC_FP32_Versor* versor)
|
||||
{
|
||||
if (versor->_s0 < 0.0f) {
|
||||
versor->_s0 = -versor->_s0;
|
||||
versor->_x1 = -versor->_x1;
|
||||
versor->_x2 = -versor->_x2;
|
||||
versor->_x3 = -versor->_x3;
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_fp64_versor_shorten(BGC_FP64_Versor* versor)
|
||||
{
|
||||
if (versor->_s0 < 0.0) {
|
||||
versor->_s0 = -versor->_s0;
|
||||
versor->_x1 = -versor->_x1;
|
||||
versor->_x2 = -versor->_x2;
|
||||
versor->_x3 = -versor->_x3;
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_fp32_versor_get_shortened(BGC_FP32_Versor* shortened, const BGC_FP32_Versor* versor)
|
||||
{
|
||||
if (versor->_s0 >= 0.0f) {
|
||||
shortened->_s0 = versor->_s0;
|
||||
shortened->_x1 = versor->_x1;
|
||||
shortened->_x2 = versor->_x2;
|
||||
shortened->_x3 = versor->_x3;
|
||||
return;
|
||||
}
|
||||
|
||||
shortened->_s0 = -versor->_s0;
|
||||
shortened->_x1 = -versor->_x1;
|
||||
shortened->_x2 = -versor->_x2;
|
||||
shortened->_x3 = -versor->_x3;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_versor_get_shortened(BGC_FP64_Versor* shortened, const BGC_FP64_Versor* versor)
|
||||
{
|
||||
if (versor->_s0 >= 0.0) {
|
||||
shortened->_s0 = versor->_s0;
|
||||
shortened->_x1 = versor->_x1;
|
||||
shortened->_x2 = versor->_x2;
|
||||
shortened->_x3 = versor->_x3;
|
||||
return;
|
||||
}
|
||||
|
||||
shortened->_s0 = -versor->_s0;
|
||||
shortened->_x1 = -versor->_x1;
|
||||
shortened->_x2 = -versor->_x2;
|
||||
shortened->_x3 = -versor->_x3;
|
||||
}
|
||||
|
||||
// ================== Negative ================== //
|
||||
|
||||
inline void bgc_fp32_versor_alternate(BGC_FP32_Versor* versor)
|
||||
{
|
||||
versor->_s0 = -versor->_s0;
|
||||
versor->_x1 = -versor->_x1;
|
||||
versor->_x2 = -versor->_x2;
|
||||
versor->_x3 = -versor->_x3;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_versor_alternate(BGC_FP64_Versor* versor)
|
||||
{
|
||||
versor->_s0 = -versor->_s0;
|
||||
versor->_x1 = -versor->_x1;
|
||||
versor->_x2 = -versor->_x2;
|
||||
versor->_x3 = -versor->_x3;
|
||||
}
|
||||
|
||||
inline void bgc_fp32_versor_get_alternative(BGC_FP32_Versor* alternative, const BGC_FP32_Versor* versor)
|
||||
{
|
||||
alternative->_s0 = -versor->_s0;
|
||||
alternative->_x1 = -versor->_x1;
|
||||
alternative->_x2 = -versor->_x2;
|
||||
alternative->_x3 = -versor->_x3;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_versor_get_alternative(BGC_FP64_Versor* alternative, const BGC_FP64_Versor* versor)
|
||||
{
|
||||
alternative->_s0 = -versor->_s0;
|
||||
alternative->_x1 = -versor->_x1;
|
||||
alternative->_x2 = -versor->_x2;
|
||||
alternative->_x3 = -versor->_x3;
|
||||
}
|
||||
|
||||
// =================== Invert =================== //
|
||||
|
||||
inline void bgc_fp32_versor_revert(BGC_FP32_Versor* versor)
|
||||
{
|
||||
versor->_x1 = -versor->_x1;
|
||||
versor->_x2 = -versor->_x2;
|
||||
versor->_x3 = -versor->_x3;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_versor_revert(BGC_FP64_Versor* versor)
|
||||
{
|
||||
versor->_x1 = -versor->_x1;
|
||||
versor->_x2 = -versor->_x2;
|
||||
versor->_x3 = -versor->_x3;
|
||||
}
|
||||
|
||||
inline void bgc_fp32_versor_get_reverse(BGC_FP32_Versor* inverse, const BGC_FP32_Versor* versor)
|
||||
{
|
||||
inverse->_s0 = versor->_s0;
|
||||
inverse->_x1 = -versor->_x1;
|
||||
inverse->_x2 = -versor->_x2;
|
||||
inverse->_x3 = -versor->_x3;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_versor_get_reverse(BGC_FP64_Versor* inverse, const BGC_FP64_Versor* versor)
|
||||
{
|
||||
inverse->_s0 = versor->_s0;
|
||||
inverse->_x1 = -versor->_x1;
|
||||
inverse->_x2 = -versor->_x2;
|
||||
inverse->_x3 = -versor->_x3;
|
||||
}
|
||||
|
||||
// =============== Get Exponation =============== //
|
||||
|
||||
void bgc_fp32_versor_get_exponation(BGC_FP32_Versor* power, const BGC_FP32_Versor* base, const float exponent);
|
||||
|
||||
void bgc_fp64_versor_get_exponation(BGC_FP64_Versor* power, const BGC_FP64_Versor* base, const double exponent);
|
||||
|
||||
// ================ Combination ================= //
|
||||
|
||||
inline void bgc_fp32_versor_combine(BGC_FP32_Versor* combination, const BGC_FP32_Versor* first, const BGC_FP32_Versor* second)
|
||||
{
|
||||
bgc_fp32_versor_make(
|
||||
combination,
|
||||
(second->_s0 * first->_s0 - second->_x1 * first->_x1) - (second->_x2 * first->_x2 + second->_x3 * first->_x3),
|
||||
(second->_x1 * first->_s0 + second->_s0 * first->_x1) - (second->_x3 * first->_x2 - second->_x2 * first->_x3),
|
||||
(second->_x2 * first->_s0 + second->_s0 * first->_x2) - (second->_x1 * first->_x3 - second->_x3 * first->_x1),
|
||||
(second->_x3 * first->_s0 + second->_s0 * first->_x3) - (second->_x2 * first->_x1 - second->_x1 * first->_x2)
|
||||
);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_versor_combine(BGC_FP64_Versor* combination, const BGC_FP64_Versor* first, const BGC_FP64_Versor* second)
|
||||
{
|
||||
bgc_fp64_versor_make(
|
||||
combination,
|
||||
(second->_s0 * first->_s0 - second->_x1 * first->_x1) - (second->_x2 * first->_x2 + second->_x3 * first->_x3),
|
||||
(second->_x1 * first->_s0 + second->_s0 * first->_x1) - (second->_x3 * first->_x2 - second->_x2 * first->_x3),
|
||||
(second->_x2 * first->_s0 + second->_s0 * first->_x2) - (second->_x1 * first->_x3 - second->_x3 * first->_x1),
|
||||
(second->_x3 * first->_s0 + second->_s0 * first->_x3) - (second->_x2 * first->_x1 - second->_x1 * first->_x2)
|
||||
);
|
||||
}
|
||||
|
||||
// ============ Combination of three ============ //
|
||||
|
||||
inline void bgc_fp32_versor_combine3(BGC_FP32_Versor* combination, const BGC_FP32_Versor* first, const BGC_FP32_Versor* second, const BGC_FP32_Versor* third)
|
||||
{
|
||||
const float s0 = (second->_s0 * first->_s0 - second->_x1 * first->_x1) - (second->_x2 * first->_x2 + second->_x3 * first->_x3);
|
||||
const float x1 = (second->_x1 * first->_s0 + second->_s0 * first->_x1) - (second->_x3 * first->_x2 - second->_x2 * first->_x3);
|
||||
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);
|
||||
|
||||
bgc_fp32_versor_make(
|
||||
combination,
|
||||
(third->_s0 * s0 - third->_x1 * x1) - (third->_x2 * x2 + third->_x3 * x3),
|
||||
(third->_x1 * s0 + third->_s0 * x1) - (third->_x3 * x2 - third->_x2 * x3),
|
||||
(third->_x2 * s0 + third->_s0 * x2) - (third->_x1 * x3 - third->_x3 * x1),
|
||||
(third->_x3 * s0 + third->_s0 * x3) - (third->_x2 * x1 - third->_x1 * x2)
|
||||
);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_versor_combine3(BGC_FP64_Versor* combination, const BGC_FP64_Versor* first, const BGC_FP64_Versor* second, const BGC_FP64_Versor* third)
|
||||
{
|
||||
const double s0 = (second->_s0 * first->_s0 - second->_x1 * first->_x1) - (second->_x2 * first->_x2 + second->_x3 * first->_x3);
|
||||
const double x1 = (second->_x1 * first->_s0 + second->_s0 * first->_x1) - (second->_x3 * first->_x2 - second->_x2 * first->_x3);
|
||||
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);
|
||||
|
||||
bgc_fp64_versor_make(
|
||||
combination,
|
||||
(third->_s0 * s0 - third->_x1 * x1) - (third->_x2 * x2 + third->_x3 * x3),
|
||||
(third->_x1 * s0 + third->_s0 * x1) - (third->_x3 * x2 - third->_x2 * x3),
|
||||
(third->_x2 * s0 + third->_s0 * x2) - (third->_x1 * x3 - third->_x3 * x1),
|
||||
(third->_x3 * s0 + third->_s0 * x3) - (third->_x2 * x1 - third->_x1 * x2)
|
||||
);
|
||||
}
|
||||
|
||||
// ================= Exclusion ================== //
|
||||
|
||||
inline void bgc_fp32_versor_exclude(BGC_FP32_Versor* difference, const BGC_FP32_Versor* base, const BGC_FP32_Versor* excludant)
|
||||
{
|
||||
bgc_fp32_versor_make(
|
||||
difference,
|
||||
(base->_s0 * excludant->_s0 + base->_x1 * excludant->_x1) + (base->_x2 * excludant->_x2 + base->_x3 * excludant->_x3),
|
||||
(base->_x1 * excludant->_s0 + base->_x3 * excludant->_x2) - (base->_s0 * excludant->_x1 + base->_x2 * excludant->_x3),
|
||||
(base->_x2 * excludant->_s0 + base->_x1 * excludant->_x3) - (base->_s0 * excludant->_x2 + base->_x3 * excludant->_x1),
|
||||
(base->_x3 * excludant->_s0 + base->_x2 * excludant->_x1) - (base->_s0 * excludant->_x3 + base->_x1 * excludant->_x2)
|
||||
);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_versor_exclude(BGC_FP64_Versor* difference, const BGC_FP64_Versor* base, const BGC_FP64_Versor* excludant)
|
||||
{
|
||||
bgc_fp64_versor_make(
|
||||
difference,
|
||||
(base->_s0 * excludant->_s0 + base->_x1 * excludant->_x1) + (base->_x2 * excludant->_x2 + base->_x3 * excludant->_x3),
|
||||
(base->_x1 * excludant->_s0 + base->_x3 * excludant->_x2) - (base->_s0 * excludant->_x1 + base->_x2 * excludant->_x3),
|
||||
(base->_x2 * excludant->_s0 + base->_x1 * excludant->_x3) - (base->_s0 * excludant->_x2 + base->_x3 * excludant->_x1),
|
||||
(base->_x3 * excludant->_s0 + base->_x2 * excludant->_x1) - (base->_s0 * excludant->_x3 + base->_x1 * excludant->_x2)
|
||||
);
|
||||
}
|
||||
|
||||
// ============ Sphere Interpolation ============ //
|
||||
|
||||
void bgc_fp32_versor_spherically_interpolate(BGC_FP32_Versor* interpolation, const BGC_FP32_Versor* start, const BGC_FP32_Versor* end, const float phase);
|
||||
|
||||
void bgc_fp64_versor_spherically_interpolate(BGC_FP64_Versor* interpolation, const BGC_FP64_Versor* start, const BGC_FP64_Versor* end, const double phase);
|
||||
|
||||
// ================ Get Rotation ================ //
|
||||
|
||||
void bgc_fp32_versor_get_rotation(BGC_FP32_Rotation3* rotation, const BGC_FP32_Versor* versor);
|
||||
|
||||
void bgc_fp64_versor_get_rotation(BGC_FP64_Rotation3* rotation, const BGC_FP64_Versor* versor);
|
||||
|
||||
// ============ Get Rotation Matrix ============= //
|
||||
|
||||
inline void bgc_fp32_versor_get_rotation_matrix(BGC_FP32_Matrix3x3* matrix, const BGC_FP32_Versor* versor)
|
||||
{
|
||||
const float s0s0 = versor->_s0 * versor->_s0;
|
||||
const float x1x1 = versor->_x1 * versor->_x1;
|
||||
const float x2x2 = versor->_x2 * versor->_x2;
|
||||
const float x3x3 = versor->_x3 * versor->_x3;
|
||||
|
||||
const float s0x1 = versor->_s0 * versor->_x1;
|
||||
const float s0x2 = versor->_s0 * versor->_x2;
|
||||
const float s0x3 = versor->_s0 * versor->_x3;
|
||||
const float x1x2 = versor->_x1 * versor->_x2;
|
||||
const float x1x3 = versor->_x1 * versor->_x3;
|
||||
const float x2x3 = versor->_x2 * versor->_x3;
|
||||
|
||||
matrix->r1c1 = (s0s0 + x1x1) - (x2x2 + x3x3);
|
||||
matrix->r2c2 = (s0s0 + x2x2) - (x1x1 + x3x3);
|
||||
matrix->r3c3 = (s0s0 + x3x3) - (x1x1 + x2x2);
|
||||
|
||||
matrix->r1c2 = 2.0f * (x1x2 - s0x3);
|
||||
matrix->r2c3 = 2.0f * (x2x3 - s0x1);
|
||||
matrix->r3c1 = 2.0f * (x1x3 - s0x2);
|
||||
|
||||
matrix->r2c1 = 2.0f * (x1x2 + s0x3);
|
||||
matrix->r3c2 = 2.0f * (x2x3 + s0x1);
|
||||
matrix->r1c3 = 2.0f * (x1x3 + s0x2);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_versor_get_rotation_matrix(BGC_FP64_Matrix3x3* matrix, const BGC_FP64_Versor* versor)
|
||||
{
|
||||
const double s0s0 = versor->_s0 * versor->_s0;
|
||||
const double x1x1 = versor->_x1 * versor->_x1;
|
||||
const double x2x2 = versor->_x2 * versor->_x2;
|
||||
const double x3x3 = versor->_x3 * versor->_x3;
|
||||
|
||||
const double s0x1 = versor->_s0 * versor->_x1;
|
||||
const double s0x2 = versor->_s0 * versor->_x2;
|
||||
const double s0x3 = versor->_s0 * versor->_x3;
|
||||
const double x1x2 = versor->_x1 * versor->_x2;
|
||||
const double x1x3 = versor->_x1 * versor->_x3;
|
||||
const double x2x3 = versor->_x2 * versor->_x3;
|
||||
|
||||
matrix->r1c1 = (s0s0 + x1x1) - (x2x2 + x3x3);
|
||||
matrix->r2c2 = (s0s0 + x2x2) - (x1x1 + x3x3);
|
||||
matrix->r3c3 = (s0s0 + x3x3) - (x1x1 + x2x2);
|
||||
|
||||
matrix->r1c2 = 2.0 * (x1x2 - s0x3);
|
||||
matrix->r2c3 = 2.0 * (x2x3 - s0x1);
|
||||
matrix->r3c1 = 2.0 * (x1x3 - s0x2);
|
||||
|
||||
matrix->r2c1 = 2.0 * (x1x2 + s0x3);
|
||||
matrix->r3c2 = 2.0 * (x2x3 + s0x1);
|
||||
matrix->r1c3 = 2.0 * (x1x3 + s0x2);
|
||||
}
|
||||
|
||||
// ============= Get Reverse Matrix ============= //
|
||||
|
||||
inline void bgc_fp32_versor_get_reverse_matrix(BGC_FP32_Matrix3x3* matrix, const BGC_FP32_Versor* versor)
|
||||
{
|
||||
const float s0s0 = versor->_s0 * versor->_s0;
|
||||
const float x1x1 = versor->_x1 * versor->_x1;
|
||||
const float x2x2 = versor->_x2 * versor->_x2;
|
||||
const float x3x3 = versor->_x3 * versor->_x3;
|
||||
|
||||
const float s0x1 = versor->_s0 * versor->_x1;
|
||||
const float s0x2 = versor->_s0 * versor->_x2;
|
||||
const float s0x3 = versor->_s0 * versor->_x3;
|
||||
const float x1x2 = versor->_x1 * versor->_x2;
|
||||
const float x1x3 = versor->_x1 * versor->_x3;
|
||||
const float x2x3 = versor->_x2 * versor->_x3;
|
||||
|
||||
matrix->r1c1 = (s0s0 + x1x1) - (x2x2 + x3x3);
|
||||
matrix->r2c2 = (s0s0 + x2x2) - (x1x1 + x3x3);
|
||||
matrix->r3c3 = (s0s0 + x3x3) - (x1x1 + x2x2);
|
||||
|
||||
matrix->r1c2 = 2.0f * (x1x2 + s0x3);
|
||||
matrix->r2c3 = 2.0f * (x2x3 + s0x1);
|
||||
matrix->r3c1 = 2.0f * (x1x3 + s0x2);
|
||||
|
||||
matrix->r2c1 = 2.0f * (x1x2 - s0x3);
|
||||
matrix->r3c2 = 2.0f * (x2x3 - s0x1);
|
||||
matrix->r1c3 = 2.0f * (x1x3 - s0x2);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_versor_get_reverse_matrix(BGC_FP64_Matrix3x3* matrix, const BGC_FP64_Versor* versor)
|
||||
{
|
||||
const double s0s0 = versor->_s0 * versor->_s0;
|
||||
const double x1x1 = versor->_x1 * versor->_x1;
|
||||
const double x2x2 = versor->_x2 * versor->_x2;
|
||||
const double x3x3 = versor->_x3 * versor->_x3;
|
||||
|
||||
const double s0x1 = versor->_s0 * versor->_x1;
|
||||
const double s0x2 = versor->_s0 * versor->_x2;
|
||||
const double s0x3 = versor->_s0 * versor->_x3;
|
||||
const double x1x2 = versor->_x1 * versor->_x2;
|
||||
const double x1x3 = versor->_x1 * versor->_x3;
|
||||
const double x2x3 = versor->_x2 * versor->_x3;
|
||||
|
||||
matrix->r1c1 = (s0s0 + x1x1) - (x2x2 + x3x3);
|
||||
matrix->r2c2 = (s0s0 + x2x2) - (x1x1 + x3x3);
|
||||
matrix->r3c3 = (s0s0 + x3x3) - (x1x1 + x2x2);
|
||||
|
||||
matrix->r1c2 = 2.0 * (x1x2 + s0x3);
|
||||
matrix->r2c3 = 2.0 * (x2x3 + s0x1);
|
||||
matrix->r3c1 = 2.0 * (x1x3 + s0x2);
|
||||
|
||||
matrix->r2c1 = 2.0 * (x1x2 - s0x3);
|
||||
matrix->r3c2 = 2.0 * (x2x3 - s0x1);
|
||||
matrix->r1c3 = 2.0 * (x1x3 - s0x2);
|
||||
}
|
||||
|
||||
// ============= Get Both Matrixes ============== //
|
||||
|
||||
inline void bgc_fp32_versor_get_both_matrices(BGC_FP32_Matrix3x3* rotation, BGC_FP32_Matrix3x3* reverse, const BGC_FP32_Versor* versor)
|
||||
{
|
||||
bgc_fp32_versor_get_reverse_matrix(reverse, versor);
|
||||
bgc_fp32_matrix3x3_get_transposed(rotation, reverse);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_versor_get_both_matrices(BGC_FP64_Matrix3x3* rotation, BGC_FP64_Matrix3x3* reverse, const BGC_FP64_Versor* versor)
|
||||
{
|
||||
bgc_fp64_versor_get_reverse_matrix(reverse, versor);
|
||||
bgc_fp64_matrix3x3_get_transposed(rotation, reverse);
|
||||
}
|
||||
|
||||
// ================ Turn Vector ================= //
|
||||
|
||||
inline void bgc_fp32_versor_turn_vector(BGC_FP32_Vector3* turned_vector, const BGC_FP32_Versor* versor, const BGC_FP32_Vector3* vector)
|
||||
{
|
||||
const float tx1 = 2.0f * (versor->_x2 * vector->x3 - versor->_x3 * vector->x2);
|
||||
const float tx2 = 2.0f * (versor->_x3 * vector->x1 - versor->_x1 * vector->x3);
|
||||
const float tx3 = 2.0f * (versor->_x1 * vector->x2 - versor->_x2 * vector->x1);
|
||||
|
||||
const float x1 = (vector->x1 + tx1 * versor->_s0) + (versor->_x2 * tx3 - versor->_x3 * tx2);
|
||||
const float x2 = (vector->x2 + tx2 * versor->_s0) + (versor->_x3 * tx1 - versor->_x1 * tx3);
|
||||
const float x3 = (vector->x3 + tx3 * versor->_s0) + (versor->_x1 * tx2 - versor->_x2 * tx1);
|
||||
|
||||
turned_vector->x1 = x1;
|
||||
turned_vector->x2 = x2;
|
||||
turned_vector->x3 = x3;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_versor_turn_vector(BGC_FP64_Vector3* turned_vector, const BGC_FP64_Versor* versor, const BGC_FP64_Vector3* vector)
|
||||
{
|
||||
const double tx1 = 2.0 * (versor->_x2 * vector->x3 - versor->_x3 * vector->x2);
|
||||
const double tx2 = 2.0 * (versor->_x3 * vector->x1 - versor->_x1 * vector->x3);
|
||||
const double tx3 = 2.0 * (versor->_x1 * vector->x2 - versor->_x2 * vector->x1);
|
||||
|
||||
const double x1 = (vector->x1 + tx1 * versor->_s0) + (versor->_x2 * tx3 - versor->_x3 * tx2);
|
||||
const double x2 = (vector->x2 + tx2 * versor->_s0) + (versor->_x3 * tx1 - versor->_x1 * tx3);
|
||||
const double x3 = (vector->x3 + tx3 * versor->_s0) + (versor->_x1 * tx2 - versor->_x2 * tx1);
|
||||
|
||||
turned_vector->x1 = x1;
|
||||
turned_vector->x2 = x2;
|
||||
turned_vector->x3 = x3;
|
||||
}
|
||||
|
||||
// ============== Turn Vector Back ============== //
|
||||
|
||||
inline void bgc_fp32_versor_turn_vector_back(BGC_FP32_Vector3* turned_vector, const BGC_FP32_Versor* versor, const BGC_FP32_Vector3* vector)
|
||||
{
|
||||
const float tx1 = 2.0f * (versor->_x2 * vector->x3 - versor->_x3 * vector->x2);
|
||||
const float tx2 = 2.0f * (versor->_x3 * vector->x1 - versor->_x1 * vector->x3);
|
||||
const float tx3 = 2.0f * (versor->_x1 * vector->x2 - versor->_x2 * vector->x1);
|
||||
|
||||
const float x1 = (vector->x1 - tx1 * versor->_s0) + (versor->_x2 * tx3 - versor->_x3 * tx2);
|
||||
const float x2 = (vector->x2 - tx2 * versor->_s0) + (versor->_x3 * tx1 - versor->_x1 * tx3);
|
||||
const float x3 = (vector->x3 - tx3 * versor->_s0) + (versor->_x1 * tx2 - versor->_x2 * tx1);
|
||||
|
||||
turned_vector->x1 = x1;
|
||||
turned_vector->x2 = x2;
|
||||
turned_vector->x3 = x3;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_versor_turn_vector_back(BGC_FP64_Vector3* turned_vector, const BGC_FP64_Versor* versor, const BGC_FP64_Vector3* vector)
|
||||
{
|
||||
const double tx1 = 2.0 * (versor->_x2 * vector->x3 - versor->_x3 * vector->x2);
|
||||
const double tx2 = 2.0 * (versor->_x3 * vector->x1 - versor->_x1 * vector->x3);
|
||||
const double tx3 = 2.0 * (versor->_x1 * vector->x2 - versor->_x2 * vector->x1);
|
||||
|
||||
const double x1 = (vector->x1 - tx1 * versor->_s0) + (versor->_x2 * tx3 - versor->_x3 * tx2);
|
||||
const double x2 = (vector->x2 - tx2 * versor->_s0) + (versor->_x3 * tx1 - versor->_x1 * tx3);
|
||||
const double x3 = (vector->x3 - tx3 * versor->_s0) + (versor->_x1 * tx2 - versor->_x2 * tx1);
|
||||
|
||||
turned_vector->x1 = x1;
|
||||
turned_vector->x2 = x2;
|
||||
turned_vector->x3 = x3;
|
||||
}
|
||||
|
||||
// ================== Are Close ================= //
|
||||
|
||||
inline int bgc_fp32_versor_are_close(const BGC_FP32_Versor* versor1, const BGC_FP32_Versor* versor2)
|
||||
{
|
||||
const float ds0 = versor1->_s0 - versor2->_s0;
|
||||
const float dx1 = versor1->_x1 - versor2->_x1;
|
||||
const float dx2 = versor1->_x2 - versor2->_x2;
|
||||
const float dx3 = versor1->_x3 - versor2->_x3;
|
||||
|
||||
return (ds0 * ds0 + dx1 * dx1) + (dx2 * dx2 + dx3 * dx3) <= BGC_FP32_SQUARE_EPSILON;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_versor_are_close(const BGC_FP64_Versor* versor1, const BGC_FP64_Versor* versor2)
|
||||
{
|
||||
const double ds0 = versor1->_s0 - versor2->_s0;
|
||||
const double dx1 = versor1->_x1 - versor2->_x1;
|
||||
const double dx2 = versor1->_x2 - versor2->_x2;
|
||||
const double dx3 = versor1->_x3 - versor2->_x3;
|
||||
|
||||
return (ds0 * ds0 + dx1 * dx1) + (dx2 * dx2 + dx3 * dx3) <= BGC_FP64_SQUARE_EPSILON;
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue