tomstewart89 / BasicLinearAlgebra

A library for using matrices and linear algebra on Arduino
MIT License
185 stars 38 forks source link

Inverse Matrix 3x3 false #51

Closed muhammadfaiz-sby closed 2 years ago

muhammadfaiz-sby commented 2 years ago

Hello, im' new here, also i'm using this library. but during use invert function, isn't as i expected. i inverse matrix 3x3 rot={1, -1, 0, 1, 0, 0, 0, 0, 1}; inv_rot=Invert(rot); the result : pop: [[1.00,0.00,0.00],[0.00,0.00,0.00],[0.00,0.00,0.00]] using wolfram online, i got true inverse matrix is : {0,1,0,-1,1,0,0,0,1}, here is my arduino code :

include

include

float j=1.57079672; using namespace BLA; void setup() { // put your setup code here, to run once: Serial.begin(9600); }

void loop() { // put your main code here, to run repeatedly: BLA::Matrix<3, 3> rot; BLA::Matrix<3, 3> inv_rot; rot={1, -1, 0, 1, 0, 0, 0, 0, 1}; inv_rot=Invert(rot); Serial << "pop: " << inv_rot << '\n'; }

thankyou,,,

edit: i tried the 3.5 version, there isn't problem,

tomstewart89 commented 2 years ago

Hey @muhammadfaiz-sby, glad you got the matrix inversion working ok, indeed there was a bug in that function up until v3.4.

On another note, if I'm interpreting your code correctly it looks like you're trying to invert a rotation matrix. If that's the case you can take advantage of the fact that rotation matrices are Orthogonal matrices so you compute their inverse much more efficiently by just taking the transpose, like so:

inv_rot= ~rot;

Having said that in the matrix you showed in the example doesn't seem to be an Orthogonal matrix so maybe you're trying to represent a different transformation? Or perhaps should rot instead be: rot={0, -1, 0, 1, 0, 0, 0, 0, 1};?

Either way it seems like this issue is resolved so I'll go ahead and close it. Let me know if you have any more trouble :+1:

muhammadfaiz-sby commented 2 years ago

yes, i'm trying to invert a rotation matrix. it works using inv_rot= ~rot; thank you.....