Does anyone have asm code for 'diagonalising' a (3x3) matrix (using Jacobi or any other method) ?
Posted on 2006-12-09 19:02:42 by Homer
I don't have the codes, but I know how to do it with pen and paper. Do you want me to help you code it?  ;)
Posted on 2006-12-09 19:09:40 by roticv
I'd love you to help me understand it.
All I really know is that it involves N iterations of matrix multiplications (and thus isn't suited to high-order matrices, but 3x3 is not so bad..)

Yes, I'm out of my depth here, I slept thru a lot of math..
Posted on 2006-12-10 02:30:24 by Homer
It's just all about finding the eigenvalues and respective eigenvectors. Well, give me some time and I'll try to come out with the code. Is that alright with you? (I need time as I can only do coding during the weekends)
Posted on 2006-12-10 05:14:30 by roticv
8)
Posted on 2006-12-10 09:16:03 by Homer
How is your mil. service going by the way, roticv?

Posted on 2006-12-11 14:57:51 by arafel
Homer,

Could you like attached the matrix codes that you have done? 3x3 would be fine. It will help me alot.

arafel,

I've sent you a PM.  ;)
Posted on 2006-12-15 11:56:38 by roticv
Here's something to look at I guess..
Attachments:
Posted on 2006-12-16 08:53:19 by Homer
Cool you have an eigenvector and eigenvalue function. Things aren't too difficult now.

Cause if you want to Diagonalise matrix A to

A = PDP-1

P = the 3 eigenvectors formed to a 3x3 matrix and D = the 3 respective eigenvalues

for example matrix A has eigenvalue of -1 with eigenvector (1 2 3) and eigenvalue of 1 with eigenvector (1 1 1) and eigenvalue of 2 with eigenvector of (1 2 2), then

P = 
      (1 1 1)
      (2 1 2)
      (3 1 2)

D =
      (-1 0 0)
      (0  1 0)
      (0  0 2)

P-1 can be found by finding the inverse of P
Posted on 2006-12-16 09:42:01 by roticv
I've got oodles of experience with 4x4 matrices, but haven't required dedicated 3x3 matrix support until recently.. I was extremely disappointed in the lack of generic support for this, and decided to write a set of helper macros with a longer-term view of wrapping them into a larger math support library.

The Eigen function hasn't been tested yet..

I've put together support code for Vec3, Mat33 and Quaternions, mostly in macro format.. the larger, more common functions have been written as procs.
Once all has been tested to my satisfaction, I'll be handing them all to Biterider for inclusion in the next release of OA32.

Anyone who has an interest in this stuff is welcome to help test and debug the beta sourcecode - as usual any source posted by me (either here on this forum, or as part of OA32) is 100% free, use it as you wish.

If you're willing to look over the source, make corrections, suggestions, optimizations, whatever, let me know and I'll start posting daily updates.
Posted on 2006-12-16 23:31:03 by Homer
Homer,

Don't worry. hmm the eigenvalue and eigenvector function is not tested yet? That's really sad. Maybe I'll test them out next week - it is a long break for me (Whee Christmas!).

I'll be willing to help out. Will ask you on IM for your copy...  ;)
Posted on 2006-12-17 03:51:24 by roticv
I'm using 3x3 matrices to represent (moment of) inertia tensors which are useful in regards to rigid body physics simulation.. my priority is to complete the framework for arbitrary rigid bodies, and that's the primary reason why I'm bothering to write up all this support code, particularly the diagonalising function.
The process of diagonalising an inertia tensor actually performs three jobs at once - it finds the principle axes of the rigid body, it aligns the center of mass with the origin of the principle axes, and (less obviously) it allows us to reduce the inertia matrix from a 3x3 matrix into a 3D vector for smaller storage at runtime... not that I've bothered to optimize memory use , my purposes don't demand it, and I'm not sure that the memory versus speed tradeoff is worth the effort :P

Posted on 2006-12-17 08:51:28 by Homer
Well I had guessed that you are using the 3x3 matrix for tensors. Do you have any links to diagonalising of an inertia tensor?
Posted on 2006-12-22 00:53:06 by roticv
Biterider gave me an excellent link to a linear solution that's supposed to work for these (assumed symmetrical) matrices, but unfortunately I've lost it :( maybe he still has it..

Anyway, I didn't use it, I implemented 'Jacobian Diagonalization of 3x3 Matrix' ..
We have a 3x3 matrix which contains the following:
Ixx, -Ixy, -Izx
-Ixy,  Iyy, -Iyz
-Izx, -Iyz,  Izz
which is our input inertia tensor.. notice its symmetry.

We want to find a Matrix containing the following:
'Ixx, 0,  0
0,  'Iyy, 0
0,  0,  'Izz
ie a diagonalized matrix where '(Ixx,Iyy,Izz) = eigen values
and the eigen vectors represent the rotation from I to 'I

The Jacobian method involves 'rotating away' the off-diagonal fields in order to make them zero.
I'll see if I can dig up some links on this solution.. note I've done some debugging/modifying of the math helpers, and am currently debugging my Jacobian Diagonalize function.. somethings screwy.

Posted on 2006-12-22 03:09:14 by Homer