-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[raymath] Matrix determinant calculation speed up (enhancement) #4780
Comments
@raylibfan Thanks for the improvement, please, note that Please, could you review provided code to follow those rules? |
// updated version without calling extra functions
P.S. I made similar improvement to the Godot game engine. So I tested all versions of determinant calculation in a single test program: P.P.S. Today I found even more optimized version of 4x4 matrix determinant calculation with only 30 multiplication. It may be mathematicaly simplified version of my code. But I am not checked and tested it yet. But it worth looking. https://github.com/FreeCAD/FreeCAD/blob/main/src/Base/Matrix.cpp LINE 164 (they store matrix with indexes differently but as soon as we have a structure - it's seems work fine) |
@raylibfan thanks for the improvement, I updated the function! |
More then 2.0x faster Matrix determinant calculation can be achieved
In raymath.h line 1467 we have such realisation:
It takes 72 multiplication to calculate 4x4 matrix determinant as one can see.
Meanwhile, accordinly to this Wikipedia's article https://en.wikipedia.org/wiki/Laplace_expansion , this calculation can be reduced to (4 + 4 * (3 + 3 * 2)) = 40 multiplication by decreasing matrix size from 4x4 to 2x2 using minors.
Such algorithm is used in blender 3d application source code as for example: https://github.com/blender/blender/blob/main/source/blender/blenlib/intern/math_matrix_c.cc from LINE 1837
So we can replace those existing code fragment from above by something like this (using raylib function naming convention):
I wrote some simple test application to check perfomance boost. New or "blender style" function is more then twice faster, then current "raylib style".
Issue Screenshot
P.S. I am crab-handed and can not provide a PR :)
The text was updated successfully, but these errors were encountered: