Find the average position of the particles
#1
HI,Tyson!
  A group of particles, I want to find the average position of each other. The average position is within a radius. Replace the original position.
Like two pictures. For the same group of particles, I let them search for each other in a radius. And find the average position of each other. Then replace the old position with the new position, the final result is that the particles "shrink". The number of particles has not decreased
Is this in TF. Is there a way to achieve it? Or how to achieve it in the script?
Thank you!
  Reply
#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
#3
Thank you very much for your guidance. I am learning script operators. This is too important for me. Thank you very much.

The principle of the "Fuse" operator is correct. But it seems to delete the particles. If you don't delete the particles, you should be able to achieve a similar effect.

  Reply


Forum Jump: