Добавление position3 и aффинного преобразования
This commit is contained in:
parent
fd7c6c91cd
commit
d8347656c7
7 changed files with 375 additions and 0 deletions
13
basic-geometry/affine3.c
Normal file
13
basic-geometry/affine3.c
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include "affine3.h"
|
||||
|
||||
extern inline void bgc_affine3_reset_fp32(BgcAffine3FP32 * affine);
|
||||
extern inline void bgc_affine3_reset_fp64(BgcAffine3FP64 * affine);
|
||||
|
||||
extern inline void bgc_affine3_make_fp32(const BgcMatrix3x3FP32 * distortion, const BgcVector3FP32 * shift, BgcAffine3FP32 * affine);
|
||||
extern inline void bgc_affine3_make_fp64(const BgcMatrix3x3FP64 * distortion, const BgcVector3FP64 * shift, BgcAffine3FP64 * affine);
|
||||
|
||||
extern inline void bgc_affine3_transform_point_fp32(const BgcAffine3FP32 * affine, const BgcVector3FP32 * initial_point, BgcVector3FP32 * transformed_point);
|
||||
extern inline void bgc_affine3_transform_point_fp64(const BgcAffine3FP64 * affine, const BgcVector3FP64 * initial_point, BgcVector3FP64 * transformed_point);
|
||||
|
||||
extern inline void bgc_affine3_transform_vector_fp32(const BgcAffine3FP32 * affine, const BgcVector3FP32 * initial_vector, BgcVector3FP32 * transformed_vector);
|
||||
extern inline void bgc_affine3_transform_vector_fp64(const BgcAffine3FP64 * affine, const BgcVector3FP64 * initial_vector, BgcVector3FP64 * transformed_vector);
|
||||
197
basic-geometry/affine3.h
Normal file
197
basic-geometry/affine3.h
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
#ifndef _BGC_AFFINE3_H_INCLUDED_
|
||||
#define _BGC_AFFINE3_H_INCLUDED_
|
||||
|
||||
#include "utilities.h"
|
||||
#include "vector3.h"
|
||||
#include "matrixes.h"
|
||||
#include "matrix3x3.h"
|
||||
|
||||
// ==================== Types ==================== //
|
||||
|
||||
typedef struct {
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
BgcMatrix3x3FP32 distortion;
|
||||
BgcVector3FP32 shift;
|
||||
#else
|
||||
float r1c1, r1c2, r1c3, shift1;
|
||||
float r2c1, r2c2, r2c3, shift2;
|
||||
float r3c1, r3c2, r3c3, shift3;
|
||||
#endif
|
||||
} BgcAffine3FP32;
|
||||
|
||||
typedef struct {
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
BgcMatrix3x3FP64 distortion;
|
||||
BgcVector3FP64 shift;
|
||||
#else
|
||||
double r1c1, r1c2, r1c3, shift1;
|
||||
double r2c1, r2c2, r2c3, shift2;
|
||||
double r3c1, r3c2, r3c3, shift3;
|
||||
#endif
|
||||
} BgcAffine3FP64;
|
||||
|
||||
// ==================== Reset ==================== //
|
||||
|
||||
inline void bgc_affine3_reset_fp32(BgcAffine3FP32 * affine)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
bgc_matrix3x3_set_to_identity_fp32(&affine->distortion);
|
||||
bgc_vector3_reset_fp32(&affine->shift);
|
||||
#else
|
||||
affine->r1c1 = 1.0f;
|
||||
affine->r1c2 = 0.0f;
|
||||
affine->r1c3 = 0.0f;
|
||||
affine->shift1 = 0.0f;
|
||||
|
||||
affine->r2c1 = 0.0f;
|
||||
affine->r2c2 = 1.0f;
|
||||
affine->r2c3 = 0.0f;
|
||||
affine->shift2 = 0.0f;
|
||||
|
||||
affine->r3c1 = 0.0f;
|
||||
affine->r3c2 = 0.0f;
|
||||
affine->r3c3 = 1.0f;
|
||||
affine->shift3 = 0.0f;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void bgc_affine3_reset_fp64(BgcAffine3FP64 * affine)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
bgc_matrix3x3_set_to_identity_fp64(&affine->distortion);
|
||||
bgc_vector3_reset_fp64(&affine->shift);
|
||||
#else
|
||||
affine->r1c1 = 1.0;
|
||||
affine->r1c2 = 0.0;
|
||||
affine->r1c3 = 0.0;
|
||||
affine->shift1 = 0.0;
|
||||
|
||||
affine->r2c1 = 0.0;
|
||||
affine->r2c2 = 1.0;
|
||||
affine->r2c3 = 0.0;
|
||||
affine->shift2 = 0.0;
|
||||
|
||||
affine->r3c1 = 0.0;
|
||||
affine->r3c2 = 0.0;
|
||||
affine->r3c3 = 1.0;
|
||||
affine->shift3 = 0.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// ==================== Make ===================== //
|
||||
|
||||
inline void bgc_affine3_make_fp32(const BgcMatrix3x3FP32 * distortion, const BgcVector3FP32 * shift, BgcAffine3FP32 * affine)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
bgc_matrix3x3_copy_fp32(distortion, &affine->distortion);
|
||||
bgc_vector3_copy_fp32(shift, &affine->shift);
|
||||
#else
|
||||
affine->r1c1 = distortion->r1c1;
|
||||
affine->r1c2 = distortion->r1c2;
|
||||
affine->r1c3 = distortion->r1c3;
|
||||
affine->shift1 = shift->x1;
|
||||
|
||||
affine->r2c1 = distortion->r2c1;
|
||||
affine->r2c2 = distortion->r2c2;
|
||||
affine->r2c3 = distortion->r2c3;
|
||||
affine->shift2 = shift->x2;
|
||||
|
||||
affine->r3c1 = distortion->r3c1;
|
||||
affine->r3c2 = distortion->r3c2;
|
||||
affine->r3c3 = distortion->r3c3;
|
||||
affine->shift3 = shift->x3;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void bgc_affine3_make_fp64(const BgcMatrix3x3FP64 * distortion, const BgcVector3FP64 * shift, BgcAffine3FP64 * affine)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
bgc_matrix3x3_copy_fp64(distortion, &affine->distortion);
|
||||
bgc_vector3_copy_fp64(shift, &affine->shift);
|
||||
#else
|
||||
affine->r1c1 = distortion->r1c1;
|
||||
affine->r1c2 = distortion->r1c2;
|
||||
affine->r1c3 = distortion->r1c3;
|
||||
affine->shift1 = shift->x1;
|
||||
|
||||
affine->r2c1 = distortion->r2c1;
|
||||
affine->r2c2 = distortion->r2c2;
|
||||
affine->r2c3 = distortion->r2c3;
|
||||
affine->shift2 = shift->x2;
|
||||
|
||||
affine->r3c1 = distortion->r3c1;
|
||||
affine->r3c2 = distortion->r3c2;
|
||||
affine->r3c3 = distortion->r3c3;
|
||||
affine->shift3 = shift->x3;
|
||||
#endif
|
||||
}
|
||||
|
||||
// =============== Transform Point =============== //
|
||||
|
||||
inline void bgc_affine3_transform_point_fp32(const BgcAffine3FP32 * affine, const BgcVector3FP32 * initial_point, BgcVector3FP32 * transformed_point)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
BgcVector3FP32 distorted;
|
||||
bgc_matrix3x3_get_right_product_fp32(&affine->distortion, initial_point, &distorted);
|
||||
bgc_vector3_add_fp32(&affine->shift, &distorted, transformed_point);
|
||||
#else
|
||||
const float x1 = affine->r1c1 * initial_point->x1 + affine->r1c2 * initial_point->x2 + affine->r1c3 * initial_point->x3 + affine->shift1;
|
||||
const float x2 = affine->r2c1 * initial_point->x1 + affine->r2c2 * initial_point->x2 + affine->r2c3 * initial_point->x3 + affine->shift2;
|
||||
const float x3 = affine->r3c1 * initial_point->x1 + affine->r3c2 * initial_point->x2 + affine->r3c3 * initial_point->x3 + affine->shift3;
|
||||
|
||||
transformed_point->x1 = x1;
|
||||
transformed_point->x2 = x2;
|
||||
transformed_point->x3 = x3;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void bgc_affine3_transform_point_fp64(const BgcAffine3FP64 * affine, const BgcVector3FP64 * initial_point, BgcVector3FP64 * transformed_point)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
BgcVector3FP64 distorted;
|
||||
bgc_matrix3x3_get_right_product_fp64(&affine->distortion, initial_point, &distorted);
|
||||
bgc_vector3_add_fp64(&affine->shift, &distorted, transformed_point);
|
||||
#else
|
||||
const double x1 = affine->r1c1 * initial_point->x1 + affine->r1c2 * initial_point->x2 + affine->r1c3 * initial_point->x3 + affine->shift1;
|
||||
const double x2 = affine->r2c1 * initial_point->x1 + affine->r2c2 * initial_point->x2 + affine->r2c3 * initial_point->x3 + affine->shift2;
|
||||
const double x3 = affine->r3c1 * initial_point->x1 + affine->r3c2 * initial_point->x2 + affine->r3c3 * initial_point->x3 + affine->shift3;
|
||||
|
||||
transformed_point->x1 = x1;
|
||||
transformed_point->x2 = x2;
|
||||
transformed_point->x3 = x3;
|
||||
#endif
|
||||
}
|
||||
|
||||
// ============== Transform Vector =============== //
|
||||
|
||||
inline void bgc_affine3_transform_vector_fp32(const BgcAffine3FP32 * affine, const BgcVector3FP32 * initial_vector, BgcVector3FP32 * transformed_vector)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
bgc_matrix3x3_get_right_product_fp32(&affine->distortion, initial_vector, transformed_vector);
|
||||
#else
|
||||
const float x1 = affine->r1c1 * initial_vector->x1 + affine->r1c2 * initial_vector->x2 + affine->r1c3 * initial_vector->x3;
|
||||
const float x2 = affine->r2c1 * initial_vector->x1 + affine->r2c2 * initial_vector->x2 + affine->r2c3 * initial_vector->x3;
|
||||
const float x3 = affine->r3c1 * initial_vector->x1 + affine->r3c2 * initial_vector->x2 + affine->r3c3 * initial_vector->x3;
|
||||
|
||||
transformed_vector->x1 = x1;
|
||||
transformed_vector->x2 = x2;
|
||||
transformed_vector->x3 = x3;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void bgc_affine3_transform_vector_fp64(const BgcAffine3FP64 * affine, const BgcVector3FP64 * initial_vector, BgcVector3FP64 * transformed_vector)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
bgc_matrix3x3_get_right_product_fp64(&affine->distortion, initial_vector, transformed_vector);
|
||||
#else
|
||||
const double x1 = affine->r1c1 * initial_vector->x1 + affine->r1c2 * initial_vector->x2 + affine->r1c3 * initial_vector->x3;
|
||||
const double x2 = affine->r2c1 * initial_vector->x1 + affine->r2c2 * initial_vector->x2 + affine->r2c3 * initial_vector->x3;
|
||||
const double x3 = affine->r3c1 * initial_vector->x1 + affine->r3c2 * initial_vector->x2 + affine->r3c3 * initial_vector->x3;
|
||||
|
||||
transformed_vector->x1 = x1;
|
||||
transformed_vector->x2 = x2;
|
||||
transformed_vector->x3 = x3;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // _BGC_AFFINE3_H_INCLUDED_
|
||||
|
|
@ -76,6 +76,10 @@
|
|||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="matrixes.h" />
|
||||
<Unit filename="position.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="position.h" />
|
||||
<Unit filename="quaternion.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@
|
|||
#include "./matrix2x3.h"
|
||||
#include "./matrix3x2.h"
|
||||
#include "./matrix3x3.h"
|
||||
|
||||
#include "./affine3.h"
|
||||
|
||||
#include "./complex.h"
|
||||
#include "./cotes-number.h"
|
||||
|
|
@ -22,5 +24,7 @@
|
|||
#include "./quaternion.h"
|
||||
#include "./versor.h"
|
||||
#include "./slerp.h"
|
||||
|
||||
#include "./position3.h"
|
||||
|
||||
#endif
|
||||
|
|
|
|||
13
basic-geometry/position3.c
Normal file
13
basic-geometry/position3.c
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include "position3.h"
|
||||
|
||||
extern inline void bgc_position3_reset_fp32(BgcPosition3FP32 * node);
|
||||
extern inline void bgc_position3_reset_fp64(BgcPosition3FP64 * node);
|
||||
|
||||
extern inline void bgc_position3_make_fp32(const BgcVersorFP32 * turn, const BgcVector3FP32 * shift, BgcPosition3FP32 * position);
|
||||
extern inline void bgc_position3_make_fp64(const BgcVersorFP64 * turn, const BgcVector3FP64 * shift, BgcPosition3FP64 * position);
|
||||
|
||||
extern inline void bgc_position3_combine_fp32(const BgcPosition3FP32 * parent, const BgcPosition3FP32 * child, BgcPosition3FP32 * combination);
|
||||
extern inline void bgc_position3_combine_fp64(const BgcPosition3FP64 * parent, const BgcPosition3FP64 * child, BgcPosition3FP64 * combination);
|
||||
|
||||
extern inline void bgc_position3_get_affine3_map_fp32(const BgcPosition3FP32 * position, BgcAffine3FP32 * affine_map);
|
||||
extern inline void bgc_position3_get_affine3_map_fp64(const BgcPosition3FP64 * position, BgcAffine3FP64 * affine_map);
|
||||
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_
|
||||
|
|
@ -46,6 +46,10 @@
|
|||
#define BGC_AXIS_REVERSE_X2 -2
|
||||
#define BGC_AXIS_REVERSE_X3 -3
|
||||
|
||||
#if !defined(BGC_AFFINE_USE_MATRIX)
|
||||
#define BGC_AFFINE_USE_MATRIX 1
|
||||
#endif
|
||||
|
||||
inline int bgc_is_correct_axis(const int axis)
|
||||
{
|
||||
return axis == BGC_AXIS_X1 || axis == BGC_AXIS_REVERSE_X1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue