dmMath

by Nickr5
A library for DM with basic mathematical functions. [More]
To download this library for your Linux/Mac installation, enter this on your command line:

DreamDownload byond://Nickr5.dmMath##version=2

Emulator users, in the BYOND pager go to File | Open Location and enter this URL:

byond://Nickr5.dmMath##version=2

183 downloads
Version 11.3.14
Date added: Feb 3 2011
Last updated: Mar 14 2011
0 fans
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.

Comments

Nickr5: (Feb 8 2011, 11: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!
Koil: (Feb 7 2011, 6: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)
Toadfish: (Feb 6 2011, 8: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.
Nickr5: (Feb 5 2011, 4: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/!
Toadfish: (Feb 5 2011, 3: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.