Приаведение тангенса (tangent) к единому виду с другими сущностями, добавлено комплексное произведение двумерных векторов
This commit is contained in:
parent
896c8615f5
commit
fcbec62024
5 changed files with 182 additions and 114 deletions
|
|
@ -93,7 +93,7 @@ BgFP32Versor * make_random_versors(const unsigned int amount)
|
|||
|
||||
void print_versor(const BgFP32Versor* versor)
|
||||
{
|
||||
printf("Versor (%f, %f, %f, %f); Delta = %e\n", versor->s0, versor->x1, versor->x2, versor->x3, bg_fp32_versor_get_modulus(versor) - 1.0f);
|
||||
printf("Versor (%f, %f, %f, %f)\n", versor->s0, versor->x1, versor->x2, versor->x3);
|
||||
}
|
||||
|
||||
void print_vector(const BgFP32Vector3* vector)
|
||||
|
|
|
|||
|
|
@ -74,6 +74,10 @@
|
|||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="rotation3.h" />
|
||||
<Unit filename="tangent.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="tangent.h" />
|
||||
<Unit filename="vector2.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
|
|
|
|||
|
|
@ -8,16 +8,30 @@
|
|||
#include "vector2.h"
|
||||
#include "matrix2x2.h"
|
||||
|
||||
// =================== Types ==================== //
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float _cos, _sin;
|
||||
const float cos, sin;
|
||||
} BgFP32Tangent;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double _cos, _sin;
|
||||
const double cos, sin;
|
||||
} BgFP64Tangent;
|
||||
|
||||
// ================= Dark Twins ================= //
|
||||
|
||||
typedef struct {
|
||||
float cos, sin;
|
||||
} __BgFP32DarkTwinTangent;
|
||||
|
||||
typedef struct {
|
||||
double cos, sin;
|
||||
} __BgFP64DarkTwinTangent;
|
||||
|
||||
// ================= Constants ================== //
|
||||
|
||||
extern const BgFP32Tangent BG_FP32_IDLE_TANGENT;
|
||||
extern const BgFP64Tangent BG_FP64_IDLE_TANGENT;
|
||||
|
||||
|
|
@ -25,212 +39,266 @@ extern const BgFP64Tangent BG_FP64_IDLE_TANGENT;
|
|||
|
||||
static inline void bg_fp32_tangent_reset(BgFP32Tangent* tangent)
|
||||
{
|
||||
tangent->_cos = 1.0f;
|
||||
tangent->_sin = 0.0f;
|
||||
__BgFP32DarkTwinTangent* twin = (__BgFP32DarkTwinTangent*)tangent;
|
||||
|
||||
twin->cos = 1.0f;
|
||||
twin->sin = 0.0f;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_tangent_reset(BgFP64Tangent* tangent)
|
||||
{
|
||||
tangent->_cos = 1.0;
|
||||
tangent->_sin = 0.0;
|
||||
__BgFP64DarkTwinTangent* twin = (__BgFP64DarkTwinTangent*)tangent;
|
||||
|
||||
twin->cos = 1.0;
|
||||
twin->sin = 0.0;
|
||||
}
|
||||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
static inline void bg_fp32_tangent_copy(const BgFP32Tangent* from, BgFP32Tangent* to)
|
||||
{
|
||||
to->_cos = from->_cos;
|
||||
to->_sin = from->_sin;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_tangent_copy(const BgFP64Tangent* from, BgFP64Tangent* to)
|
||||
{
|
||||
to->_cos = from->_cos;
|
||||
to->_sin = from->_sin;
|
||||
}
|
||||
|
||||
// ==================== Make ==================== //
|
||||
// ==================== Set ===================== //
|
||||
|
||||
static inline void bg_fp32_tangent_set_values(const float x1, const float x2, BgFP32Tangent* tangent)
|
||||
{
|
||||
const float square_module = x1 * x1 + x2 * x2;
|
||||
|
||||
tangent->_cos = x1;
|
||||
tangent->_sin = x2;
|
||||
__BgFP32DarkTwinTangent* twin = (__BgFP32DarkTwinTangent*)tangent;
|
||||
|
||||
twin->cos = x1;
|
||||
twin->sin = x2;
|
||||
|
||||
if (1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (square_module <= BG_FP32_SQUARE_EPSYLON) {
|
||||
tangent->_cos = 1.0f;
|
||||
tangent->_sin = 0.0f;
|
||||
twin->cos = 1.0f;
|
||||
twin->sin = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
const float multiplier = sqrtf(1.0f / square_module);
|
||||
|
||||
tangent->_cos = x1 * multiplier;
|
||||
tangent->_sin = x2 * multiplier;
|
||||
twin->cos = x1 * multiplier;
|
||||
twin->sin = x2 * multiplier;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_tangent_set_values(const double x1, const double x2, BgFP64Tangent* tangent)
|
||||
{
|
||||
const double square_module = x1 * x1 + x2 * x2;
|
||||
|
||||
tangent->_cos = x1;
|
||||
tangent->_sin = x2;
|
||||
__BgFP64DarkTwinTangent* twin = (__BgFP64DarkTwinTangent*)tangent;
|
||||
|
||||
twin->cos = x1;
|
||||
twin->sin = x2;
|
||||
|
||||
if (1.0 - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (square_module <= BG_FP64_SQUARE_EPSYLON) {
|
||||
tangent->_cos = 1.0;
|
||||
tangent->_sin = 0.0;
|
||||
twin->cos = 1.0;
|
||||