Find the average position of the particles
#2
You could achieve it pretty easily with a script.

The basic idea is: search for the neighbors of a particle within a radius. Find the center point of all neighbors that haven't already been moved. Move the neighbors to the center and mark them all as moved. Repeat for each particle.

Code:
public void simulationStep()
{    
    float searchRadius = 5.0f;
    
    
    tf.PrepNeighbors(false);
    List<bool> movedParticles = new List<bool>();
    for (int sInx = 0; sInx < totalParticleCount; sInx++) {movedParticles.Add(false);}
    
    for (int sInx = 0; sInx < totalParticleCount; sInx++)
    {
        Point3 pos = tf.GetPos(sInx);
        List<int> neighbors = tf.GetNeighbors(pos, searchRadius);
        
        Point3 center = new Point3();
        int neighborCount = 0;
        for (int n = 0; n < neighbors.Count; n++)
        {
            int nInx = neighbors[n];
            if (!movedParticles[nInx])
            {
                center += tf.GetPos(nInx);
                neighborCount++;
            }
        }
        if (neighborCount > 0)
        {
            center /= neighborCount;
            
            for (int n = 0; n < neighbors.Count; n++)
            {
                int nInx = neighbors[n];
                if (!movedParticles[nInx])
                {                
                    movedParticles[nInx] = true;
                    tf.SetPos(nInx, center);
                }
            }
        }
    }
}
  Reply


Messages In This Thread
RE: Find the average position of the particles - by tyFlow - 04-24-2020, 04:04 AM

Forum Jump: