Saturday, September 1, 2007

as3mathlib (formerly WIS math libraries)

I've just imported the WIS mathematics library -- an excellent collection of mathematics routines -- onto Google Code. (You'll find the Actionscript 2 version of the library at its original site)

This library carries a BSD-ish license and includes support for

  • Geometric Objects and Intersection calculations
  • Integral and Differential equation calculations
  • Bezier, Quadric, Polynomial, Complex, Vector and Matrix calculations
  • Symbolic expression parsing

I'm converting the library to Actionscript 3 from Actionscript 2 as time and necessity allow. (That's converting as in getting it to work, and converting as in getting it to be object/pattern oriented). Right now it builds without errors and only a few warnings, but I haven't applied any of the unit tests or checked it for correctness or compatibility.

If you see the value of updating this well-thought out collection of functions, please get in touch and I will add you as a developer. The code is quite modular: it will be straigforward to take modest chunks and get them working independently. I wrote the original author and maintainer, who responded "By all means, continue in the evolution/integration of my library to support AS3" -- but please let me know of any other efforts to update this code, or if a similar or superior math library exists, so that I don't waste my time :).

Email me [flip at the mrflip with the dot and the com] or comment on this post if you'd like to pitch in!

Labels: , , , , , , , , , , , , , , , ,

Monday, August 20, 2007

Flex Demo: Matrix Math (and an error in the Actionscript docs)

I'm working on something that uses (an algorithm similar to) texture mapping, for which I want to precalculate the .invert() of a whole bunch of .transform.matrix objects. I'll post something about that in the next coupla days. Meanwhile, I found something perplexing in the Actionscript documentation but the possibility exists that I am just a dope so please point out an error in my reasoning. As you may know, you can represent any arbitrary combination of 2-D scalings, skews, rotations and translations using standard matrix operations. The Actionscript docs for the Matrix class mention this in passing, but has elements .b and .c switched: it should be
right: [ [a,c,tx] [b,d,ty] [0,0,1] ] and not wrong: [ [a,c,tx] [c,d,ty] [0,0,1] ].
I whipped up a MatrixMathDemo in flex to demonstrate the issue: and a writeup on Mathematical matrices and the actionscript Matrix transformations [PDF]. The 2d, 3d, 4th tabs compare the Matrix methods concat(), invert() and (deltaP/p)ointTransform() respectively with an explicit calculation of the corresponding Matrix operation: they show that in fact the documentation has b and c switched. (The code is free to reuse or modify (but give credit) in case that's useful.) Some references:

Labels: , , , , , , , , , , , , ,