diff --git a/basic-geometry/position3.c b/basic-geometry/position3.c index c7857d8..7f7e41c 100644 --- a/basic-geometry/position3.c +++ b/basic-geometry/position3.c @@ -33,9 +33,15 @@ extern inline void bgc_fp64_position3_exclude(BGC_FP64_Position3* const differen extern inline void bgc_fp32_position3_get_affine(BGC_FP32_Affine3* const outward_affine_map, const BGC_FP32_Position3* const position); extern inline void bgc_fp64_position3_get_affine(BGC_FP64_Affine3* const outward_affine_map, const BGC_FP64_Position3* const position); +extern inline int bgc_fp32_position3_set_affine(BGC_FP32_Position3* const position, const BGC_FP32_Affine3* const affine_map); +extern inline int bgc_fp64_position3_set_affine(BGC_FP64_Position3* const position, const BGC_FP64_Affine3* const affine_map); + extern inline void bgc_fp32_position3_get_reverse_affine(BGC_FP32_Affine3* const inward_affine_map, const BGC_FP32_Position3* const position); extern inline void bgc_fp64_position3_get_reverse_affine(BGC_FP64_Affine3* const inward_affine_map, const BGC_FP64_Position3* const position); +extern inline int bgc_fp32_position3_set_reverse_affine(BGC_FP32_Position3* const position, const BGC_FP32_Affine3* const affine_map); +extern inline int bgc_fp64_position3_set_reverse_affine(BGC_FP64_Position3* const position, const BGC_FP64_Affine3* const affine_map); + extern inline void bgc_fp32_position3_transform_point(BGC_FP32_Vector3* const transformed_point, const BGC_FP32_Position3* const position, const BGC_FP32_Vector3* const initial_point); extern inline void bgc_fp64_position3_transform_point(BGC_FP64_Vector3* const transformed_point, const BGC_FP64_Position3* const position, const BGC_FP64_Vector3* const initial_point); diff --git a/basic-geometry/position3.h b/basic-geometry/position3.h index 0d011a8..c757b8c 100644 --- a/basic-geometry/position3.h +++ b/basic-geometry/position3.h @@ -170,6 +170,28 @@ inline void bgc_fp64_position3_get_affine(BGC_FP64_Affine3* const affine_map, co bgc_fp64_vector3_copy(&affine_map->shift, &position->shift); } +// ================= Set Affine ================== // + +inline int bgc_fp32_position3_set_affine(BGC_FP32_Position3* const position, const BGC_FP32_Affine3* const affine_map) +{ + if (bgc_fp32_quaternion_set_rotation_matrix(&position->turn._versor, &affine_map->distortion) == BGC_SUCCESS) { + bgc_fp32_vector3_copy(&position->shift, &affine_map->shift); + return BGC_SUCCESS; + } + + return BGC_FAILURE; +} + +inline int bgc_fp64_position3_set_affine(BGC_FP64_Position3* const position, const BGC_FP64_Affine3* const affine_map) +{ + if (bgc_fp64_quaternion_set_rotation_matrix(&position->turn._versor, &affine_map->distortion) == BGC_SUCCESS) { + bgc_fp64_vector3_copy(&position->shift, &affine_map->shift); + return BGC_SUCCESS; + } + + return BGC_FAILURE; +} + // ============= Get Reverse Affine ============== // inline void bgc_fp32_position3_get_reverse_affine(BGC_FP32_Affine3* const affine_map, const BGC_FP32_Position3* const position) @@ -186,6 +208,32 @@ inline void bgc_fp64_position3_get_reverse_affine(BGC_FP64_Affine3* const affine bgc_fp64_vector3_revert(&affine_map->shift); } +// ============= Set Reverse Affine ============== // + +inline int bgc_fp32_position3_set_reverse_affine(BGC_FP32_Position3* const position, const BGC_FP32_Affine3* const affine_map) +{ + if (bgc_fp32_quaternion_set_rotation_matrix(&position->turn._versor, &affine_map->distortion) == BGC_SUCCESS) { + bgc_fp32_vector3_multiply_by_matrix3x3(&position->shift, &affine_map->shift, &affine_map->distortion); + bgc_fp32_quaternion_conjugate(&position->turn._versor); + bgc_fp32_vector3_revert(&position->shift); + return BGC_SUCCESS; + } + + return BGC_FAILURE; +} + +inline int bgc_fp64_position3_set_reverse_affine(BGC_FP64_Position3* const position, const BGC_FP64_Affine3* const affine_map) +{ + if (bgc_fp64_quaternion_set_rotation_matrix(&position->turn._versor, &affine_map->distortion) == BGC_SUCCESS) { + bgc_fp64_vector3_multiply_by_matrix3x3(&position->shift, &affine_map->shift, &affine_map->distortion); + bgc_fp64_quaternion_conjugate(&position->turn._versor); + bgc_fp64_vector3_revert(&position->shift); + return BGC_SUCCESS; + } + + return BGC_FAILURE; +} + // =============== Transform Point =============== // inline void bgc_fp32_position3_transform_point(BGC_FP32_Vector3* const transformed_point, const BGC_FP32_Position3* const position, const BGC_FP32_Vector3* const initial_point) diff --git a/basic-geometry/quaternion.c b/basic-geometry/quaternion.c index 6dd2c3a..86d7ef6 100644 --- a/basic-geometry/quaternion.c +++ b/basic-geometry/quaternion.c @@ -303,64 +303,64 @@ int bgc_fp32_quaternion_set_rotation_matrix(BGC_FP32_Quaternion* const quaternio return BGC_FAILURE; } - const float ss_4 = (1 + matrix->r1c1) + (matrix->r2c2 + matrix->r3c3); - const float xx_4 = (1 + matrix->r1c1) - (matrix->r2c2 + matrix->r3c3); - const float yy_4 = (1 + matrix->r2c2) - (matrix->r1c1 + matrix->r3c3); - const float zz_4 = (1 + matrix->r3c3) - (matrix->r1c1 + matrix->r2c2); + const float ss4 = (1 + matrix->r1c1) + (matrix->r2c2 + matrix->r3c3); + const float xx4 = (1 + matrix->r1c1) - (matrix->r2c2 + matrix->r3c3); + const float yy4 = (1 + matrix->r2c2) - (matrix->r1c1 + matrix->r3c3); + const float zz4 = (1 + matrix->r3c3) - (matrix->r1c1 + matrix->r2c2); - const float sx_4 = matrix->r3c2 - matrix->r2c3; - const float sy_4 = matrix->r1c3 - matrix->r3c1; - const float sz_4 = matrix->r2c1 - matrix->r1c2; + const float sx4 = matrix->r3c2 - matrix->r2c3; + const float sy4 = matrix->r1c3 - matrix->r3c1; + const float sz4 = matrix->r2c1 - matrix->r1c2; - const float yz_4 = matrix->r3c2 + matrix->r2c3; - const float xz_4 = matrix->r1c3 + matrix->r3c1; - const float xy_4 = matrix->r2c1 + matrix->r1c2; + const float yz4 = matrix->r3c2 + matrix->r2c3; + const float xz4 = matrix->r1c3 + matrix->r3c1; + const float xy4 = matrix->r2c1 + matrix->r1c2; - float max = ss_4; + float max = ss4; int index = 0; - if (xx_4 > max) { - max = xx_4; + if (xx4 > max) { + max = xx4; index = 1; } - if (yy_4 > max) { - max = yy_4; + if (yy4 > max) { + max = yy4; index = 2; } - if (zz_4 > max) { - max = zz_4; + if (zz4 > max) { + max = zz4; index = 3; } switch (index) { case 0: - quaternion->s = ss_4; - quaternion->x = sx_4; - quaternion->y = sy_4; - quaternion->z = sz_4; + quaternion->s = ss4; + quaternion->x = sx4; + quaternion->y = sy4; + quaternion->z = sz4; break; case 1: - quaternion->s = sx_4; - quaternion->x = xx_4; - quaternion->y = xy_4; - quaternion->z = xz_4; + quaternion->s = sx4; + quaternion->x = xx4; + quaternion->y = xy4; + quaternion->z = xz4; break; case 2: - quaternion->s = sy_4; - quaternion->x = xy_4; - quaternion->y = yy_4; - quaternion->z = yz_4; + quaternion->s = sy4; + quaternion->x = xy4; + quaternion->y = yy4; + quaternion->z = yz4; break; case 3: - quaternion->s = sz_4; - quaternion->x = xz_4; - quaternion->y = yz_4; - quaternion->z = zz_4; + quaternion->s = sz4; + quaternion->x = xz4; + quaternion->y = yz4; + quaternion->z = zz4; break; } @@ -387,64 +387,64 @@ int bgc_fp64_quaternion_set_rotation_matrix(BGC_FP64_Quaternion* const quaternio return BGC_FAILURE; } - const double ss_4 = (1 + matrix->r1c1) + (matrix->r2c2 + matrix->r3c3); - const double xx_4 = (1 + matrix->r1c1) - (matrix->r2c2 - matrix->r3c3); - const double yy_4 = (1 + matrix->r2c2) - (matrix->r1c1 - matrix->r3c3); - const double zz_4 = (1 + matrix->r3c3) - (matrix->r1c1 - matrix->r2c2); + const double ss4 = (1 + matrix->r1c1) + (matrix->r2c2 + matrix->r3c3); + const double xx4 = (1 + matrix->r1c1) - (matrix->r2c2 - matrix->r3c3); + const double yy4 = (1 + matrix->r2c2) - (matrix->r1c1 - matrix->r3c3); + const double zz4 = (1 + matrix->r3c3) - (matrix->r1c1 - matrix->r2c2); - const double sx_4 = matrix->r3c2 - matrix->r2c3; - const double sy_4 = matrix->r1c3 - matrix->r3c1; - const double sz_4 = matrix->r2c1 - matrix->r1c2; + const double sx4 = matrix->r3c2 - matrix->r2c3; + const double sy4 = matrix->r1c3 - matrix->r3c1; + const double sz4 = matrix->r2c1 - matrix->r1c2; - const double yz_4 = matrix->r3c2 + matrix->r2c3; - const double xz_4 = matrix->r1c3 + matrix->r3c1; - const double xy_4 = matrix->r2c1 + matrix->r1c2; + const double yz4 = matrix->r3c2 + matrix->r2c3; + const double xz4 = matrix->r1c3 + matrix->r3c1; + const double xy4 = matrix->r2c1 + matrix->r1c2; - double max = ss_4; + double max = ss4; int index = 0; - if (xx_4 > max) { - max = xx_4; + if (xx4 > max) { + max = xx4; index = 1; } - if (yy_4 > max) { - max = yy_4; + if (yy4 > max) { + max = yy4; index = 2; } - if (zz_4 > max) { - max = zz_4; + if (zz4 > max) { + max = zz4; index = 3; } switch (index) { case 0: - quaternion->s = ss_4; - quaternion->x = sx_4; - quaternion->y = sy_4; - quaternion->z = sz_4; + quaternion->s = ss4; + quaternion->x = sx4; + quaternion->y = sy4; + quaternion->z = sz4; break; case 1: - quaternion->s = sx_4; - quaternion->x = xx_4; - quaternion->y = xy_4; - quaternion->z = xz_4; + quaternion->s = sx4; + quaternion->x = xx4; + quaternion->y = xy4; + quaternion->z = xz4; break; case 2: - quaternion->s = sy_4; - quaternion->x = xy_4; - quaternion->y = yy_4; - quaternion->z = yz_4; + quaternion->s = sy4; + quaternion->x = xy4; + quaternion->y = yy4; + quaternion->z = yz4; break; case 3: - quaternion->s = sz_4; - quaternion->x = xz_4; - quaternion->y = yz_4; - quaternion->z = zz_4; + quaternion->s = sz4; + quaternion->x = xz4; + quaternion->y = yz4; + quaternion->z = zz4; break; } diff --git a/docs/vector2-rus.md b/docs/vector2-rus.md index 108d542..5682d87 100644 --- a/docs/vector2-rus.md +++ b/docs/vector2-rus.md @@ -1,4 +1,4 @@ -# Двумерные векторы векторы +# Двумерные векторы [English (Английский)](vector2-eng.md) diff --git a/docs/vector3-rus.md b/docs/vector3-rus.md index f858f4e..c4a39b1 100644 --- a/docs/vector3-rus.md +++ b/docs/vector3-rus.md @@ -1,4 +1,4 @@ -# Трёхмерные векторы векторы +# Трёхмерные векторы [English version / Английская версия](vector3-eng.md)