### Author Topic: Matrix operation  (Read 2476 times)

#### Sloothword

• byte
• Posts: 12
##### Matrix operation
« on: May 05, 2006, 12:58:43 pm »
Hi
Excuse me for my stupid question, but i'm searching a method, which does exactly the opposite of SimpleVector.matMul

Example:

Code: [Select]
`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

• Administrator
• quad
• Posts: 11777
##### Matrix operation
« Reply #1 on: May 06, 2006, 09:06:42 pm »
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

• byte
• Posts: 12
##### mistake in my code
« Reply #2 on: May 07, 2006, 09:35:01 pm »
I already tested this, but something must be wrong with my code:

Code: [Select]
`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

• Administrator
• quad
• Posts: 11777
##### Matrix operation
« Reply #3 on: May 07, 2006, 10:15:46 pm »
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

• byte
• Posts: 12
##### Oh no
« Reply #4 on: May 08, 2006, 04:04:42 pm »
I thought it works like SimpleVector.matMul()

Thanks a lot for your fast reply