Добавление position3 и aффинного преобразования
This commit is contained in:
parent
fd7c6c91cd
commit
d8347656c7
7 changed files with 375 additions and 0 deletions
140
basic-geometry/position3.h
Normal file
140
basic-geometry/position3.h
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
#ifndef _BGC_POSITION3_H_INCLUDED_
|
||||
#define _BGC_POSITION3_H_INCLUDED_
|
||||
|
||||
#include "vector3.h"
|
||||
#include "affine3.h"
|
||||
#include "versor.h"
|
||||
|
||||
// ==================== Types ==================== //
|
||||
|
||||
typedef struct {
|
||||
BgcVersorFP32 turn;
|
||||
BgcVector3FP32 shift;
|
||||
} BgcPosition3FP32;
|
||||
|
||||
typedef struct {
|
||||
BgcVersorFP64 turn;
|
||||
BgcVector3FP64 shift;
|
||||
} BgcPosition3FP64;
|
||||
|
||||
// ==================== Reset ==================== //
|
||||
|
||||
inline void bgc_position3_reset_fp32(BgcPosition3FP32 * position)
|
||||
{
|
||||
bgc_versor_reset_fp32(&position->turn);
|
||||
bgc_vector3_reset_fp32(&position->shift);
|
||||
}
|
||||
|
||||
inline void bgc_position3_reset_fp64(BgcPosition3FP64 * position)
|
||||
{
|
||||
bgc_versor_reset_fp64(&position->turn);
|
||||
bgc_vector3_reset_fp64(&position->shift);
|
||||
}
|
||||
|
||||
// ==================== Make ===================== //
|
||||
|
||||
inline void bgc_position3_make_fp32(const BgcVersorFP32 * turn, const BgcVector3FP32 * shift, BgcPosition3FP32 * position)
|
||||
{
|
||||
bgc_versor_copy_fp32(turn, &position->turn);
|
||||
bgc_vector3_copy_fp32(shift, &position->shift);
|
||||
}
|
||||
|
||||
inline void bgc_position3_make_fp64(const BgcVersorFP64 * turn, const BgcVector3FP64 * shift, BgcPosition3FP64 * position)
|
||||
{
|
||||
bgc_versor_copy_fp64(turn, &position->turn);
|
||||
bgc_vector3_copy_fp64(shift, &position->shift);
|
||||
}
|
||||
|
||||
// =================== Combine =================== //
|
||||
|
||||
inline void bgc_position3_combine_fp32(const BgcPosition3FP32 * parent, const BgcPosition3FP32 * child, BgcPosition3FP32 * combination)
|
||||
{
|
||||
BgcVector3FP32 relative_shift;
|
||||
bgc_versor_turn_vector_fp32(&parent->turn, &child->shift, &relative_shift);
|
||||
bgc_versor_combine_fp32(&child->turn, &parent->turn, &combination->turn);
|
||||
bgc_vector3_add_fp32(&parent->shift, &relative_shift, &combination->shift);
|
||||
}
|
||||
|
||||
inline void bgc_position3_combine_fp64(const BgcPosition3FP64 * parent, const BgcPosition3FP64 * child, BgcPosition3FP64 * combination)
|
||||
{
|
||||
BgcVector3FP64 relative_shift;
|
||||
bgc_versor_turn_vector_fp64(&parent->turn, &child->shift, &relative_shift);
|
||||
bgc_versor_combine_fp64(&child->turn, &parent->turn, &combination->turn);
|
||||
bgc_vector3_add_fp64(&parent->shift, &relative_shift, &combination->shift);
|
||||
}
|
||||
|
||||
// ================= Get Affine ================== //
|
||||
|
||||
inline void bgc_position3_get_affine3_map_fp32(const BgcPosition3FP32 * position, BgcAffine3FP32 * affine_map)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
bgc_versor_get_rotation_matrix_fp32(&position->turn, &affine_map->distortion);
|
||||
bgc_vector3_copy_fp32(&position->shift, &affine_map->shift);
|
||||
#else
|
||||
const float s0s0 = position->turn._s0 * position->turn._s0;
|
||||
const float x1x1 = position->turn._x1 * position->turn._x1;
|
||||
const float x2x2 = position->turn._x2 * position->turn._x2;
|
||||
const float x3x3 = position->turn._x3 * position->turn._x3;
|
||||
|
||||
const float s0x1 = position->turn._s0 * position->turn._x1;
|
||||
const float s0x2 = position->turn._s0 * position->turn._x2;
|
||||
const float s0x3 = position->turn._s0 * position->turn._x3;
|
||||
const float x1x2 = position->turn._x1 * position->turn._x2;
|
||||
const float x1x3 = position->turn._x1 * position->turn._x3;
|
||||
const float x2x3 = position->turn._x2 * position->turn._x3;
|
||||
|
||||
affine_map->r1c1 = (s0s0 + x1x1) - (x2x2 + x3x3);
|
||||
affine_map->r2c2 = (s0s0 + x2x2) - (x1x1 + x3x3);
|
||||
affine_map->r3c3 = (s0s0 + x3x3) - (x1x1 + x2x2);
|
||||
|
||||
affine_map->r1c2 = 2.0f * (x1x2 - s0x3);
|
||||
affine_map->r2c3 = 2.0f * (x2x3 - s0x1);
|
||||
affine_map->r3c1 = 2.0f * (x1x3 - s0x2);
|
||||
|
||||
affine_map->r2c1 = 2.0f * (x1x2 + s0x3);
|
||||
affine_map->r3c2 = 2.0f * (x2x3 + s0x1);
|
||||
affine_map->r1c3 = 2.0f * (x1x3 + s0x2);
|
||||
|
||||
affine_map->shift1 = position->shift.x1;
|
||||
affine_map->shift2 = position->shift.x2;
|
||||
affine_map->shift3 = position->shift.x3;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void bgc_position3_get_affine3_map_fp64(const BgcPosition3FP64 * position, BgcAffine3FP64 * affine_map)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
bgc_versor_get_rotation_matrix_fp64(&position->turn, &affine_map->distortion);
|
||||
bgc_vector3_copy_fp64(&position->shift, &affine_map->shift);
|
||||
#else
|
||||
const double s0s0 = position->turn._s0 * position->turn._s0;
|
||||
const double x1x1 = position->turn._x1 * position->turn._x1;
|
||||
const double x2x2 = position->turn._x2 * position->turn._x2;
|
||||
const double x3x3 = position->turn._x3 * position->turn._x3;
|
||||
|
||||
const double s0x1 = position->turn._s0 * position->turn._x1;
|
||||
const double s0x2 = position->turn._s0 * position->turn._x2;
|
||||
const double s0x3 = position->turn._s0 * position->turn._x3;
|
||||
const double x1x2 = position->turn._x1 * position->turn._x2;
|
||||
const double x1x3 = position->turn._x1 * position->turn._x3;
|
||||
const double x2x3 = position->turn._x2 * position->turn._x3;
|
||||
|
||||
affine_map->r1c1 = (s0s0 + x1x1) - (x2x2 + x3x3);
|
||||
affine_map->r2c2 = (s0s0 + x2x2) - (x1x1 + x3x3);
|
||||
affine_map->r3c3 = (s0s0 + x3x3) - (x1x1 + x2x2);
|
||||
|
||||
affine_map->r1c2 = 2.0 * (x1x2 - s0x3);
|
||||
affine_map->r2c3 = 2.0 * (x2x3 - s0x1);
|
||||
affine_map->r3c1 = 2.0 * (x1x3 - s0x2);
|
||||
|
||||
affine_map->r2c1 = 2.0 * (x1x2 + s0x3);
|
||||
affine_map->r3c2 = 2.0 * (x2x3 + s0x1);
|
||||
affine_map->r1c3 = 2.0 * (x1x3 + s0x2);
|
||||
|
||||
affine_map->shift1 = position->shift.x1;
|
||||
affine_map->shift2 = position->shift.x2;
|
||||
affine_map->shift3 = position->shift.x3;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // _BGC_POSITION_H_INCLUDED_
|
||||
Loading…
Add table
Add a link
Reference in a new issue