23 #ifndef __MATRIX_33_H_ 24 #define __MATRIX_33_H_ 35 template<
typename T1,
typename T2>
36 inline void mat33_cast( T1 dst[3][3],
const T2 src[3][3] )
38 for( uint32_t i=0; i < 3; i++ )
39 for( uint32_t j=0; j < 3; j++ )
40 dst[i][j] = (T1)src[i][j];
51 memcpy(dst, src,
sizeof(T) * 9);
62 return src[0][0] * (src[1][1] * src[2][2] - src[1][2] * src[2][1])
63 - src[0][1] * (src[1][0] * src[2][2] - src[1][2] * src[2][0])
64 + src[0][2] * (src[1][0] * src[2][1] - src[1][1] * src[2][0]);
75 dst[0][0] = 1; dst[0][1] = 0; dst[0][2] = 0;
76 dst[1][0] = 0; dst[1][1] = 1; dst[1][2] = 0;
77 dst[2][0] = 0; dst[2][1] = 0; dst[2][2] = 1;
94 inv[0][0] = + (src[1][1] * src[2][2] - src[1][2] * src[2][1]);
95 inv[0][1] = - (src[0][1] * src[2][2] - src[0][2] * src[2][1]);
96 inv[0][2] = + (src[0][1] * src[1][2] - src[0][2] * src[1][1]);
97 inv[1][0] = - (src[1][0] * src[2][2] - src[1][2] * src[2][0]);
98 inv[1][1] = + (src[0][0] * src[2][2] - src[0][2] * src[2][0]);
99 inv[1][2] = - (src[0][0] * src[1][2] - src[0][2] * src[1][0]);
100 inv[2][0] = + (src[1][0] * src[2][1] - src[1][1] * src[2][0]);
101 inv[2][1] = - (src[0][0] * src[2][1] - src[0][1] * src[2][0]);
102 inv[2][2] = + (src[0][0] * src[1][1] - src[0][1] * src[1][0]);
105 for( uint32_t i=0; i < 3; i++ )
106 for( uint32_t k=0; k < 3; k++ )
107 dst[i][k] = inv[i][k] / det;
118 for(
int i=0; i < 3; i++ )
120 for(
int j=0; j < 3; j++ )
124 for(
int k=0; k < 3; k++ )
125 dst[i][j] = dst[i][j] + a[i][k] * b[k][j];
136 inline void mat33_print(
const T src[3][3],
const char* name=NULL )
139 printf(
"%s = \n", name);
143 for( uint32_t i=0; i < 3; i++ )
145 for( uint32_t j=0; j < 3; j++ )
146 printf(
"%f ", src[i][j]);
171 for(
int row=0; row < rank; row++ )
173 if( mat[row][row] != 0 )
175 for(
int col=0; col < 3; col++ )
179 const T mult = mat[col][row] / mat[row][row];
181 for(
int i = 0; i < rank; i++ )
182 mat[col][i] -= mult * mat[row][i];
190 for(
int i=row+1; i < 3; i++ )
192 if( mat[i][row] != 0 )
194 for(
int k=0; k < rank; k++ )
196 const T tmp = mat[row][k];
197 mat[row][k] = mat[i][k];
210 for(
int i=0; i < 3; i++ )
211 mat[i][row] = mat[i][rank];
231 const T rad = 0.01745329251 * degrees;
233 const T c = cos(rad);
234 const T s = sin(rad);
335 return src[0][0] + src[1][1] + src[2][2];
372 inline void mat33_transform( T& x_out, T& y_out,
const T x_in,
const T y_in,
const T mat[3][3] )
374 const T x = mat[0][0] * x_in + mat[0][1] * y_in + mat[0][2];
375 const T y = mat[1][0] * x_in + mat[1][1] * y_in + mat[1][2];
376 const T z = mat[2][0] * x_in + mat[2][1] * y_in + mat[2][2];
401 for( uint32_t n=0; n < N; n++ )
412 for( uint32_t i=0; i < 3; i++ )
413 for( uint32_t j=0; j < 3; j++ )
414 dst[i][j] = src[j][i];
425 memset(dst, 0,
sizeof(T) * 9);
void mat33_cast(T1 dst[3][3], const T2 src[3][3])
Cast a 3x3 matrix from one type to another.
Definition: mat33.h:36
void mat33_transpose(T dst[3][3], const T src[3][3])
Transpose a 3x3 matrix, dst=src^T
Definition: mat33.h:410
void mat33_transform(T &x_out, T &y_out, const T x_in, const T y_in, const T mat[3][3])
Transform a 2D vector by a 3x3 matrix.
Definition: mat33.h:372
void mat33_shear(T dst[3][3], T sx, T sy)
Initialize a 3x3 shear matrix.
Definition: mat33.h:290
void mat33_zero(T dst[3][3])
Set a 3x3 matrix to all zero's.
Definition: mat33.h:423
void mat33_print(const T src[3][3], const char *name=NULL)
Print out a 3x3 matrix to stdout.
Definition: mat33.h:136
void mat33_swap(T a[3][3], T b[3][3])
Swap two 3x3 matrices inline, a=b and b=a
Definition: mat33.h:318
void mat33_scale(T dst[3][3], T sx, T sy)
Initialize a 3x3 scaling matrix.
Definition: mat33.h:262
T mat33_trace(const T src[3][3])
Compute the trace of a 3x3 matrix, returns tr(src)
Definition: mat33.h:333
void mat33_rotation(T dst[3][3], T degrees)
Initialize a 3x3 rotation matrix.
Definition: mat33.h:227
void mat33_identity(T dst[3][3])
Initialize a 3x3 identity matrix.
Definition: mat33.h:73
void mat33_multiply(T dst[3][3], const T a[3][3], const T b[3][3])
Multiply two 3x3 matrices, dst=a*b
Definition: mat33.h:116
void mat33_copy(T dst[3][3], const T src[3][3])
Copy src input matrix to dst output.
Definition: mat33.h:49
int mat33_rank(const T src[3][3])
Determine the rank of a 3x3 matrix.
Definition: mat33.h:161
T mat33_det(const T src[3][3])
Compute the determinant of a 3x3 matrix, returns |src|
Definition: mat33.h:60
void mat33_translate(T dst[3][3], T x, T y)
Initialize a 3x3 translation matrix.
Definition: mat33.h:344
void mat33_inverse(T dst[3][3], const T src[3][3])
Compute the inverse of a 3x3 matrix, dst=src^-1 It is safe to have dst and src be the same memory...
Definition: mat33.h:87