Advertisement

How to get the transpose of 3x3 matrix?

Started by June 27, 2005 05:43 AM
3 comments, last by ajas95 19 years, 7 months ago
Hi I've got a 3x3 matrix and Im suppose to get the transpose for other calculations. Except I'm not really sure what the tranpose of a matrix is. So what would be the output of a transpose of a matrix? eg if ihad the values in the matrix like so: m11, m12, m13 m21, m22, m23 m31, m32, m33 Thanks
Transpose matrix is simply:
m11, m21, m31
m12, m22, m32
m13, m23, m33

switch rows with columns, and that`s it...
Bulma
Advertisement
in code:

	public static int [] [] MatrixTranspose ( int [] [] A  ){		int [] [] TransposedMatrix = new int [ A.length ] [ A[0].length ];		for ( int a = 0 ; a < A[0].length ; a++ ){			for ( int b = 0 ; b < A.length ; b++ ){			        int temp = A [ a ] ;<br>				A [ a ]  = A  [ a ];<br>				A  [ a ] = temp;<br>			}<br>		}<br>		<span class=cpp-keyword>return</span> TransposedMatrix;<br>	}<br><br></pre></div><!–ENDSCRIPT–><br>Hope this helps
(0110101101000110)The Murphy Philosophy: Smile . . . tomorrow will be worse.
Here is the function I use to transpose matrices in my math lib.
inline void matrix::transpose(void){		matrix T = *this;			M12=T.M21;	M13=T.M31;	M21=T.M12;			M23=T.M32;	M31=T.M13;	M32=T.M23; }
here's mine.

// input xyz in xmm5,7,6// output in xmm0,1,7// ?? == don't care.                                   // xmm5 : ?? z0 y0 x0                                   // xmm7 : ?? z1 y1 x1                                   // xmm6 : ?? z2 y2 x2movaps	xmm0,	xmm7		   // xmm0 : ?? z1 y1 x1movaps	xmm1,	xmm5		   // xmm1 : ?? z0 y0 x0unpcklps xmm0,	xmm5		   // xmm0 : y1 y0 x1 x0unpckhps xmm7,	xmm5		   // xmm7 : ?? ?? z1 z0movhlps	xmm1,	xmm0		   // xmm1 : ?? z1 y1 y0shufps	xmm7,	xmm6,	11100100b  // xmm7 : ?? z2 z1 z0movlhps	xmm0,	xmm6		   // xmm0 : ?? x2 x1 x0shufps	xmm1,	xmm6,	01010100b  // xmm1 : ?? y2 y1 y0


3x3 transpose is super-useful in SSE for computing simultaneous dot-products and having the result set up for another parallel operation (like rsqrtps for doing parallel vector normalizes). So this is a good one to remember!

(P.S. If anyone has a faster way, I'd love to hear it. This uses 5 registers, and so destroys one of the inputs. Still, it's a great problem for people that are into this sort of thing).

This topic is closed to new replies.

Advertisement