# dmMath

by Nickr5
A library for DM with basic mathematical functions.
 ID:109090   Feb 3 2011, 9:00 pm Have suggestions? Submit your contributions, bug reports, and feature requests to the Google Code project. Also see the site for documentation. Go here to see the latest changes. dmMath includes finding averages, a ceiling function, conversions between radians and degrees, some trig functions (including atan2), linear interpolation, fractions, matrices, and more.
 Feb 5 2011, 2:51 pm Saw this on the front page. From skimming the code, I have a few suggestions about the Matrix datum: - Storing values in the vars list seems to me like poor form. I think it's more useful if you had it in a list, especially if someone was interested in the "raw" matrix for some reason, but also because it just seems less awkward. - Support for a matrix which isn't square would be nice, although I'm not sure how often they're used in game programming. - About computing inverse matrices, remember that if the determinant is 0 (i.e. the matrix is singular), the inverse does not exist. - Since you already have support for 2x2 & 3x3 determinant and inverse, why not add support for a general square matrix? I'm assuming you know how to calculate these, but if not you can look it up, it's very simple.
 Feb 5 2011, 3:02 pm The matrix will definitely see some improvements. Toadfish wrote: - Storing values in the vars list seems to me like poor form. I think it's more useful if you had it in a list, especially if someone was interested in the "raw" matrix for some reason, but also because it just seems less awkward. I agree that using the vars list is weird, however this was done so that you can access the Matrix's values using Matrix.M23 syntax instead of having to call a proc or access a list (though GetValue and SetValue procs do exist). - About computing inverse matrices, remember that if the determinant is 0 (i.e. the matrix is singular), the inverse does not exist. Hmm... I thought I added a check for that. At any rate you'd still just get a division by zero error. - Since you already have support for 2x2 & 3x3 determinant and inverse, why not add support for a general square matrix? I'm assuming you know how to calculate these, but if not you can look it up, it's very simple. Yeah it should have been this way from the start. I'll get rid of the dimension-specific types. Also note that code contributions are welcome at https://code.google.com/p/dm-math/!
 Feb 6 2011, 7:44 am Thanks for responding. I'll see if there's something I can contribute to the code project later. I see you have Determinant/Inverse calculation now :). Also, another thing about matrices - if you allow matrices of unequal m,n dimensions, you also pretty much get built-in vector support for free. With built-in vector support - you also have complex number support for free, which might allow for a more hierarchical program structure.
 Feb 7 2011, 5:49 pm Your matrix datum stores it's values as a DM 2D list. This is extremely wasteful. You should use a single dimension list and perform a simple calculation to determine where a 2D location would be in a 1D list (((y - 1) * width) + x). That way you don't have row x column number of lists (which only have 1 element in them anyway)
 Feb 8 2011, 10:35 am Koil wrote: That way you don't have row x column number of lists (which only have 1 element in them anyway) Right now I'm pretty sure there are only rows + 1 lists for every matrix, but you're right that this is wasteful. Thanks for your advice, I'll make the changes!