Matrix operation

Started by Sloothword, May 05, 2006, 12:58:43 PM

Previous topic - Next topic

Sloothword

Hi
Excuse me for my stupid question, but i'm searching a method, which does exactly the opposite of SimpleVector.matMul

Example:



Matrix m =new Matrix();
m.rotateX((float)(0.5*Math.PI));
SimpleVector v1=new SimpleVector(0,1,0);
v1.matMul(m);


What had I to do with v1 to get the startvalue of (0,1,0)?
I think it has something to do with .invert, but i'm not sure how to use it.[/code]

EgonOlsen

invert the matrix and multiply it again with the result of your first mul. That should work. If it's a rotation matrix only, you may use invert3x3 to save some cycles.

Sloothword

I already tested this, but something must be wrong with my code:


Matrix m =new Matrix();
m.rotateX((float)(0.5*Math.PI));
SimpleVector v1=new SimpleVector(0,1,0);
v1.matMul(m);

m.invert3x3();
v1.matMul(m);

JOptionPane.showMessageDialog(null, v1, "v1", JOptionPane.ERROR_MESSAGE);


In the messageDialog v1 is (0.0,-1.0,8.742278E-8) and i thought it should be (0,1,0).

EgonOlsen

invert as well as invert3x3 don't modify the matrix itself but return the inverted one. Try m=m.invert3x3(); instead. In any case, it may happen that 0 or 1 or not exactly transformed back to 0 and 1 but to something very close to these value. That's due to the limited accuracy of floating point values and nothing you should worry about.

Sloothword

I thought it works like SimpleVector.matMul()

Thanks a lot for your fast reply