I think this is the simplest 2D implementation of SPH
It uses a slightly modified Spatial grid to detect the pairs of particles to be processed.
It's very simple, based on 3 main "rules":
Attraction
Density & Pressure
Viscosity
ATTRACTION:
When the particles are close together they attract each other with a force proportional to the square of the inverse of the distance.
If r is the distance between them (normalized in the range 0-1)
Their attraction strength is equal to (1-r) ^ 2
Density and PRESSURE:
The density of each particle is calculated by adding up the weight of neighboring cells. (within the radius h)
The weight of neighboring cells is given by the Density Kernel:
Code:
Private Function SmoothKernel_3(ByVal r As Single) As Single
r = r * 2!
If r <= 1! Then
SmoothKernel_3 = 1! - 1.5! * r * r + 0.75! * r * r * r
Else
r = 2! - r
SmoothKernel_3 = 0.25! * r * r * r
End If
End Function
The pressure of each particle is given by Pressure (I) = (Density (I) - RestDensity) / RestDensity
The replusion force due to pressure is given by the average pressure of the pair of particles multiplied by the Density Kernel * (1 - r)
VISCOSITY
The force due to the viscosity between two particles is given by
This smoothing kernel: -0.5 * r ^ 3 + r ^ 2 + 1 / (2 * r) - 1
It is applied when the particles are approaching each other.
When they are moving away, however, only a small part of this force is applied.
cSpatialGrid3D To quick detect pairs of points at a fixed minumun distance in a 3D space
m3DEasyCam To manage a virtual camera and convert 3D world coordinates to the screen ones
mQuickSort To draw points from farthest to nearest to camera
move clicked-mouse on picture to rotate camera.
EDIT 2
Update to 3D v4
Basically:
-new simplified camera model
-Fake particels at boundaries
EDIT 3
Latest 3D Version on GitHub
From 3D version V.5 , camera has been improved, now it can manage lines which have one of its points that goes behind the camera by using "near-clipping-plane" technique.
Last edited by reexre; May 15th, 2019 at 09:41 AM.
Tell me about it, and with SO little code. Yes I examined it some. There are *very* few in the world who can pull this off, no matter how much code is used.
Well, that would require 3D calculations, so off hand, a fair amount of extra calculation compared to a 2D fluid calculation.
Have to wonder whether the planet calculation has to take into consideration the various layers and type of material the planets are made of and account for those in the particle calculations.
I'm not sure what you're asking.
The equations you posted are pretty much the same as what reexre posted that he is using in the first post.
Since he is using the same or similar equations and using vbrichclient to illustrate the implementation on a large number of particles, it you wanted to modify the equations slightly, then there shouldn't be any issue with using vbrichclient since that is what is already being done.
I'm not sure what you're asking.
The equations you posted are pretty much the same as what reexre posted that he is using in the first post.
Since he is using the same or similar equations and using vbrichclient to illustrate the implementation on a large number of particles, it you wanted to modify the equations slightly, then there shouldn't be any issue with using vbrichclient since that is what is already being done.
I mean how to draw math-equations with vbRichClient5 or pure VB6.
Ok, to replicate the graphs shown?
That should be easy enough with pure VB6, and I'm sure also vbRichClient5, although I haven't used vbRichClient.
I guess you can't see the whole equation for the Density Smooth.
With "pure VB6", you could just create a picturebox to use as the graph area, set the ScaleWidth and ScaleHeight to the size you want for your plot area and set the ScaleLeft and ScaleTop appropriately.
I guess looking at the web page, perhaps it is a little more complicated than that since you can click on the graph, and drag to scroll the graph vertically and horizontally to see more of the graph, so the plot's virtual size can be much larger than what can fit on the screen at any given time. And you can zoom in and out so the scale is modifiable. If you want to replicate the functionality of the desmos graphing interface, then that would be quite a bit of work, i.e. the display of point values along the curve with tooltip type windows, etc...
I'm sure it can be done in pure VB6 or other graphic library. The question is how much of the functionality are you looking to implement.
This is my new test.
I added an Attraction to Global Center of Mass
Thanks for the suggestion.
Quite near your Planets demo... but I don't think I'll go more further
now 3D version (V.5) has an improved camera that can manage lines which have one of its points that goes behind the camera by using "near-clipping-plane" technique.
Last edited by reexre; May 15th, 2019 at 09:44 AM.