Pages

Wednesday, 3 March 2010

3D Waves: Projected 2D fluid simulation

I found this experiment quite interesting. In an earlier post I gave an example of a 2-dimension fluid simulation that I'd been working on using the Navier-Stokes equations. I decided to play around with this code a bit and use the 3D point engine from my last experiment in conjunction with the fluid engine. The density from the fluid simulation is simply projected onto the XZ plane with density values corresponding to the height of corresponding point particles.

The results are certainly interesting. Click the image below to start up the experiment. To create waves just move your mouse around and drag the movie to change the camera angle. I decided to add a slight fade and blur on the particles which makes it look very pretty. Enjoy!

3 comments:

  1. Hi

    I couldn't find your email address anywhere on your page so Im just going to write here:

    This is a very niche wave simulation, would it be possible to take a look at the source ? Also your particle 3D grapher (3D particle systems in AS3) - would be interesting to see. If by any chance that is possible you are more than welcome to send me a link or some files at samialbeik at gmail.com

    ReplyDelete
  2. Hi Sami, you've just alerted me to the lack of contact details on this site!

    Glad you like the simulation! A great place to look is here http://code.google.com/p/in-spirit/wiki/FluidSolver
    which has complete source to a fluid solver by Eugene Zatepyakin. I'll try to dig up some source code for the 3D stuff, I'm currently very busy at university, sorry for the late reply!

    Cheers

    Sam

    ReplyDelete
  3. Oh and this code should get you started on 3D stuff, it loads any .obj file (a wavefront 3d object, you should be able to download some for free online) and renders all the vertices which then move around the screen in 3D, its not in OOP unfortunately, but will paste nicely into your timeline and give you a good idea of what its doing:


    //focal length
    var f:int = 400;

    //rotation
    var u:Number = 0;
    var r:Number = 0;
    var d:int = 2500;

    //camera
    var cX:int = 0;
    var cY:int = 0;
    var cZ:int = 0;

    //position
    var tX:int;
    var tY:int;
    var tZ:int;

    //scale
    var s:Number;

    //Vector co-ordinates
    var X:Vector. = new Vector.();
    var Y:Vector. = new Vector.();
    var Z:Vector. = new Vector.();

    var NUM_P:int = 0;

    //counters
    var i:int;
    var j:int;
    var k:int;

    //------------------------------------
    //Populate 3D Data
    //------------------------------------

    //Load OBJ File

    include "OBJ.as"

    //save data into arrays...

    var A:Array = new Array();
    A = OBJ.split(",");
    var l:int = A.length-1;
    for(i=l;i>=0;--i)
    {
    if(A[i].indexOf("v ")==-1)
    {
    A.splice(i,1);
    }
    }
    l = A.length;

    var LL:int = Math.ceil(l/10000);

    if(A[0].split(" ").length==4)
    {
    for(i=0;i2*Math.PI) r-=2*Math.PI;
    if(r<0) r+=2*Math.PI;

    for(i=0;i0];
    }

    ReplyDelete