164 lines
11 KiB
C
164 lines
11 KiB
C
#include "./matrix3x3.h"
|
|
|
|
extern inline void bgc_fp32_matrix3x3_reset(BGC_FP32_Matrix3x3* const matrix);
|
|
extern inline void bgc_fp64_matrix3x3_reset(BGC_FP64_Matrix3x3* const matrix);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_make_identity(BGC_FP32_Matrix3x3* const matrix);
|
|
extern inline void bgc_fp64_matrix3x3_make_identity(BGC_FP64_Matrix3x3* const matrix);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_make_diagonal(BGC_FP32_Matrix3x3* const matrix, const float d1, const float d2, const float d3);
|
|
extern inline void bgc_fp64_matrix3x3_make_diagonal(BGC_FP64_Matrix3x3* const matrix, const double d1, const double d2, const double d3);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_copy(BGC_FP32_Matrix3x3* const destination, const BGC_FP32_Matrix3x3* const source);
|
|
extern inline void bgc_fp64_matrix3x3_copy(BGC_FP64_Matrix3x3* const destination, const BGC_FP64_Matrix3x3* const source);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_swap(BGC_FP32_Matrix3x3* const matrix1, BGC_FP32_Matrix3x3* const matrix2);
|
|
extern inline void bgc_fp64_matrix3x3_swap(BGC_FP64_Matrix3x3* const matrix1, BGC_FP64_Matrix3x3* const matrix2);
|
|
|
|
extern inline void bgc_fp64_matrix3x3_convert_to_fp32(BGC_FP32_Matrix3x3* const destination, const BGC_FP64_Matrix3x3* const source);
|
|
extern inline void bgc_fp32_matrix3x3_convert_to_fp64(BGC_FP64_Matrix3x3* const destination, const BGC_FP32_Matrix3x3* const source);
|
|
|
|
extern inline float bgc_fp32_matrix3x3_get_determinant(const BGC_FP32_Matrix3x3* const matrix);
|
|
extern inline double bgc_fp64_matrix3x3_get_determinant(const BGC_FP64_Matrix3x3* const matrix);
|
|
|
|
extern inline int bgc_fp32_matrix3x3_is_identity(const BGC_FP32_Matrix3x3* const matrix);
|
|
extern inline int bgc_fp64_matrix3x3_is_identity(const BGC_FP64_Matrix3x3* const matrix);
|
|
|
|
extern inline int bgc_fp32_matrix3x3_is_singular(const BGC_FP32_Matrix3x3* const matrix);
|
|
extern inline int bgc_fp64_matrix3x3_is_singular(const BGC_FP64_Matrix3x3* const matrix);
|
|
|
|
extern inline int bgc_fp32_matrix3x3_is_rotation(const BGC_FP32_Matrix3x3* const matrix);
|
|
extern inline int bgc_fp64_matrix3x3_is_rotation(const BGC_FP64_Matrix3x3* const matrix);
|
|
|
|
extern inline int bgc_fp32_matrix3x3_invert(BGC_FP32_Matrix3x3* const matrix);
|
|
extern inline int bgc_fp64_matrix3x3_invert(BGC_FP64_Matrix3x3* const matrix);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_transpose(BGC_FP32_Matrix3x3* const matrix);
|
|
extern inline void bgc_fp64_matrix3x3_transpose(BGC_FP64_Matrix3x3* const matrix);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_get_transposed(BGC_FP32_Matrix3x3* const transposed, const BGC_FP32_Matrix3x3* const matrix);
|
|
extern inline void bgc_fp64_matrix3x3_get_transposed(BGC_FP64_Matrix3x3* const transposed, const BGC_FP64_Matrix3x3* const matrix);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_get_row(BGC_FP32_Vector3* const row, const BGC_FP32_Matrix3x3* const matrix, const int row_number);
|
|
extern inline void bgc_fp64_matrix3x3_get_row(BGC_FP64_Vector3* const row, const BGC_FP64_Matrix3x3* const matrix, const int row_number);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_set_row(BGC_FP32_Matrix3x3* const matrix, const int row_number, const BGC_FP32_Vector3* const row);
|
|
extern inline void bgc_fp64_matrix3x3_set_row(BGC_FP64_Matrix3x3* const matrix, const int row_number, const BGC_FP64_Vector3* const row);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_get_column(BGC_FP32_Vector3* const column, const BGC_FP32_Matrix3x3* const matrix, const int column_number);
|
|
extern inline void bgc_fp64_matrix3x3_get_column(BGC_FP64_Vector3* const column, const BGC_FP64_Matrix3x3* const matrix, const int column_number);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_set_column(BGC_FP32_Matrix3x3* const matrix, const int column_number, const BGC_FP32_Vector3* const column);
|
|
extern inline void bgc_fp64_matrix3x3_set_column(BGC_FP64_Matrix3x3* const matrix, const int column_number, const BGC_FP64_Vector3* const column);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_add(BGC_FP32_Matrix3x3* const sum, const BGC_FP32_Matrix3x3* const matrix1, const BGC_FP32_Matrix3x3* const matrix2);
|
|
extern inline void bgc_fp64_matrix3x3_add(BGC_FP64_Matrix3x3* const sum, const BGC_FP64_Matrix3x3* const matrix1, const BGC_FP64_Matrix3x3* const matrix2);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_add_scaled(BGC_FP32_Matrix3x3* const sum, const BGC_FP32_Matrix3x3* const basic_matrix, const BGC_FP32_Matrix3x3* const scalable_matrix, const float scale);
|
|
extern inline void bgc_fp64_matrix3x3_add_scaled(BGC_FP64_Matrix3x3* const sum, const BGC_FP64_Matrix3x3* const basic_matrix, const BGC_FP64_Matrix3x3* const scalable_matrix, const double scale);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_subtract(BGC_FP32_Matrix3x3* const difference, const BGC_FP32_Matrix3x3* const minuend, const BGC_FP32_Matrix3x3* const subtrahend);
|
|
extern inline void bgc_fp64_matrix3x3_subtract(BGC_FP64_Matrix3x3* const difference, const BGC_FP64_Matrix3x3* const minuend, const BGC_FP64_Matrix3x3* const subtrahend);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_subtract_scaled(BGC_FP32_Matrix3x3* const difference, const BGC_FP32_Matrix3x3* const basic_matrix, const BGC_FP32_Matrix3x3* const scalable_matrix, const float scale);
|
|
extern inline void bgc_fp64_matrix3x3_subtract_scaled(BGC_FP64_Matrix3x3* const difference, const BGC_FP64_Matrix3x3* const basic_matrix, const BGC_FP64_Matrix3x3* const scalable_matrix, const double scale);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_multiply_by_real(BGC_FP32_Matrix3x3* const product, const BGC_FP32_Matrix3x3* const multiplicand, const float multiplier);
|
|
extern inline void bgc_fp64_matrix3x3_multiply_by_real(BGC_FP64_Matrix3x3* const product, const BGC_FP64_Matrix3x3* const multiplicand, const double multiplier);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_multiply_by_vector3(BGC_FP32_Vector3* const product, const BGC_FP32_Matrix3x3* const matrix, const BGC_FP32_Vector3* const vector);
|
|
extern inline void bgc_fp64_matrix3x3_multiply_by_vector3(BGC_FP64_Vector3* const product, const BGC_FP64_Matrix3x3* const matrix, const BGC_FP64_Vector3* const vector);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_multiply_by_matrix2x3(BGC_FP32_Matrix2x3* const product, const BGC_FP32_Matrix3x3* const matrix1, const BGC_FP32_Matrix2x3* const matrix2);
|
|
extern inline void bgc_fp64_matrix3x3_multiply_by_matrix2x3(BGC_FP64_Matrix2x3* const product, const BGC_FP64_Matrix3x3* const matrix1, const BGC_FP64_Matrix2x3* const matrix2);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_multiply_by_matrix3x3(BGC_FP32_Matrix3x3* const product, const BGC_FP32_Matrix3x3* const matrix1, const BGC_FP32_Matrix3x3* const matrix2);
|
|
extern inline void bgc_fp64_matrix3x3_multiply_by_matrix3x3(BGC_FP64_Matrix3x3* const product, const BGC_FP64_Matrix3x3* const matrix1, const BGC_FP64_Matrix3x3* const matrix2);
|
|
|
|
extern inline int bgc_fp32_matrix3x3_divide_by_real(BGC_FP32_Matrix3x3* const quotient, const BGC_FP32_Matrix3x3* const dividend, const float divisor);
|
|
extern inline int bgc_fp64_matrix3x3_divide_by_real(BGC_FP64_Matrix3x3* const quotient, const BGC_FP64_Matrix3x3* const dividend, const double divisor);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_get_mean2(BGC_FP32_Matrix3x3* const mean, const BGC_FP32_Matrix3x3* const term1, const BGC_FP32_Matrix3x3* const term2);
|
|
extern inline void bgc_fp64_matrix3x3_get_mean2(BGC_FP64_Matrix3x3* const mean, const BGC_FP64_Matrix3x3* const term1, const BGC_FP64_Matrix3x3* const term2);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_get_mean3(BGC_FP32_Matrix3x3* const mean, const BGC_FP32_Matrix3x3* const term1, const BGC_FP32_Matrix3x3* const term2, const BGC_FP32_Matrix3x3* const term3);
|
|
extern inline void bgc_fp64_matrix3x3_get_mean3(BGC_FP64_Matrix3x3* const mean, const BGC_FP64_Matrix3x3* const term1, const BGC_FP64_Matrix3x3* const term2, const BGC_FP64_Matrix3x3* const term3);
|
|
|
|
extern inline void bgc_fp32_matrix3x3_interpolate(BGC_FP32_Matrix3x3* const interpolation, const BGC_FP32_Matrix3x3* const first, const BGC_FP32_Matrix3x3* const second, const float phase);
|
|
extern inline void bgc_fp64_matrix3x3_interpolate(BGC_FP64_Matrix3x3* const interpolation, const BGC_FP64_Matrix3x3* const first, const BGC_FP64_Matrix3x3* const second, const double phase);
|
|
|
|
// ================ Get Inverse ================= //
|
|
|
|
int bgc_fp32_matrix3x3_get_inverse(BGC_FP32_Matrix3x3* const inverse, const BGC_FP32_Matrix3x3* const matrix)
|
|
{
|
|
const float determinant = bgc_fp32_matrix3x3_get_determinant(matrix);
|
|
|
|
if (bgc_fp32_is_zero(determinant)) {
|
|
return BGC_FAILURE;
|
|
}
|
|
|
|
const float r1c1 = matrix->r2c2 * matrix->r3c3 - matrix->r2c3 * matrix->r3c2;
|
|
const float r1c2 = matrix->r1c3 * matrix->r3c2 - matrix->r1c2 * matrix->r3c3;
|
|
const float r1c3 = matrix->r1c2 * matrix->r2c3 - matrix->r1c3 * matrix->r2c2;
|
|
|
|
const float r2c1 = matrix->r2c3 * matrix->r3c1 - matrix->r2c1 * matrix->r3c3;
|
|
const float r2c2 = matrix->r1c1 * matrix->r3c3 - matrix->r1c3 * matrix->r3c1;
|
|
const float r2c3 = matrix->r1c3 * matrix->r2c1 - matrix->r1c1 * matrix->r2c3;
|
|
|
|
const float r3c1 = matrix->r2c1 * matrix->r3c2 - matrix->r2c2 * matrix->r3c1;
|
|
const float r3c2 = matrix->r1c2 * matrix->r3c1 - matrix->r1c1 * matrix->r3c2;
|
|
const float r3c3 = matrix->r1c1 * matrix->r2c2 - matrix->r1c2 * matrix->r2c1;
|
|
|
|
const float multiplier = 1.0f / determinant;
|
|
|
|
inverse->r1c1 = r1c1 * multiplier;
|
|
inverse->r1c2 = r1c2 * multiplier;
|
|
inverse->r1c3 = r1c3 * multiplier;
|
|
|
|
inverse->r2c1 = r2c1 * multiplier;
|
|
inverse->r2c2 = r2c2 * multiplier;
|
|
inverse->r2c3 = r2c3 * multiplier;
|
|
|
|
inverse->r3c1 = r3c1 * multiplier;
|
|
inverse->r3c2 = r3c2 * multiplier;
|
|
inverse->r3c3 = r3c3 * multiplier;
|
|
|
|
return BGC_SUCCESS;
|
|
}
|
|
|
|
int bgc_fp64_matrix3x3_get_inverse(BGC_FP64_Matrix3x3* const inverse, const BGC_FP64_Matrix3x3* const matrix)
|
|
{
|
|
const double determinant = bgc_fp64_matrix3x3_get_determinant(matrix);
|
|
|
|
if (bgc_fp64_is_zero(determinant)) {
|
|
return BGC_FAILURE;
|
|
}
|
|
|
|
const double r1c1 = matrix->r2c2 * matrix->r3c3 - matrix->r2c3 * matrix->r3c2;
|
|
const double r1c2 = matrix->r1c3 * matrix->r3c2 - matrix->r1c2 * matrix->r3c3;
|
|
const double r1c3 = matrix->r1c2 * matrix->r2c3 - matrix->r1c3 * matrix->r2c2;
|
|
|
|
const double r2c1 = matrix->r2c3 * matrix->r3c1 - matrix->r2c1 * matrix->r3c3;
|
|
const double r2c2 = matrix->r1c1 * matrix->r3c3 - matrix->r1c3 * matrix->r3c1;
|
|
const double r2c3 = matrix->r1c3 * matrix->r2c1 - matrix->r1c1 * matrix->r2c3;
|
|
|
|
const double r3c1 = matrix->r2c1 * matrix->r3c2 - matrix->r2c2 * matrix->r3c1;
|
|
const double r3c2 = matrix->r1c2 * matrix->r3c1 - matrix->r1c1 * matrix->r3c2;
|
|
const double r3c3 = matrix->r1c1 * matrix->r2c2 - matrix->r1c2 * matrix->r2c1;
|
|
|
|
const double multiplier = 1.0 / determinant;
|
|
|
|
inverse->r1c1 = r1c1 * multiplier;
|
|
inverse->r1c2 = r1c2 * multiplier;
|
|
inverse->r1c3 = r1c3 * multiplier;
|
|
|
|
inverse->r2c1 = r2c1 * multiplier;
|
|
inverse->r2c2 = r2c2 * multiplier;
|
|
inverse->r2c3 = r2c3 * multiplier;
|
|
|
|
inverse->r3c1 = r3c1 * multiplier;
|
|
inverse->r3c2 = r3c2 * multiplier;
|
|
inverse->r3c3 = r3c3 * multiplier;
|
|
|
|
return BGC_SUCCESS;
|
|
}
|