Развитие дуальный чисел, векторов и кватернионов, а также гомогенных векторов и матриц
This commit is contained in:
parent
3f96b661a9
commit
b87518cd3f
21 changed files with 1787 additions and 1511 deletions
|
|
@ -8,13 +8,13 @@
|
|||
// Homogeneous 3D Vector
|
||||
typedef struct
|
||||
{
|
||||
float x1, x2, x3, ratio;
|
||||
float x1, x2, x3, d0;
|
||||
} BGC_FP32_HgVector3;
|
||||
|
||||
// Homogeneous 3D Vector
|
||||
typedef struct
|
||||
{
|
||||
double x1, x2, x3, ratio;
|
||||
double x1, x2, x3, d0;
|
||||
} BGC_FP64_HgVector3;
|
||||
|
||||
// ================ Reset Point ================= //
|
||||
|
|
@ -24,7 +24,7 @@ inline void bgc_fp32_hg_vector3_reset_point(BGC_FP32_HgVector3* homogeneous_vect
|
|||
homogeneous_vector->x1 = 0.0f;
|
||||
homogeneous_vector->x2 = 0.0f;
|
||||
homogeneous_vector->x3 = 0.0f;
|
||||
homogeneous_vector->ratio = 1.0f;
|
||||
homogeneous_vector->d0 = 1.0f;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_hg_vector3_reset_point(BGC_FP64_HgVector3* homogeneous_vector)
|
||||
|
|
@ -32,7 +32,7 @@ inline void bgc_fp64_hg_vector3_reset_point(BGC_FP64_HgVector3* homogeneous_vect
|
|||
homogeneous_vector->x1 = 0.0;
|
||||
homogeneous_vector->x2 = 0.0;
|
||||
homogeneous_vector->x3 = 0.0;
|
||||
homogeneous_vector->ratio = 1.0;
|
||||
homogeneous_vector->d0 = 1.0;
|
||||
}
|
||||
|
||||
// ================ Reset Point ================= //
|
||||
|
|
@ -42,7 +42,7 @@ inline void bgc_fp32_hg_vector3_reset_vector(BGC_FP32_HgVector3* homogeneous_vec
|
|||
homogeneous_vector->x1 = 0.0f;
|
||||
homogeneous_vector->x2 = 0.0f;
|
||||
homogeneous_vector->x3 = 0.0f;
|
||||
homogeneous_vector->ratio = 0.0f;
|
||||
homogeneous_vector->d0 = 0.0f;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_hg_vector3_reset_vector(BGC_FP64_HgVector3* homogeneous_vector)
|
||||
|
|
@ -50,25 +50,25 @@ inline void bgc_fp64_hg_vector3_reset_vector(BGC_FP64_HgVector3* homogeneous_vec
|
|||
homogeneous_vector->x1 = 0.0;
|
||||
homogeneous_vector->x2 = 0.0;
|
||||
homogeneous_vector->x3 = 0.0;
|
||||
homogeneous_vector->ratio = 0.0;
|
||||
homogeneous_vector->d0 = 0.0;
|
||||
}
|
||||
|
||||
// ==================== Make ==================== //
|
||||
|
||||
inline void bgc_fp32_hg_vector3_make(BGC_FP32_HgVector3* homogeneous_vector, const float x1, const float x2, const float x3, const float ratio)
|
||||
inline void bgc_fp32_hg_vector3_make(BGC_FP32_HgVector3* homogeneous_vector, const float x1, const float x2, const float x3, const float d0)
|
||||
{
|
||||
homogeneous_vector->x1 = x1;
|
||||
homogeneous_vector->x2 = x2;
|
||||
homogeneous_vector->x3 = x3;
|
||||
homogeneous_vector->ratio = ratio;
|
||||
homogeneous_vector->d0 = d0;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_hg_vector3_make(BGC_FP64_HgVector3* homogeneous_vector, const double x1, const double x2, const double x3, const double ratio)
|
||||
inline void bgc_fp64_hg_vector3_make(BGC_FP64_HgVector3* homogeneous_vector, const double x1, const double x2, const double x3, const double d0)
|
||||
{
|
||||
homogeneous_vector->x1 = x1;
|
||||
homogeneous_vector->x2 = x2;
|
||||
homogeneous_vector->x3 = x3;
|
||||
homogeneous_vector->ratio = ratio;
|
||||
homogeneous_vector->d0 = d0;
|
||||
}
|
||||
|
||||
// ================= Make Point ================= //
|
||||
|
|
@ -78,7 +78,7 @@ inline void bgc_fp32_hg_vector3_make_point(BGC_FP32_HgVector3* homogeneous_vecto
|
|||
homogeneous_vector->x1 = regular_vector->x1;
|
||||
homogeneous_vector->x2 = regular_vector->x2;
|
||||
homogeneous_vector->x3 = regular_vector->x3;
|
||||
homogeneous_vector->ratio = 1.0f;
|
||||
homogeneous_vector->d0 = 1.0f;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_hg_vector3_make_point(BGC_FP64_HgVector3* homogeneous_vector, const BGC_FP64_Vector3* regular_vector)
|
||||
|
|
@ -86,7 +86,7 @@ inline void bgc_fp64_hg_vector3_make_point(BGC_FP64_HgVector3* homogeneous_vecto
|
|||
homogeneous_vector->x1 = regular_vector->x1;
|
||||
homogeneous_vector->x2 = regular_vector->x2;
|
||||
homogeneous_vector->x3 = regular_vector->x3;
|
||||
homogeneous_vector->ratio = 1.0;
|
||||
homogeneous_vector->d0 = 1.0;
|
||||
}
|
||||
|
||||
// ================ Make Vector ================= //
|
||||
|
|
@ -96,7 +96,7 @@ inline void bgc_fp32_hg_vector3_make_vector(BGC_FP32_HgVector3* homogeneous_vect
|
|||
homogeneous_vector->x1 = regular_vector->x1;
|
||||
homogeneous_vector->x2 = regular_vector->x2;
|
||||
homogeneous_vector->x3 = regular_vector->x3;
|
||||
homogeneous_vector->ratio = 0.0f;
|
||||
homogeneous_vector->d0 = 0.0f;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_hg_vector3_make_vector(BGC_FP64_HgVector3* homogeneous_vector, const BGC_FP64_Vector3* regular_vector)
|
||||
|
|
@ -104,31 +104,31 @@ inline void bgc_fp64_hg_vector3_make_vector(BGC_FP64_HgVector3* homogeneous_vect
|
|||
homogeneous_vector->x1 = regular_vector->x1;
|
||||
homogeneous_vector->x2 = regular_vector->x2;
|
||||
homogeneous_vector->x3 = regular_vector->x3;
|
||||
homogeneous_vector->ratio = 0.0;
|
||||
homogeneous_vector->d0 = 0.0;
|
||||
}
|
||||
|
||||
// ================== Is Point ================== //
|
||||
|
||||
inline int bgc_fp32_hg_vector3_is_point(const BGC_FP32_HgVector3* homogeneous_vector)
|
||||
{
|
||||
return !bgc_fp32_is_zero(homogeneous_vector->ratio);
|
||||
return !bgc_fp32_is_zero(homogeneous_vector->d0);
|
||||
}
|
||||
|
||||
inline int bgc_fp64_hg_vector3_is_point(const BGC_FP64_HgVector3* homogeneous_vector)
|
||||
{
|
||||
return !bgc_fp64_is_zero(homogeneous_vector->ratio);
|
||||
return !bgc_fp64_is_zero(homogeneous_vector->d0);
|
||||
}
|
||||
|
||||
// ================= Is Vector ================== //
|
||||
|
||||
inline int bgc_fp32_hg_vector3_is_vector(const BGC_FP32_HgVector3* homogeneous_vector)
|
||||
{
|
||||
return bgc_fp32_is_zero(homogeneous_vector->ratio);
|
||||
return bgc_fp32_is_zero(homogeneous_vector->d0);
|
||||
}
|
||||
|
||||
inline int bgc_fp64_hg_vector3_is_vector(const BGC_FP64_HgVector3* homogeneous_vector)
|
||||
{
|
||||
return bgc_fp64_is_zero(homogeneous_vector->ratio);
|
||||
return bgc_fp64_is_zero(homogeneous_vector->d0);
|
||||
}
|
||||
|
||||
// ==================== Copy ==================== //
|
||||
|
|
@ -138,7 +138,7 @@ inline void bgc_fp32_hg_vector3_copy(BGC_FP32_HgVector3* destination, const BGC_
|
|||
destination->x1 = source->x1;
|
||||
destination->x2 = source->x2;
|
||||
destination->x3 = source->x3;
|
||||
destination->ratio = source->ratio;
|
||||
destination->d0 = source->d0;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_hg_vector3_copy(BGC_FP64_HgVector3* destination, const BGC_FP64_HgVector3* source)
|
||||
|
|
@ -146,7 +146,7 @@ inline void bgc_fp64_hg_vector3_copy(BGC_FP64_HgVector3* destination, const BGC_
|
|||
destination->x1 = source->x1;
|
||||
destination->x2 = source->x2;
|
||||
destination->x3 = source->x3;
|
||||
destination->ratio = source->ratio;
|
||||
destination->d0 = source->d0;
|
||||
}
|
||||
|
||||
// ==================== Swap ==================== //
|
||||
|
|
@ -156,17 +156,17 @@ inline void bgc_fp32_hg_vector3_swap(BGC_FP32_HgVector3* first, BGC_FP32_HgVecto
|
|||
const float x1 = first->x1;
|
||||
const float x2 = first->x2;
|
||||
const float x3 = first->x3;
|
||||
const float ratio = first->ratio;
|
||||
const float d0 = first->d0;
|
||||
|
||||
first->x1 = second->x1;
|
||||
first->x2 = second->x2;
|
||||
first->x3 = second->x3;
|
||||
first->ratio = second->ratio;
|
||||
first->d0 = second->d0;
|
||||
|
||||
second->x1 = x1;
|
||||
second->x2 = x2;
|
||||
second->x3 = x3;
|
||||
second->ratio = ratio;
|
||||
second->d0 = d0;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_hg_vector3_swap(BGC_FP64_HgVector3* first, BGC_FP64_HgVector3* second)
|
||||
|
|
@ -174,17 +174,51 @@ inline void bgc_fp64_hg_vector3_swap(BGC_FP64_HgVector3* first, BGC_FP64_HgVecto
|
|||
const double x1 = first->x1;
|
||||
const double x2 = first->x2;
|
||||
const double x3 = first->x3;
|
||||
const double ratio = first->ratio;
|
||||
const double d0 = first->d0;
|
||||
|
||||
first->x1 = second->x1;
|
||||
first->x2 = second->x2;
|
||||
first->x3 = second->x3;
|
||||
first->ratio = second->ratio;
|
||||
first->d0 = second->d0;
|
||||
|
||||
second->x1 = x1;
|
||||
second->x2 = x2;
|
||||
second->x3 = x3;
|
||||
second->ratio = ratio;
|
||||
second->d0 = d0;
|
||||
}
|
||||
|
||||
// ================== Rescale =================== //
|
||||
|
||||
inline int bgc_fp32_hg_vector3_rescale(BGC_FP32_HgVector3* homogeneous_vector, const float new_ratio)
|
||||
{
|
||||
if (bgc_fp32_is_zero(homogeneous_vector->d0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float multiplier = new_ratio / homogeneous_vector->d0;
|
||||
|
||||
homogeneous_vector->x1 *= multiplier;
|
||||
homogeneous_vector->x2 *= multiplier;
|
||||
homogeneous_vector->x3 *= multiplier;
|
||||
homogeneous_vector->d0 = new_ratio;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_hg_vector3_rescale(BGC_FP64_HgVector3* homogeneous_vector, const double new_ratio)
|
||||
{
|
||||
if (bgc_fp64_is_zero(homogeneous_vector->d0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double multiplier = new_ratio / homogeneous_vector->d0;
|
||||
|
||||
homogeneous_vector->x1 *= multiplier;
|
||||
homogeneous_vector->x2 *= multiplier;
|
||||
homogeneous_vector->x3 *= multiplier;
|
||||
homogeneous_vector->d0 = new_ratio;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue