Добавление тангентов (аналог версоров, но для двумерных пространств) / Adding of tangent pairs, it is like versors but for 2 dimensional spaces

This commit is contained in:
Andrey Pokidov 2024-12-19 00:16:52 +07:00
parent 5fd14e4627
commit 896c8615f5
7 changed files with 316 additions and 5 deletions

View file

@ -234,7 +234,7 @@ int main()
for (int j = 0; j < 1000; j++) {
for (unsigned int i = 0; i < amount; i++) {
bg_fp32_versor_combine(&versors1[i], &versors2[i], &results[i]);
bg_fp32_versor_get_rotation_matrix(&versors1[i], &matrixes[i]);
bg_fp32_versor_make_rotation_matrix(&versors1[i], &matrixes[i]);
bg_fp32_matrix3x3_right_product(&matrixes[i], &vectors[i], &vectors[i]);
//bg_fp32_versor_turn(&results[i], &vectors[i], &vectors[i]);
}

View file

@ -14,6 +14,8 @@
#include "matrix3x2.h"
#include "matrix3x3.h"
#include "tangent.h"
#include "rotation3.h"
#include "quaternion.h"

View file

@ -29,6 +29,7 @@
<ClInclude Include="matrixes.h" />
<ClInclude Include="quaternion.h" />
<ClInclude Include="rotation3.h" />
<ClInclude Include="tangent.h" />
<ClInclude Include="versor.h" />
<ClInclude Include="vector2.h" />
<ClInclude Include="vector3.h" />
@ -43,6 +44,7 @@
<ClCompile Include="matrixes.c" />
<ClCompile Include="quaternion.c" />
<ClCompile Include="rotation3.c" />
<ClCompile Include="tangent.c" />
<ClCompile Include="versor.c" />
<ClCompile Include="vector2.c" />
<ClCompile Include="vector3.c" />

View file

@ -54,6 +54,9 @@
<ClInclude Include="matrixes.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
<ClInclude Include="tangent.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="angle.c">
@ -92,5 +95,8 @@
<ClCompile Include="matrix3x2.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="tangent.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
</ItemGroup>
</Project>

5
basic-geometry/tangent.c Normal file
View file

@ -0,0 +1,5 @@
#include "tangent.h"
const BgFP32Tangent BG_FP32_IDLE_TANGENT = { 1.0f, 0.0f };
const BgFP64Tangent BG_FP64_IDLE_TANGENT = { 1.0, 0.0 };

296
basic-geometry/tangent.h Normal file
View file

Internal server error - Personal Git Server: Beyond coding. We Forge.

500

Internal server error

Forgejo version: 11.0.1+gitea-1.22.0

@ -0,0 +1,296 @@
#ifndef _GEOMETRY_TANGENT_H_
#define _GEOMETRY_TANGENT_H_
#include <math.h>
#include "basis.h"
#include "angle.h"
#include "vector2.h"
#include "matrix2x2.h"
typedef struct
{
float _cos, _sin;
} BgFP32Tangent;
typedef struct
{
double _cos, _sin;
} BgFP64Tangent;
extern const BgFP32Tangent BG_FP32_IDLE_TANGENT;
extern const BgFP64Tangent BG_FP64_IDLE_TANGENT;
// =================== Reset ==================== //
static inline void bg_fp32_tangent_reset(BgFP32Tangent* tangent)
{
tangent->_cos = 1.0f;
tangent->_sin = 0.0f;
}
static inline void bg_fp64_tangent_reset(BgFP64Tangent* tangent)
{
tangent->_cos = 1.0;
tangent->_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 ==================== //
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;
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;
return;
}
const float multiplier = sqrtf(1.0f / square_module);
tangent->_cos = x1 * multiplier;
tangent->_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;
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;
return;
}
const double multiplier = sqrt(1.0 / square_module);
tangent->_cos = x1 * multiplier;
tangent->_sin = x2 * multiplier;
}
// ================== Set Angle ================= //
static inline void bg_fp32_tangent_set_angle(const float angle, const angle_unit_t unit, BgFP32Tangent* tangent)
{