Отказ от терминов Versor и Cotes Number в пользу Turn3 и Turn2, использование кватернионов внутри Turn3
This commit is contained in:
parent
38cff7e27d
commit
b470a3194b
27 changed files with 1815 additions and 2045 deletions
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue