Thursday, September 8, 2011

Three.js and jsFiddle

So, the previous post touched on the fact that all of the free or open-source math and computer algebra environments that I've been looking at are a bit weak in the general 3D polygon mesh visualization department.  Since the purpose of the blog is to put up things people can immediately see and play with, I thought I'd see what was at hand these days for 3D visualization directly in the web browser.  Without too much effort, I found Three.js and jsFiddle.  Taken together, they can make toys like this:


Here, Three.js provides a nice browser-neutral 3D JavaScript library.  It can render via any of WebGL, HTML5 Canvas, or SVG back ends, to various levels of capability.  I've chosen SVG here, so this example should even work in Internet Eplorer :-)

JsFiddle provides a surrounding environment for web toys.  If you click on the "+" button above, you'll go off site to a full multi-pane view of the toy, where you can inspect and modify and play with the various parts of the HTML, CSS, and JavaScript.

I did hit one wrinkle to do with Internet Explorer 9, which I'll mention here in case anybody else runs up against it.  Originally, I was referencing Three.js from its canonical location on GitHub.  GitHub was exporting this with a MIME type of "text/plain", however, and it seems IE9 will no longer load <script> tags whose specified type does not match the MIME type of their source.  In the end, I needed to copy the script files I wanted to use to a different server that exports them as "application/javascript" to make things work correctly under IE9.

MATLAB alternatives

Okay, so I like MATLAB -- it's interactive, expressive, handles a lot of tedious math, and draws nice pictures. It's a little arcane (which can be fun in a sort of puzzling way) and it makes you think about everything in a sort of vectorized way to get decent performance (which can be fun in a sort of challenging way).

I used to have an old crusty copy for 32-bit Windows on some previous laptop from some previous job.  These days I'm using a MacBook (and 64-bit Windows when I have to) so I figured I'd go see about getting an updated copy for personal use...

$2,100.00 for a single, personal use license.  Are you f-ing kidding me?  I could buy a really nice bass for $2,100.00.  Y'know, for $200.00 I would have just bought MATLAB right away.  For anything up to $500.00 I probably would have just bought it after some serious thought...  For $2,100.00 -- no way!

I want to post snippets of mathematical code here from time to time, and I'd like students and non-millionaire-hobbyists to be able to conceivably grab those and play with them.  So to heck with MATLAB.  Started looking into free and/or open-source alternatives, and few that I played with were not that bad:

SciLab (http://www.scilab.org/)

Octave (http://www.gnu.org/software/octave/)

NumPy / SciPy (http://www.scipy.org/)

I'll comment more on these soon after I've had a little more of a chance to play around with them.  I'm probably leaning towards NumPy / SciPy, since so many people seem to be familiar with Python these days.

The most immediate weakness of all three of these seems to be the lack of a fully developed 3D polygon patch visualization system like MATLAB has (damn you, MATLAB!) so I guess I'll be looking elsewhere for that.