jnxd wrote: ↑Wed Jun 22, 2022 3:58 pm
This is a point of contention though:
matrices shouldn't explicitly be inverted. Ideally there should be a function that solves an equation
Ax = b where A is our matrix, for example, by LU decomposition. Otherwise we're quickly looking at large round-off errors.
I kinda agree, but the main point is that we are dealing here with very small matrix (and with size being known)...
- About the speed of the operation :
Yes, there is a 3 time ratio between both way, but I often need to solve one given system for many inputs : example : if I when to change the origin of multiples points (lets says a mesh), I need to take the inverse matrix of the transform of the target origin, then multiply by all the point in my mesh to get the work done. At this point I'm way better off computing the inverse matrix once and multiply by all my point (granted, it's faster only if I have more than 3 point in my mesh, which is often the case)
Moreover, given the figure 2 in "Numerical experiments", if I look at the curve for n=4, I get only negligible value, so I'm not sure if it's worth it... Yes, 3 times faster is 3 times faster, but I mean FreeCAD is not aimed at inverting matrix, and other stuff will take significantly much more time...
- About the loss of accuracy :
Given the figure 3 in "Numerical experiments", if I look at the curve for n=4, the error doesn't seems to be such a big deal, IMHO
- About our use case :
I do think (but I could be vastly wrong) that more often than not FreeCAD matrix are often transformation (rotation/translation...), and might be well invertible (ie well-conditioned) (but don't quote me on that). (and for my use case, I should replace the inversion of rotation matrix by transpose, but I'm too lazy now xD)
Having say that, it will not harm to add a matrix.solve(vector) method that will compute matrix.inverse()*vector, using the fast way
Whatever the conclusion is, invert() and inverse() should continue to exist, but should behave correctly, as described earlier !
That my 2cents !
PS: @jnxd I did start a work of cleaning up the
https://github.com/FreeCAD/FreeCAD/blob ... Matrix.cpp file, which contains the code to inverse a matrix
https://github.com/FreeCAD/FreeCAD/blob ... x.cpp#L492. But I'm not so confident to work on that part of the code... If you feel up the task, we might join forces
I've exposed my thought here :
https://forum.freecadweb.org/viewtopic. ... 55#p568155 and the branch :
https://github.com/ShuffleWire/FreeCAD/ ... ean_matrix