Добавлеие позиционирования и аффинного преобразования для 2-мерного пространства, добавление функций для аффинных преобразований и позиционирования
This commit is contained in:
parent
3c2b89f369
commit
101df9f089
12 changed files with 734 additions and 322 deletions
|
|
@ -45,6 +45,66 @@ inline void bgc_position3_make_fp64(const BgcVersorFP64 * turn, const BgcVector3
|
|||
bgc_vector3_copy_fp64(shift, &position->shift);
|
||||
}
|
||||
|
||||
// ==================== Copy ===================== //
|
||||
|
||||
inline void bgc_position3_copy_fp32(const BgcPosition3FP32 * source, BgcPosition3FP32 * destination)
|
||||
{
|
||||
bgc_versor_copy_fp32(&source->turn, &destination->turn);
|
||||
bgc_vector3_copy_fp32(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
inline void bgc_position3_copy_fp64(const BgcPosition3FP64 * source, BgcPosition3FP64 * destination)
|
||||
{
|
||||
bgc_versor_copy_fp64(&source->turn, &destination->turn);
|
||||
bgc_vector3_copy_fp64(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
// =================== Convert =================== //
|
||||
|
||||
inline void bgc_position3_convert_fp64_to_fp32(const BgcPosition3FP64 * source, BgcPosition3FP32 * destination)
|
||||
{
|
||||
bgc_versor_convert_fp64_to_fp32(&source->turn, &destination->turn);
|
||||
bgc_vector3_convert_fp64_to_fp32(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
inline void bgc_position3_convert_fp32_to_fp64(const BgcPosition3FP32 * source, BgcPosition3FP64 * destination)
|
||||
{
|
||||
bgc_versor_convert_fp32_to_fp64(&source->turn, &destination->turn);
|
||||
bgc_vector3_convert_fp32_to_fp64(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
// =================== Invert ==================== //
|
||||
|
||||
inline void bgc_position3_invert_fp32(BgcPosition3FP32 * position)
|
||||
{
|
||||
bgc_versor_turn_vector_back_fp32(&position->turn, &position->shift, &position->shift);
|
||||
bgc_versor_invert_fp32(&position->turn);
|
||||
bgc_vector3_make_opposite_fp32(&position->shift);
|
||||
}
|
||||
|
||||
inline void bgc_position3_invert_fp64(BgcPosition3FP64 * position)
|
||||
{
|
||||
bgc_versor_turn_vector_back_fp64(&position->turn, &position->shift, &position->shift);
|
||||
bgc_versor_invert_fp64(&position->turn);
|
||||
bgc_vector3_make_opposite_fp64(&position->shift);
|
||||
}
|
||||
|
||||
// ================= Get Inverse ================= //
|
||||
|
||||
inline void bgc_position3_get_inverse_fp32(const BgcPosition3FP32 * position, BgcPosition3FP32 * inverted)
|
||||
{
|
||||
bgc_versor_turn_vector_back_fp32(&position->turn, &position->shift, &inverted->shift);
|
||||
bgc_versor_get_inverse_fp32(&position->turn, &inverted->turn);
|
||||
bgc_vector3_make_opposite_fp32(&inverted->shift);
|
||||
}
|
||||
|
||||
inline void bgc_position3_get_inverse_fp64(const BgcPosition3FP64 * position, BgcPosition3FP64 * inverted)
|
||||
{
|
||||
bgc_versor_turn_vector_back_fp64(&position->turn, &position->shift, &inverted->shift);
|
||||
bgc_versor_get_inverse_fp64(&position->turn, &inverted->turn);
|
||||
bgc_vector3_make_opposite_fp64(&inverted->shift);
|
||||
}
|
||||
|
||||
// =================== Combine =================== //
|
||||
|
||||
inline void bgc_position3_combine_fp32(const BgcPosition3FP32 * parent, const BgcPosition3FP32 * child, BgcPosition3FP32 * combination)
|
||||
|
|
@ -63,78 +123,92 @@ inline void bgc_position3_combine_fp64(const BgcPosition3FP64 * parent, const Bg
|
|||
bgc_vector3_add_fp64(&parent->shift, &relative_shift, &combination->shift);
|
||||
}
|
||||
|
||||
// ================= Get Affine ================== //
|
||||
// ============= Get Outward Affine ============== //
|
||||
|
||||
inline void bgc_position3_get_affine3_map_fp32(const BgcPosition3FP32 * position, BgcAffine3FP32 * affine_map)
|
||||
inline void bgc_position3_get_outward_affine_fp32(const BgcPosition3FP32 * position, BgcAffine3FP32 * outward_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
|
||||
bgc_versor_get_rotation_matrix_fp32(&position->turn, &outward_affine_map->distortion);
|
||||
bgc_vector3_copy_fp32(&position->shift, &outward_affine_map->shift);
|
||||
}
|
||||
|
||||
inline void bgc_position3_get_affine3_map_fp64(const BgcPosition3FP64 * position, BgcAffine3FP64 * affine_map)
|
||||
inline void bgc_position3_get_outward_affine_fp64(const BgcPosition3FP64 * position, BgcAffine3FP64 * outward_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;
|
||||
bgc_versor_get_rotation_matrix_fp64(&position->turn, &outward_affine_map->distortion);
|
||||
bgc_vector3_copy_fp64(&position->shift, &outward_affine_map->shift);
|
||||
}
|
||||
|
||||
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;
|
||||
// ============== Get Inward Affine ============== //
|
||||
|
||||
affine_map->r1c1 = (s0s0 + x1x1) - (x2x2 + x3x3);
|
||||
affine_map->r2c2 = (s0s0 + x2x2) - (x1x1 + x3x3);
|
||||
affine_map->r3c3 = (s0s0 + x3x3) - (x1x1 + x2x2);
|
||||
inline void bgc_position3_get_inward_affine_fp32(const BgcPosition3FP32 * position, BgcAffine3FP32 * inward_affine_map)
|
||||
{
|
||||
bgc_versor_get_reverse_matrix_fp32(&position->turn, &inward_affine_map->distortion);
|
||||
bgc_matrix3x3_get_right_product_fp32(&inward_affine_map->distortion, &position->shift, &inward_affine_map->shift);
|
||||
bgc_vector3_make_opposite_fp32(&inward_affine_map->shift);
|
||||
}
|
||||
|
||||
affine_map->r1c2 = 2.0 * (x1x2 - s0x3);
|
||||
affine_map->r2c3 = 2.0 * (x2x3 - s0x1);
|
||||
affine_map->r3c1 = 2.0 * (x1x3 - s0x2);
|
||||
inline void bgc_position3_get_inward_affine_fp64(const BgcPosition3FP64 * position, BgcAffine3FP64 * inward_affine_map)
|
||||
{
|
||||
bgc_versor_get_reverse_matrix_fp64(&position->turn, &inward_affine_map->distortion);
|
||||
bgc_matrix3x3_get_right_product_fp64(&inward_affine_map->distortion, &position->shift, &inward_affine_map->shift);
|
||||
bgc_vector3_make_opposite_fp64(&inward_affine_map->shift);
|
||||
}
|
||||
|
||||
affine_map->r2c1 = 2.0 * (x1x2 + s0x3);
|
||||
affine_map->r3c2 = 2.0 * (x2x3 + s0x1);
|
||||
affine_map->r1c3 = 2.0 * (x1x3 + s0x2);
|
||||
// ========== Transform Point Outwards =========== //
|
||||
|
||||
affine_map->shift1 = position->shift.x1;
|
||||
affine_map->shift2 = position->shift.x2;
|
||||
affine_map->shift3 = position->shift.x3;
|
||||
#endif
|
||||
inline void bgc_position3_transform_point_outwards_fp32(const BgcPosition3FP32 * position, const BgcVector3FP32 * inner_point, BgcVector3FP32 * outer_point)
|
||||
{
|
||||
BgcVector3FP32 turned_point;
|
||||
bgc_versor_turn_vector_fp32(&position->turn, inner_point, &turned_point);
|
||||
bgc_vector3_add_fp32(&position->shift, &turned_point, outer_point);
|
||||
}
|
||||
|
||||
inline void bgc_position3_transform_point_outwards_fp64(const BgcPosition3FP64 * position, const BgcVector3FP64 * inner_point, BgcVector3FP64 * outer_point)
|
||||
{
|
||||
BgcVector3FP64 turned_point;
|
||||
bgc_versor_turn_vector_fp64(&position->turn, inner_point, &turned_point);
|
||||
bgc_vector3_add_fp64(&position->shift, &turned_point, outer_point);
|
||||
}
|
||||
|
||||
// =========== Transform Point Inwards =========== //
|
||||
|
||||
inline void bgc_position3_transform_point_inwards_fp32(const BgcPosition3FP32 * position, const BgcVector3FP32 * outer_point, BgcVector3FP32 * inner_point)
|
||||
{
|
||||
BgcVector3FP32 relative_point;
|
||||
bgc_vector3_subtract_fp32(outer_point, &position->shift, &relative_point);
|
||||
bgc_versor_turn_vector_back_fp32(&position->turn, &relative_point, inner_point);
|
||||
|
||||
}
|
||||
|
||||
inline void bgc_position3_transform_point_inwards_fp64(const BgcPosition3FP64 * position, const BgcVector3FP64 * outer_point, BgcVector3FP64 * inner_point)
|
||||
{
|
||||
BgcVector3FP64 relative_point;
|
||||
bgc_vector3_subtract_fp64(outer_point, &position->shift, &relative_point);
|
||||
bgc_versor_turn_vector_back_fp64(&position->turn, &relative_point, inner_point);
|
||||
|
||||
}
|
||||
|
||||
// ========== Transform Vector Outwards ========== //
|
||||
|
||||
inline void bgc_position3_transform_vector_outwards_fp32(const BgcPosition3FP32 * position, const BgcVector3FP32 * inner_vector, BgcVector3FP32 * outer_vector)
|
||||
{
|
||||
bgc_versor_turn_vector_fp32(&position->turn, inner_vector, outer_vector);
|
||||
}
|
||||
|
||||
inline void bgc_position3_transform_vector_outwards_fp64(const BgcPosition3FP64 * position, const BgcVector3FP64 * inner_vector, BgcVector3FP64 * outer_vector)
|
||||
{
|
||||
bgc_versor_turn_vector_fp64(&position->turn, inner_vector, outer_vector);
|
||||
}
|
||||
|
||||
// ========== Transform Vector Inwards =========== //
|
||||
|
||||
inline void bgc_position3_transform_vector_inward_fp32(const BgcPosition3FP32 * position, const BgcVector3FP32 * outer_vector, BgcVector3FP32 * inner_vector)
|
||||
{
|
||||
bgc_versor_turn_vector_back_fp32(&position->turn, outer_vector, inner_vector);
|
||||
}
|
||||
|
||||
inline void bgc_position3_transform_vector_inward_fp64(const BgcPosition3FP64 * position, const BgcVector3FP64 * outer_vector, BgcVector3FP64 * inner_vector)
|
||||
{
|
||||
bgc_versor_turn_vector_back_fp64(&position->turn, outer_vector, inner_vector);
|
||||
}
|
||||
|
||||
#endif // _BGC_POSITION_H_INCLUDED_
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue