23 #ifndef __MATRIX_33_H_
24 #define __MATRIX_33_H_
37 template<
typename T1,
typename T2>
38 inline void mat33_cast( T1 dst[3][3],
const T2 src[3][3] )
40 for( uint32_t i=0; i < 3; i++ )
41 for( uint32_t j=0; j < 3; j++ )
42 dst[i][j] = (T1)src[i][j];
53 memcpy(dst, src,
sizeof(T) * 9);
64 return src[0][0] * (src[1][1] * src[2][2] - src[1][2] * src[2][1])
65 - src[0][1] * (src[1][0] * src[2][2] - src[1][2] * src[2][0])
66 + src[0][2] * (src[1][0] * src[2][1] - src[1][1] * src[2][0]);
77 dst[0][0] = 1; dst[0][1] = 0; dst[0][2] = 0;
78 dst[1][0] = 0; dst[1][1] = 1; dst[1][2] = 0;
79 dst[2][0] = 0; dst[2][1] = 0; dst[2][2] = 1;
96 inv[0][0] = + (src[1][1] * src[2][2] - src[1][2] * src[2][1]);
97 inv[0][1] = - (src[0][1] * src[2][2] - src[0][2] * src[2][1]);
98 inv[0][2] = + (src[0][1] * src[1][2] - src[0][2] * src[1][1]);
99 inv[1][0] = - (src[1][0] * src[2][2] - src[1][2] * src[2][0]);
100 inv[1][1] = + (src[0][0] * src[2][2] - src[0][2] * src[2][0]);
101 inv[1][2] = - (src[0][0] * src[1][2] - src[0][2] * src[1][0]);
102 inv[2][0] = + (src[1][0] * src[2][1] - src[1][1] * src[2][0]);
103 inv[2][1] = - (src[0][0] * src[2][1] - src[0][1] * src[2][0]);
104 inv[2][2] = + (src[0][0] * src[1][1] - src[0][1] * src[1][0]);
107 for( uint32_t i=0; i < 3; i++ )
108 for( uint32_t k=0; k < 3; k++ )
109 dst[i][k] = inv[i][k] / det;
122 for(
int i=0; i < 3; i++ )
124 for(
int j=0; j < 3; j++ )
128 for(
int k=0; k < 3; k++ )
129 tmp[i][j] = tmp[i][j] + a[i][k] * b[k][j];
142 inline void mat33_print(
const T src[3][3],
const char* name=NULL )
149 for( uint32_t i=0; i < 3; i++ )
151 for( uint32_t j=0; j < 3; j++ )
181 for(
int row=0; row < rank; row++ )
183 if( mat[row][row] != 0 )
185 for(
int col=0; col < 3; col++ )
189 const T mult = mat[col][row] / mat[row][row];
191 for(
int i = 0; i < rank; i++ )
192 mat[col][i] -= mult * mat[row][i];
200 for(
int i=row+1; i < 3; i++ )
202 if( mat[i][row] != 0 )
204 for(
int k=0; k < rank; k++ )
206 const T tmp = mat[row][k];
207 mat[row][k] = mat[i][k];
220 for(
int i=0; i < 3; i++ )
221 mat[i][row] = mat[i][rank];
269 const T rad = 0.01745329251 * degrees;
271 const T c = cos(rad);
272 const T s = sin(rad);
300 inline void mat33_rotation( T dst[3][3], T degrees,
float origin_x,
float origin_y )
313 inline void mat33_rotation( T dst[3][3], T src[3][3], T degrees,
float origin_x,
float origin_y )
399 return src[0][0] + src[1][1] + src[2][2];
408 inline void mat33_transform( T& x_out, T& y_out,
const T x_in,
const T y_in,
const T mat[3][3] )
410 const T x = mat[0][0] * x_in + mat[0][1] * y_in + mat[0][2];
411 const T y = mat[1][0] * x_in + mat[1][1] * y_in + mat[1][2];
412 const T z = mat[2][0] * x_in + mat[2][1] * y_in + mat[2][2];
437 for( uint32_t n=0; n < N; n++ )
450 for( uint32_t i=0; i < 3; i++ )
451 for( uint32_t j=0; j < 3; j++ )
452 tmp[i][j] = src[j][i];
465 memset(dst, 0,
sizeof(T) * 9);