To calculate the total linear force on a single rigid body, simply sum all the forces of each particle that belongs to that rigid body. [1]
$F_{total} = \displaystyle \sum_{i=0}^N f_i$
And the total torque can be calculated by summing up the cross product of the linear force with the radius from the center of mass for each particle. [1]
$F_{torque} = \displaystyle \sum_{i=0}^N ((pos_i-pos_{com}) \times f_i)$
Currently I don't have any constraints implemented. Also, I still need to implement the segmented scan to improve the calculation of force totals on the rigid body. Currently I naively loop and sum for each rigid body which is inefficient. I also need to create a renderer which will render rigid body meshes at the appropriate locations.
Here is a video of my progress so far.
Rigid-body and Fluid interaction with velocity vectors from Andrew Young on Vimeo.
In the video above, I render the velocity vectors of each particle. This helps to visualize the flow of the fluid. I plan to create a separate blog to discuss my implementation of the rendering code for the velocity vectors.
The interaction between fluid and rigid-body is modeled by a spring/dampening system. The calculations are based on the following two equations as described in [1].
$f_s = -k(d-r_{ij})\frac{r_{ij}}{\left|r_{ij}\right|}$
$f_d = \eta(v_{j}-v_{i})$
Where k is the spring constant and $\eta$ is the dampening coefficient. I need to experiment with these coefficients to get more accurate results.
I also focused a lot of time to refactoring the code around the System class. The System class was abstract and had very little functionality. When creating the rigid body class, I noticed I was just copying and pasting a lot of code. That was a perfect reason to push things up to the parent class.
I moved a lot of generic functionality as well as several buffers (position, velocity, force) that were common to all systems up to the System class. I then added some rudimentary code to all for interaction between systems. Currently this only works between SPH and Rigidbody systems. Eventually, I hope to have a better interaction framework where you can define new rules of interaction quickly and easily. Then I could add interaction between Flocks and SPH which could provide some very interesting simulations.
Todo:
- Verify spacing of the rigid-body system is correct.
- Experiment with coefficients for interaction.
- Explore the alternative formulations for system interaction.
- Continue refactoring the code.
- Create a class to better handle particle shapes.
References
[1] Harada, T., Tanaka, M., Koshizuka, S., & Kawaguchi, Y. (2007). Real-time Coupling of Fluids and Rigid Bodies. Proc of the APCOM, 1-13. Retrieved from http://individuals.iii.u-tokyo.ac.jp/~yoichiro/report/report-pdf/harada/international/2007apcom.pdf
[2] Fang, S., & Chen, H. (2000). Hardware accelerated voxelization. Computers & Graphics, 24(3), 433-442. Elsevier. Retrieved from http://www.sciencedirect.com/science/article/pii/S0097849300000388