Fork me on GitHub
Not signed in (Sign In)
    • CommentAuthorColin
    • CommentTimeMay 24th 2011
    Hi Richard,

    I've been working recently on 2D simulations of liquids, which involve high particle densities. I noticed that in these simulations the particles spontaneously adopt a configuration in which a gradient in particle density is present from left to right (more particles/area on left; fewer particles/area on right). You can see a very simple simulation that illustrates this here:

    As is clear from this simulation's source (which I've included at the bottom of this message), only the Move, Collide, and BoundingBox actions are used. I have taken note of the caveat you included in the source for the Collide action, so I guess the question here is whether the behavior described and demonstrated above is really a bug or whether the system is behaving as designed. If the described behavior is consistent with your design, perhaps you could suggest some changes I could make to the Collide action that would mitigate the gradient-forming tendencies of the system as it stands.


    =============Begin Source Code===============

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx=""
    minWidth="500" minHeight="500"
    frameRate="60" xmlns:debug="org.flintparticles.common.debug.*">

    import org.flintparticles.common.displayObjects.Dot;

    <f:DisplayObjectRenderer id="renderer" width="500" height="500">
    <f:Emitter id="emitter" autoStart="true">
    <f:Blast startCount="800"/>
    <f:RectangleZone top="10" left="10" bottom="490" right="490"/>
    <f:DiscZone centerX="0" centerY="0" innerRadius="50" outerRadius="80"/>
    <f:ImageClass imageClass="{Dot}" parameters="8"/>
    <f:CollisionRadiusInit radius="8"/>
    <f:MassInit mass="1"/>
    <f:ColorInit minColor="0xFFFFFFFF" maxColor="0xFFFFFFFF"/>
    <f:BoundingBox left="0" right="500" top="0" bottom="500"/>
    • CommentAuthorRichard
    • CommentTimeMay 26th 2011 edited
    Hi Colin

    To improve performance on collisions and other algorithms that involve interactions between particles the particles are sorted based on their x coordinate. As a result, when these algorithms are applied small errors occur because they are applied to the particles on the left side of the screen first. Most of the time the error is unnoticeable, but occasionally it is apparent, as you found in your example.

    Your message prompted me to find a solution, and the one that has minimal impact on the performance is to alternate the direction in which the particles are processed, applying them left to right in one frame and then right to left in the next. I've implemented the fix and it's in the Github repository. The commit information is here.