Добавлеие позиционирования и аффинного преобразования для 2-мерного пространства, добавление функций для аффинных преобразований и позиционирования
This commit is contained in:
parent
3c2b89f369
commit
101df9f089
12 changed files with 734 additions and 322 deletions
28
basic-geometry/affine2.c
Normal file
28
basic-geometry/affine2.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include "affine2.h"
|
||||
|
||||
extern inline void bgc_affine2_reset_fp32(BgcAffine2FP32 * affine);
|
||||
extern inline void bgc_affine2_reset_fp64(BgcAffine2FP64 * affine);
|
||||
|
||||
extern inline void bgc_affine2_make_fp32(const BgcMatrix2x2FP32 * distortion, const BgcVector2FP32 * shift, BgcAffine2FP32 * affine);
|
||||
extern inline void bgc_affine2_make_fp64(const BgcMatrix2x2FP64 * distortion, const BgcVector2FP64 * shift, BgcAffine2FP64 * affine);
|
||||
|
||||
extern inline void bgc_affine2_copy_fp32(const BgcAffine2FP32 * source, BgcAffine2FP32 * destination);
|
||||
extern inline void bgc_affine2_copy_fp64(const BgcAffine2FP64 * source, BgcAffine2FP64 * destination);
|
||||
|
||||
extern inline void bgc_affine2_convert_fp64_to_fp32(const BgcAffine2FP64 * source, BgcAffine2FP32 * destination);
|
||||
extern inline void bgc_affine2_convert_fp32_to_fp64(const BgcAffine2FP32 * source, BgcAffine2FP64 * destination);
|
||||
|
||||
extern inline int bgc_affine2_invert_fp32(BgcAffine2FP32 * affine);
|
||||
extern inline int bgc_affine2_invert_fp64(BgcAffine2FP64 * affine);
|
||||
|
||||
extern inline int bgc_affine2_get_inverse_fp32(const BgcAffine2FP32 * source, BgcAffine2FP32 * destination);
|
||||
extern inline int bgc_affine2_get_inverse_fp64(const BgcAffine2FP64 * source, BgcAffine2FP64 * destination);
|
||||
|
||||
extern inline void bgc_affine2_combine_fp32(const BgcAffine2FP32 * parent, const BgcAffine2FP32 * child, BgcAffine2FP32 * combination);
|
||||
extern inline void bgc_affine2_combine_fp64(const BgcAffine2FP64 * parent, const BgcAffine2FP64 * child, BgcAffine2FP64 * combination);
|
||||
|
||||
extern inline void bgc_affine2_transform_point_fp32(const BgcAffine2FP32 * affine, const BgcVector2FP32 * initial_point, BgcVector2FP32 * transformed_point);
|
||||
extern inline void bgc_affine2_transform_point_fp64(const BgcAffine2FP64 * affine, const BgcVector2FP64 * initial_point, BgcVector2FP64 * transformed_point);
|
||||
|
||||
extern inline void bgc_affine2_transform_vector_fp32(const BgcAffine2FP32 * affine, const BgcVector2FP32 * initial_vector, BgcVector2FP32 * transformed_vector);
|
||||
extern inline void bgc_affine2_transform_vector_fp64(const BgcAffine2FP64 * affine, const BgcVector2FP64 * initial_vector, BgcVector2FP64 * transformed_vector);
|
||||
175
basic-geometry/affine2.h
Normal file
175
basic-geometry/affine2.h
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
#ifndef _BGC_AFFINE2_H_INCLUDED_
|
||||
#define _BGC_AFFINE2_H_INCLUDED_
|
||||
|
||||
#include "vector2.h"
|
||||
#include "matrixes.h"
|
||||
#include "matrix2x2.h"
|
||||
|
||||
// ==================== Types ==================== //
|
||||
|
||||
typedef struct {
|
||||
BgcMatrix2x2FP32 distortion;
|
||||
BgcVector2FP32 shift;
|
||||
} BgcAffine2FP32;
|
||||
|
||||
typedef struct {
|
||||
BgcMatrix2x2FP64 distortion;
|
||||
BgcVector2FP64 shift;
|
||||
} BgcAffine2FP64;
|
||||
|
||||
// ==================== Reset ==================== //
|
||||
|
||||
inline void bgc_affine2_reset_fp32(BgcAffine2FP32 * affine)
|
||||
{
|
||||
bgc_matrix2x2_set_to_identity_fp32(&affine->distortion);
|
||||
bgc_vector2_reset_fp32(&affine->shift);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_reset_fp64(BgcAffine2FP64 * affine)
|
||||
{
|
||||
bgc_matrix2x2_set_to_identity_fp64(&affine->distortion);
|
||||
bgc_vector2_reset_fp64(&affine->shift);
|
||||
}
|
||||
|
||||
// ==================== Make ===================== //
|
||||
|
||||
inline void bgc_affine2_make_fp32(const BgcMatrix2x2FP32 * distortion, const BgcVector2FP32 * shift, BgcAffine2FP32 * affine)
|
||||
{
|
||||
bgc_matrix2x2_copy_fp32(distortion, &affine->distortion);
|
||||
bgc_vector2_copy_fp32(shift, &affine->shift);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_make_fp64(const BgcMatrix2x2FP64 * distortion, const BgcVector2FP64 * shift, BgcAffine2FP64 * affine)
|
||||
{
|
||||
bgc_matrix2x2_copy_fp64(distortion, &affine->distortion);
|
||||
bgc_vector2_copy_fp64(shift, &affine->shift);
|
||||
}
|
||||
|
||||
|
||||
// ==================== Copy ===================== //
|
||||
|
||||
inline void bgc_affine2_copy_fp32(const BgcAffine2FP32 * source, BgcAffine2FP32 * destination)
|
||||
{
|
||||
bgc_matrix2x2_copy_fp32(&source->distortion, &destination->distortion);
|
||||
bgc_vector2_copy_fp32(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_copy_fp64(const BgcAffine2FP64 * source, BgcAffine2FP64 * destination)
|
||||
{
|
||||
bgc_matrix2x2_copy_fp64(&source->distortion, &destination->distortion);
|
||||
bgc_vector2_copy_fp64(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
// =================== Convert =================== //
|
||||
|
||||
inline void bgc_affine2_convert_fp64_to_fp32(const BgcAffine2FP64 * source, BgcAffine2FP32 * destination)
|
||||
{
|
||||
bgc_matrix2x2_convert_fp64_to_fp32(&source->distortion, &destination->distortion);
|
||||
bgc_vector2_convert_fp64_to_fp32(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_convert_fp32_to_fp64(const BgcAffine2FP32 * source, BgcAffine2FP64 * destination)
|
||||
{
|
||||
bgc_matrix2x2_convert_fp32_to_fp64(&source->distortion, &destination->distortion);
|
||||
bgc_vector2_convert_fp32_to_fp64(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
// =================== Invert ==================== //
|
||||
|
||||
inline int bgc_affine2_invert_fp32(BgcAffine2FP32 * affine)
|
||||
{
|
||||
if (!bgc_matrix2x2_invert_fp32(&affine->distortion, &affine->distortion)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_matrix2x2_get_right_product_fp32(&affine->distortion, &affine->shift, &affine->shift);
|
||||
bgc_vector2_make_opposite_fp32(&affine->shift);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_affine2_invert_fp64(BgcAffine2FP64 * affine)
|
||||
{
|
||||
if (!bgc_matrix2x2_invert_fp64(&affine->distortion, &affine->distortion)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_matrix2x2_get_right_product_fp64(&affine->distortion, &affine->shift, &affine->shift);
|
||||
bgc_vector2_make_opposite_fp64(&affine->shift);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ================= Get Inverse ================= //
|
||||
|
||||
inline int bgc_affine2_get_inverse_fp32(const BgcAffine2FP32 * source, BgcAffine2FP32 * destination)
|
||||
{
|
||||
if (!bgc_matrix2x2_invert_fp32(&source->distortion, &destination->distortion)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_matrix2x2_get_right_product_fp32(&destination->distortion, &source->shift, &destination->shift);
|
||||
bgc_vector2_make_opposite_fp32(&destination->shift);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_affine2_get_inverse_fp64(const BgcAffine2FP64 * source, BgcAffine2FP64 * destination)
|
||||
{
|
||||
if (!bgc_matrix2x2_invert_fp64(&source->distortion, &destination->distortion)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_matrix2x2_get_right_product_fp64(&destination->distortion, &source->shift, &destination->shift);
|
||||
bgc_vector2_make_opposite_fp64(&destination->shift);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// =================== Combine =================== //
|
||||
|
||||
inline void bgc_affine2_combine_fp32(const BgcAffine2FP32 * parent, const BgcAffine2FP32 * child, BgcAffine2FP32 * combination)
|
||||
{
|
||||
BgcVector2FP32 child_shift;
|
||||
bgc_matrix2x2_get_right_product_fp32(&parent->distortion, &child->shift, &child_shift);
|
||||
bgc_matrix_product_2x2_at_2x2_fp32(&parent->distortion, &child->distortion, &combination->distortion);
|
||||
bgc_vector2_add_fp32(&parent->shift, &child_shift, &combination->shift);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_combine_fp64(const BgcAffine2FP64 * parent, const BgcAffine2FP64 * child, BgcAffine2FP64 * combination)
|
||||
{
|
||||
BgcVector2FP64 child_shift;
|
||||
bgc_matrix2x2_get_right_product_fp64(&parent->distortion, &child->shift, &child_shift);
|
||||
bgc_matrix_product_2x2_at_2x2_fp64(&parent->distortion, &child->distortion, &combination->distortion);
|
||||
bgc_vector2_add_fp64(&parent->shift, &child_shift, &combination->shift);
|
||||
}
|
||||
|
||||
// =============== Transform Point =============== //
|
||||
|
||||
inline void bgc_affine2_transform_point_fp32(const BgcAffine2FP32 * affine, const BgcVector2FP32 * initial_point, BgcVector2FP32 * transformed_point)
|
||||
{
|
||||
BgcVector2FP32 distorted;
|
||||
bgc_matrix2x2_get_right_product_fp32(&affine->distortion, initial_point, &distorted);
|
||||
bgc_vector2_add_fp32(&affine->shift, &distorted, transformed_point);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_transform_point_fp64(const BgcAffine2FP64 * affine, const BgcVector2FP64 * initial_point, BgcVector2FP64 * transformed_point)
|
||||
{
|
||||
BgcVector2FP64 distorted;
|
||||
bgc_matrix2x2_get_right_product_fp64(&affine->distortion, initial_point, &distorted);
|
||||
bgc_vector2_add_fp64(&affine->shift, &distorted, transformed_point);
|
||||
}
|
||||
|
||||
// ============== Transform Vector =============== //
|
||||
|
||||
inline void bgc_affine2_transform_vector_fp32(const BgcAffine2FP32 * affine, const BgcVector2FP32 * initial_vector, BgcVector2FP32 * transformed_vector)
|
||||
{
|
||||
bgc_matrix2x2_get_right_product_fp32(&affine->distortion, initial_vector, transformed_vector);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_transform_vector_fp64(const BgcAffine2FP64 * affine, const BgcVector2FP64 * initial_vector, BgcVector2FP64 * transformed_vector)
|
||||
{
|
||||
bgc_matrix2x2_get_right_product_fp64(&affine->distortion, initial_vector, transformed_vector);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -3,15 +3,21 @@
|
|||
extern inline void bgc_affine3_reset_fp32(BgcAffine3FP32 * affine);
|
||||
extern inline void bgc_affine3_reset_fp64(BgcAffine3FP64 * affine);
|
||||
|
||||
extern inline void bgc_affine3_reset_distortion_fp32(BgcAffine3FP32 * affine);
|
||||
extern inline void bgc_affine3_reset_distortion_fp64(BgcAffine3FP64 * affine);
|
||||
|
||||
extern inline void bgc_affine3_reset_shift_fp32(BgcAffine3FP32 * affine);
|
||||
extern inline void bgc_affine3_reset_shift_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_copy_fp32(const BgcAffine3FP32 * source, BgcAffine3FP32 * destination);
|
||||
extern inline void bgc_affine3_copy_fp64(const BgcAffine3FP64 * source, BgcAffine3FP64 * destination);
|
||||
|
||||
extern inline void bgc_affine3_convert_fp64_to_fp32(const BgcAffine3FP64 * source, BgcAffine3FP32 * destination);
|
||||
extern inline void bgc_affine3_convert_fp32_to_fp64(const BgcAffine3FP32 * source, BgcAffine3FP64 * destination);
|
||||
|
||||
extern inline int bgc_affine3_invert_fp32(BgcAffine3FP32 * affine);
|
||||
extern inline int bgc_affine3_invert_fp64(BgcAffine3FP64 * affine);
|
||||
|
||||
extern inline int bgc_affine3_get_inverse_fp32(const BgcAffine3FP32 * source, BgcAffine3FP32 * destination);
|
||||
extern inline int bgc_affine3_get_inverse_fp64(const BgcAffine3FP64 * source, BgcAffine3FP64 * destination);
|
||||
|
||||
extern inline void bgc_affine3_combine_fp32(const BgcAffine3FP32 * parent, const BgcAffine3FP32 * child, BgcAffine3FP32 * combination);
|
||||
extern inline void bgc_affine3_combine_fp64(const BgcAffine3FP64 * parent, const BgcAffine3FP64 * child, BgcAffine3FP64 * combination);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef _BGC_AFFINE3_H_INCLUDED_
|
||||
#define _BGC_AFFINE3_H_INCLUDED_
|
||||
|
||||
#include "utilities.h"
|
||||
#include "vector3.h"
|
||||
#include "matrixes.h"
|
||||
#include "matrix3x3.h"
|
||||
|
|
@ -9,333 +8,167 @@
|
|||
// ==================== 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
|
||||
}
|
||||
|
||||
inline void bgc_affine3_reset_distortion_fp32(BgcAffine3FP32 * affine)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
bgc_matrix3x3_set_to_identity_fp32(&affine->distortion);
|
||||
#else
|
||||
affine->r1c1 = 1.0f;
|
||||
affine->r1c2 = 0.0f;
|
||||
affine->r1c3 = 0.0f;
|
||||
|
||||
affine->r2c1 = 0.0f;
|
||||
affine->r2c2 = 1.0f;
|
||||
affine->r2c3 = 0.0f;
|
||||
|
||||
affine->r3c1 = 0.0f;
|
||||
affine->r3c2 = 0.0f;
|
||||
affine->r3c3 = 1.0f;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void bgc_affine3_reset_distortion_fp64(BgcAffine3FP64 * affine)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
bgc_matrix3x3_set_to_identity_fp64(&affine->distortion);
|
||||
#else
|
||||
affine->r1c1 = 1.0;
|
||||
affine->r1c2 = 0.0;
|
||||
affine->r1c3 = 0.0;
|
||||
|
||||
affine->r2c1 = 0.0;
|
||||
affine->r2c2 = 1.0;
|
||||
affine->r2c3 = 0.0;
|
||||
|
||||
affine->r3c1 = 0.0;
|
||||
affine->r3c2 = 0.0;
|
||||
affine->r3c3 = 1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void bgc_affine3_reset_shift_fp32(BgcAffine3FP32 * affine)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
bgc_vector3_reset_fp32(&affine->shift);
|
||||
#else
|
||||
affine->shift1 = 0.0f;
|
||||
affine->shift2 = 0.0f;
|
||||
affine->shift3 = 0.0f;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void bgc_affine3_reset_shift_fp64(BgcAffine3FP64 * affine)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
bgc_vector3_reset_fp64(&affine->shift);
|
||||
#else
|
||||
affine->shift1 = 0.0;
|
||||
affine->shift2 = 0.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;
|
||||
// ==================== Copy ===================== //
|
||||
|
||||
affine->r3c1 = distortion->r3c1;
|
||||
affine->r3c2 = distortion->r3c2;
|
||||
affine->r3c3 = distortion->r3c3;
|
||||
affine->shift3 = shift->x3;
|
||||
#endif
|
||||
inline void bgc_affine3_copy_fp32(const BgcAffine3FP32 * source, BgcAffine3FP32 * destination)
|
||||
{
|
||||
bgc_matrix3x3_copy_fp32(&source->distortion, &destination->distortion);
|
||||
bgc_vector3_copy_fp32(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
inline void bgc_affine3_copy_fp64(const BgcAffine3FP64 * source, BgcAffine3FP64 * destination)
|
||||
{
|
||||
bgc_matrix3x3_copy_fp64(&source->distortion, &destination->distortion);
|
||||
bgc_vector3_copy_fp64(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
// =================== Convert =================== //
|
||||
|
||||
inline void bgc_affine3_convert_fp64_to_fp32(const BgcAffine3FP64 * source, BgcAffine3FP32 * destination)
|
||||
{
|
||||
bgc_matrix3x3_convert_fp64_to_fp32(&source->distortion, &destination->distortion);
|
||||
bgc_vector3_convert_fp64_to_fp32(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
inline void bgc_affine3_convert_fp32_to_fp64(const BgcAffine3FP32 * source, BgcAffine3FP64 * destination)
|
||||
{
|
||||
bgc_matrix3x3_convert_fp32_to_fp64(&source->distortion, &destination->distortion);
|
||||
bgc_vector3_convert_fp32_to_fp64(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
// =================== Invert ==================== //
|
||||
|
||||
inline int bgc_affine3_invert_fp32(BgcAffine3FP32 * affine)
|
||||
{
|
||||
if (!bgc_matrix3x3_invert_fp32(&affine->distortion, &affine->distortion)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_matrix3x3_get_right_product_fp32(&affine->distortion, &affine->shift, &affine->shift);
|
||||
bgc_vector3_make_opposite_fp32(&affine->shift);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_affine3_invert_fp64(BgcAffine3FP64 * affine)
|
||||
{
|
||||
if (!bgc_matrix3x3_invert_fp64(&affine->distortion, &affine->distortion)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_matrix3x3_get_right_product_fp64(&affine->distortion, &affine->shift, &affine->shift);
|
||||
bgc_vector3_make_opposite_fp64(&affine->shift);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ================= Get Inverse ================= //
|
||||
|
||||
inline int bgc_affine3_get_inverse_fp32(const BgcAffine3FP32 * source, BgcAffine3FP32 * destination)
|
||||
{
|
||||
if (!bgc_matrix3x3_invert_fp32(&source->distortion, &destination->distortion)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_matrix3x3_get_right_product_fp32(&destination->distortion, &source->shift, &destination->shift);
|
||||
bgc_vector3_make_opposite_fp32(&destination->shift);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_affine3_get_inverse_fp64(const BgcAffine3FP64 * source, BgcAffine3FP64 * destination)
|
||||
{
|
||||
if (!bgc_matrix3x3_invert_fp64(&source->distortion, &destination->distortion)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_matrix3x3_get_right_product_fp64(&destination->distortion, &source->shift, &destination->shift);
|
||||
bgc_vector3_make_opposite_fp64(&destination->shift);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// =================== Combine =================== //
|
||||
|
||||
inline void bgc_affine3_combine_fp32(const BgcAffine3FP32 * parent, const BgcAffine3FP32 * child, BgcAffine3FP32 * combination)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
BgcVector3FP32 child_shift;
|
||||
bgc_matrix3x3_get_right_product_fp32(&parent->distortion, &child->shift, &child_shift);
|
||||
bgc_matrix_product_3x3_at_3x3_fp32(&parent->distortion, &child->distortion, &combination->distortion);
|
||||
bgc_vector3_add_fp32(&parent->shift, &child_shift, &combination->shift);
|
||||
#else
|
||||
const float r1c1 = parent->r1c1 * child->r1c1 + parent->r1c2 * child->r2c1 + parent->r1c3 * child->r3c1;
|
||||
const float r1c2 = parent->r1c1 * child->r1c2 + parent->r1c2 * child->r2c2 + parent->r1c3 * child->r3c2;
|
||||
const float r1c3 = parent->r1c1 * child->r1c3 + parent->r1c2 * child->r2c3 + parent->r1c3 * child->r3c3;
|
||||
|
||||
const float r2c1 = parent->r2c1 * child->r1c1 + parent->r2c2 * child->r2c1 + parent->r2c3 * child->r3c1;
|
||||
const float r2c2 = parent->r2c1 * child->r1c2 + parent->r2c2 * child->r2c2 + parent->r2c3 * child->r3c2;
|
||||
const float r2c3 = parent->r2c1 * child->r1c3 + parent->r2c2 * child->r2c3 + parent->r2c3 * child->r3c3;
|
||||
|
||||
const float r3c1 = parent->r3c1 * child->r1c1 + parent->r3c2 * child->r2c1 + parent->r3c3 * child->r3c1;
|
||||
const float r3c2 = parent->r3c1 * child->r1c2 + parent->r3c2 * child->r2c2 + parent->r3c3 * child->r3c2;
|
||||
const float r3c3 = parent->r3c1 * child->r1c3 + parent->r3c2 * child->r2c3 + parent->r3c3 * child->r3c3;
|
||||
|
||||
const float shift1 = parent->r1c1 * child->shift1 + parent->r1c2 * child->shift2 + parent->r1c3 * child->shift3;
|
||||
const float shift2 = parent->r2c1 * child->shift1 + parent->r2c2 * child->shift2 + parent->r2c3 * child->shift3;
|
||||
const float shift3 = parent->r3c1 * child->shift1 + parent->r3c2 * child->shift2 + parent->r3c3 * child->shift3;
|
||||
|
||||
combination->r1c1 = r1c1;
|
||||
combination->r1c2 = r1c2;
|
||||
combination->r1c3 = r1c3;
|
||||
combination->shift1 = shift1;
|
||||
|
||||
combination->r2c1 = r2c1;
|
||||
combination->r2c2 = r2c2;
|
||||
combination->r2c3 = r2c3;
|
||||
combination->shift2 = shift2;
|
||||
|
||||
combination->r3c1 = r3c1;
|
||||
combination->r3c2 = r3c2;
|
||||
combination->r3c3 = r3c3;
|
||||
combination->shift3 = shift3;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void bgc_affine3_combine_fp64(const BgcAffine3FP64 * parent, const BgcAffine3FP64 * child, BgcAffine3FP64 * combination)
|
||||
{
|
||||
#if BGC_AFFINE_USE_MATRIX
|
||||
BgcVector3FP64 child_shift;
|
||||
bgc_matrix3x3_get_right_product_fp64(&parent->distortion, &child->shift, &child_shift);
|
||||
bgc_matrix_product_3x3_at_3x3_fp64(&parent->distortion, &child->distortion, &combination->distortion);
|
||||
bgc_vector3_add_fp64(&parent->shift, &child_shift, &combination->shift);
|
||||
#else
|
||||
const double r1c1 = parent->r1c1 * child->r1c1 + parent->r1c2 * child->r2c1 + parent->r1c3 * child->r3c1;
|
||||
const double r1c2 = parent->r1c1 * child->r1c2 + parent->r1c2 * child->r2c2 + parent->r1c3 * child->r3c2;
|
||||
const double r1c3 = parent->r1c1 * child->r1c3 + parent->r1c2 * child->r2c3 + parent->r1c3 * child->r3c3;
|
||||
|
||||
const double r2c1 = parent->r2c1 * child->r1c1 + parent->r2c2 * child->r2c1 + parent->r2c3 * child->r3c1;
|
||||
const double r2c2 = parent->r2c1 * child->r1c2 + parent->r2c2 * child->r2c2 + parent->r2c3 * child->r3c2;
|
||||
const double r2c3 = parent->r2c1 * child->r1c3 + parent->r2c2 * child->r2c3 + parent->r2c3 * child->r3c3;
|
||||
|
||||
const double r3c1 = parent->r3c1 * child->r1c1 + parent->r3c2 * child->r2c1 + parent->r3c3 * child->r3c1;
|
||||
const double r3c2 = parent->r3c1 * child->r1c2 + parent->r3c2 * child->r2c2 + parent->r3c3 * child->r3c2;
|
||||
const double r3c3 = parent->r3c1 * child->r1c3 + parent->r3c2 * child->r2c3 + parent->r3c3 * child->r3c3;
|
||||
|
||||
const double shift1 = parent->r1c1 * child->shift1 + parent->r1c2 * child->shift2 + parent->r1c3 * child->shift3;
|
||||
const double shift2 = parent->r2c1 * child->shift1 + parent->r2c2 * child->shift2 + parent->r2c3 * child->shift3;
|
||||
const double shift3 = parent->r3c1 * child->shift1 + parent->r3c2 * child->shift2 + parent->r3c3 * child->shift3;
|
||||
|
||||
combination->r1c1 = r1c1;
|
||||
combination->r1c2 = r1c2;
|
||||
combination->r1c3 = r1c3;
|
||||
combination->shift1 = shift1;
|
||||
|
||||
combination->r2c1 = r2c1;
|
||||
combination->r2c2 = r2c2;
|
||||
combination->r2c3 = r2c3;
|
||||
combination->shift2 = shift2;
|
||||
|
||||
combination->r3c1 = r3c1;
|
||||
combination->r3c2 = r3c2;
|
||||
combination->r3c3 = r3c3;
|
||||
combination->shift3 = shift3;
|
||||
#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_
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -43,6 +43,14 @@
|
|||
</Linker>
|
||||
</Target>
|
||||
</Build>
|
||||
<Unit filename="affine2.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="affine2.h" />
|
||||
<Unit filename="affine3.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="affine3.h" />
|
||||
<Unit filename="angle.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
|
|
@ -76,10 +84,14 @@
|
|||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="matrixes.h" />
|
||||
<Unit filename="position.c">
|
||||
<Unit filename="position2.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="position.h" />
|
||||
<Unit filename="position2.h" />
|
||||
<Unit filename="position3.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="position3.h" />
|
||||
<Unit filename="quaternion.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#include "./matrix3x2.h"
|
||||
#include "./matrix3x3.h"
|
||||
|
||||
#include "./affine2.h"
|
||||
#include "./affine3.h"
|
||||
|
||||
#include "./complex.h"
|
||||
|
|
@ -25,6 +26,7 @@
|
|||
#include "./versor.h"
|
||||
#include "./slerp.h"
|
||||
|
||||
#include "./position2.h"
|
||||
#include "./position3.h"
|
||||
|
||||
#endif
|
||||
|
|
|
|||
40
basic-geometry/position2.c
Normal file
40
basic-geometry/position2.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#include "position2.h"
|
||||
|
||||
extern inline void bgc_position2_reset_fp32(BgcPosition2FP32 * node);
|
||||