Statistical physics in 2D world: How to simulate gas and its interaction with objects? (game design)

  • #1
XNTEABDSC
4
1
TL;DR Summary
For a 2D game, how to simulate gas and its interaction with objects?
I want to make a 2D game with gas (stardust) simulation. (I'm lazy to learn statistical physics and integrate thing by my self so) I want to know how gas spread, and how gas interact with circle object.

There will be 2D square grid. Each cell contains values of the state of the gas (a struct GasCell). I expect the values are (assume we have a list of atoms, each atom has mass ##m## and velocity ##v##. ##\sum_A## means for each atom)
V:Volume(in 2D it means area)
M:Total Mass
Momentum: ##\sum_A(m_A \cdot \vec{v_A} )##
Kinetic energy: ##\frac{1}{2}\sum_A(m_A \cdot v_A^2 )##
If you find better choice, fell free to use them.
##d GasCell## means state changes of states of gas

All objects in the game are circles (a struct Body).
Mass,Radius,Velocity,Angular Velocity, and Velocity Variance? or Temperature?

We consider classical mechanics only.
I want to know following situations. (if you need, dt=1/32s)
fn evaluate_over_time(GasCell) -> 5 d GasCell :how the gas cell and its neighborhoods change over dt.
fn interact_with_object(GasCell,Body) -> (d GasCell,d Body) :how the gas cell and object change over dt.
fn receive_momentum(GasCell,Momentum)-> d GasCell :how the gas cell changes when receive momentum, assume all atom receive same dv.(##GasCell.Momentum+=Momentum##,##GasCell.Kinetic+=\frac{Momentum}{ GasCell.Mass}(1/2 Momentum + GasCell.Momentum)##. is this true?)
fn mass_transfer(GasCell,Body,MassFromGasCellToBody) -> (d GasCell,d Body) :how the gas cell and object change when some mass are transferred from gas cell to body (e.g. use gas to build ship).(easy)

Notes that we just need simulation that is close enough to the real state (e.g. While a object contacts multiple gas cell, I will only calculate interaction between it and the gas cell where object's center is).

You can expect that the diameter of circles is smaller than the length of side of gas cells.

If you want to write code directly, I'm using rust and crate fixed and cordic, while it is ok if you write them in another language. If you find out that use code directly (e.g. simulates 100 atoms) is faster than formulas and precise enough, then use code.

About the game: It is a rts game where stardust is the resource to build units.
There may be 64x64 grid of gas and about 1000 objects in the game.

Notes again that all of this is in 2d world. (If you can let it run in 3D world, and know how to control units well, please tell me)
 
Physics news on Phys.org
  • #2
In the case the system is closed and there is no circle object but gas molecules, in COM-IFR,
[tex]M=\sum_A m_A[/tex]
[tex]P=\sum_A m_A \vec{v_A}=0[/tex]
[tex]2E=\sum_A m_A \vec{v_A}\cdot\vec{v_A}[/tex]
In case ##m_A=m##, a single kind of gas, the last formula means a shell of 2N dimension sphere where N is number of molecules.
Next we may include the circle object in A as if it is a newly added molecule.
Do you need more relations to construct your model ?
 
Last edited:
  • #3
Sorry I will add more information.
anuttarasammyak said:
Next we may include the circle object in A as if it is a newly added molecule.
The circle object is not a part of gas cell and it's state won't be included in gas cell. They just interact with eachother.

The most important things I want to know are:
XNTEABDSC said:
TL;DR Summary: For a 2D game, how to simulate gas and its interaction with objects?

fn evaluate_over_time(GasCell) -> 5 d GasCell :how the gas cell and its neighborhoods change over dt.
fn interact_with_object(GasCell,Body) -> (d GasCell,d Body) :how the gas cell and object change over dt.

(Sorry I'm bad at communicating, I will add more information once I found it is needed)
 
  • #4
XNTEABDSC said:
The circle object is not a part of gas cell and it's state won't be included in gas cell. They just interact with eachother.
So you mean that the circle object does not account for the system momentum and energy conservation formula which I wrote ?

[EDIT] Brownian motion https://en.wikipedia.org/wiki/Brownian_motion might be of your interest.
 
Last edited:
  • #5
Ah seems I misunderstood.
Objects are part of momentum and energy of the system.
 
  • Like
Likes anuttarasammyak
  • #6
If gas is confined in the vessel its momentum and energy would be also considered. 1d gas case might be worth considered for the preparation of 2d gas case.
 
Last edited:
  • #7
anuttarasammyak said:
If gas is confined in the vessel its momentum and energy would be also considered. 1d gas case might be worth considered for the preparation of 2d gas case.
The problem is intergration on circles and squares which isn't included in 1d gas case. 1d gas case is too simple.
 
Back
Top