CS 184: Computer Graphics and Imaging, Spring 2017

Milestone: 3D Position Based Fluid Simulation

Bosen Ding, CS184-abp, Sijia Teng, CS199-djl

Current Progress

In past two weeks, we have first tried to find starter code for 3D particle-based fluid simulation. We have downloaded three starter codes online and tried to get them work, but none of them works. They all require installation of CUDA, but we fail to install CUDA on our machines.

GUI, Scene, and Simulation Setup

After the starter code from last year is available on Piazza, we first familiar ourself with the code. The starter code gives us the Particles structure to manipulate the particles, and a simple GUI. So what do need is to enable the GUI with more functions and render a scene for the simulation setup.

For GUI, we add a keyboard controled zoom in / out function in addition to rotation.

To render the scene, we use 6 planes to form the box frame where the water particles are restricted inside. Five of the planes are rendered in colors, except the front plane remains transparent to ensure a better view. We modify the code so that the constant setups for the particles and the scene is easy to control.

To setup the simulation, we initialize the particles with a velocity and an external force, and do position update using explicit Euler's method in each step. Then we perform the bouncing detection and response of the particles and the planes which is introduced in section 1.2, and also also use it to debug the neighbor finding function which is introduced in section 1.3.

The Planes Structure

After we ensure that the particle position and velocity can be updated correctly according to external force, we then proceed to implement the bouncing effect with the surface of the box. The functions are implemented in the Planes structure. The Planes structure includes the follwing functions:

  • Rendering: Render all the planes given scene parameters
  • The Plane Structure: Set the related variables (point, normal, bounce detection and responce functions with single plane, etc) related to a single plane
  • Planes initialization: Define an array of all the six planes in the scene, compute the point and normal vector of the plane based on the scene parameters
  • Bounce detection and responce: Check bounce with all the six frames in a time step and update the new velocity and position

We first notice that the particles sometimes bounce out of the box. The problem results from that the particle might bounce twice within the time step and thus we have to double check to handle the multiple bounces of the particles with the box surface. Another reason is, since the sign-change method we use to detect collision may result in a small float value close to zero, the sign is not stable.

The Bounding Box System for Neighbor-Finding

After ensuring the particles are strictly within the box, we then proceed to implement the finding neighbor part of the code. We have dealt three problems in this part.

  • The first difficulty we have is that floor(a/b) sometimes does not give correct number due to floating precision issue. We solve this problem by replacing with int(a/b). We are not sure why this works, but it seems working correctly.
  • The second problem also arises from the floating issue. When comparing distances like a <= b, we have to use a <= b + EPSILON in order to get correct answer.
  • The third problem we have in this part is pointer issue. If we directly assign value as class_A a = b[x][y], a would be a copy of b[x][y]. Thus when we modify a, b[x][y] is not updated correctly. Instead, we need to use the pointer or reference to modify b[x][y].


We have included screenshots of movements of particles after random initialization due to some external forces.

Updated Schedule

Unfortunately, we did not follow our previous plan strictly, so we update our plan below.

By April 30, we plan to finish implementing the algorithm, and get the fluid simulation running.

By May 2nd, we plan to finish the poster and the first draft of the final paper as well as the final website.

By May 3rd, we plan to publish our final website, submit the final paper.

slides for milestone report can be found  here.

video for milestone report can be found  here.

milestone report can be found  here.


Miles Macklin and Matthias Müller. Position based fluids. ACM Trans.Graph., 32(4):104:1–104:12, July 2013.

Past class project website. Water simulation

Two MacBook Pro and lab instruction machine in Soda 349.