# FOSS tools for creating high quality physics animations and simulations in 2d and 3d

If I want to create a high quality figure to illustrate a scientific concept or experiment I usually use tikz together with pgfplots or pstricks. However this is for static content. Both tools are extremely powerfull for it's purpose and give high quality results. Furhtermore there is a large database of examples, very good documentation and a huge, active user community around those projects.

What would be the "equivalent" of this for creating physics animations or simulations?

I want to start with 2d and 3d animations and simulations like found on the following pages (but possibly looking a bit more high quality):

and then proceed to more complex things when I get how to use it.

So what would you recommend for this task and why? I have little bit background in python so I would prefer this but if there is a "killer tool" for this, it would be ok to learn a new language from scratch. Here are the requirements:

• free and open source (FOSS) and should run on linux
• it should be a good interface to recreate the examples from the three cited web sites above (with the potential to make even more complex things)
• like for tikz in the case of static content there should be good documentation and a large active user base
• I need something for 2d and also for 3d

Concerning the difference between animations and simulations, I think that there should be no difference because for a simulation I have to solve a differential equation first (using another library, for example numpy/scipy) and then animating the data. So one could reduce the term "simulation" to "animation" for this question (or did I overlook something?).

Sure I googled for this, but the problem was that got I a very long list of packages and I am not sure where to start. For the static content it was easy as described above, but here I don't see, what would be worth to learn in detail.

Since I have a little bit python experience at first I narrowd the search down to this language.

• The only tool I found made for this purpose is vpython, which I tried. However the results didn't look very professional compared to what I was used to get for static content with tikz.

• Then I found some nice plotting tools like mathplotlib, mayavi, bokeh, chaco, nodebox, pyqtgraph, vispy, protovis and visvis which possibly could be used to make animations but I am not sure if this is a good way since they seem to be more suited for static plotting

• The next category I found were game engines like pygame or pylet, panda3d or python-ogre. I am not sure if it is a good idea to use a complete gaming environment like this for physics animations.

• Another possibility would be to use just the OpenGl bindings for python directly: pyopengl

• Then there is blender

• Finally there seems to be much specalized tools like pymbs, pyblocksim or pyOpTools

However the most physics animations or simulations I can find on the web are java applets. Most of them closed source so I didn't find out which java libraries were used for them. The only one was ejs which has a graphical user interface but which looks a bit old fashioned.

Finally I considered using html5 for this.

• The best tool in terms of how fast one can make simulations I found is Mathematica. Some examples here demonstrations.wolfram.com a free plugin is needed to be installed in your pc to run these. – Nasser Jun 9 '14 at 15:44
• Yes, but mathematica is not FOSS – Julia Jun 9 '14 at 15:53

For my work, I tend to have programs output a sequence of still images, and I then convert them to an animated format in a post-processing step. To make a video, I use ffmpeg (http://www.ffmpeg.org/); to make a .gif, I use imagemagick (http://www.imagemagick.org/). Both of these tools are easy to script from the command line. There are numerous tutorials available that demonstrate this process for each program.

• This ^. Both IM and ffmpeg are very easy to install (at least on Linux) and use. – stali Jun 10 '14 at 14:07

I think the basic ideas behind this question are extremely valuable (the question should be made a bit more precise, though), and it'd be nice to see an answer in a community wiki-style format, with a list of software and a short explanation of each item. Below, however, are my ramblings and personal experiences.

# 2D animations

As you are already aware, LaTeX with TikZ/PGF in particular, can produce very high quality plots. I typically use PGFPlots to graph the final figures for academic papers and such, where anything but static graphics is not possible, anyway. Note, though, that you can in fact produce animations in LaTeX (PGFPlots), as attested to by the many questions in TeX.SE (yes, it's quite bug-prone). You can also plot simple 3D images in PGFPlots. Slightly more interactive, and 3D, graphics can be produced with Asymptote, a language that interfaces very well with LaTeX. There is a downside: the only reader that can display these with all of their properties is, to my knowledge, Adobe Acrobat.

Then there are the different programming languages and their different plotting backends: Python, Julia, R, and Octave, to name a few of the ones scientists commonly use for their graphical features. Many of these probably if not default, at least can use, gnuplot and should be able to graph in 3D. Most explicitly support animations, and the ones that do not, support printing out static images which you can then ffmpeg/avconv/mencoder into a video (this is what the libraries that provide a frontend for animations usually do behind the scenes, anyway).

Now one of the reasons that the output of LaTeX is of such high quality is that its default output format is PDF, which can store vector graphics. It should be noted that most other programs made for plotting, too, can output vector graphics, but png and other lossless raster graphics are usually the default. With animations in their most common file formats, .gif, .avi etc., though, you lose the ability to produce vector graphics. Well, not quite, I already did mention that PDF does support some simple animations.

Better yet, SVG, the most common vector graphics format, can work wonders: You can even program whole games just using the features of SVG, so animations are easy-peasy. I have in fact largely switched from Beamer to HTML5 (SVG being a part of HTML5, in a way) when preparing presentation slides mainly because of its support for animations (both ones interactively generated by the document itself, but also because with HTML5, embedding .avis is hassle-free). What I have found particularly useful is D3.js, a JavaScript library for displaying data (in SVG). It can do much more than just simple plots so its usage can get a bit unwieldy at times. That said, the library is extremely well documented, and already has books written about it. C3.js is a simpler interface for D3.js for plotting charts, but I found it to have been designed with business charts in mind, and seem to remember that setting the x-axis, y-axis scalings and data was not particularly easy.

# 3D animations

If you really want quality graphics with lens flare like you're J.J. Abrams, and this applies for 2D as well, vector graphics won't cut it: You'll most probably want to use some image filters and very few are available in vector format. Now in 2D this usually is not an issue (unless you want to include a photograph), but for 3D perspectives such filters help a lot. There are a few ways of producing vector graphics that look 3D-ish; for example Sketch for LaTeX or the PostScript output of MolScript to name a couple, but these are often application specific and don't come even close to emulating different sorts of materials etc. What you'd really want, then, for presenting any 3D data which you want to look artistic or realistic rather than just a sketch, is ray tracing.

I like POVRay, it's open source, well documented, and easy to use. I say easy to use, but it might take some figuring out how to use it with scientific data as it was not built with that audience in mind, but it can be done. A popular one in molecular dynamics (MD) simulations is Tachyon as it was built of this particular purpose. It comes with VMD, one of the most popular viewers of MD data.

# Simulations

What I wrote above is really only about static animations: Ones you make but later cannot affect, like an .avi file (the part about SVG/D3.js, though, works interactively). Why? Because the simulation details will depend on the platform: Do you want a website or a downloadable demonstration of some physical phenomena? Or do you perhaps have a simulation API and want to interface your own interactive graphics to it so that you might affect the simulation and see what's happening?

If you want to deploy online, yes, nowadays you'd probably want to use HTML5 (building the simulation in JavaScript and interfacing it with some SVG or canvas based solutions, for example through D3.js). For 3D you'd probably use a WebGL library. If you're happy with offline, then there are thousands of libraries out there, many built on OpenGL.

I have used matplotlib quite a bit though not for animation. However, I think the matplotlib animation module allows you to turn any programmatically created sequence of images into an animation.

As an example see this animation of the wavefunction of a particle bouncing off a potential barrier (and partly tunelling). Its creator also wrote a brief tutorial.