I am starting a sketch on Diffusion Limited Aggregation, but I am getting an infinite Loop when my first particle is attached to the origin point, and I dont know why I am getting this infinite loop.
I know it has to do with my while loop, but I cant figure out what is failing. When the while loop is false (larger than particle radius*2) the walker will keep evaluating its distance to the particle list while moving at random positions. When finally the while loop is true, it means that the walker is now attached to a particle and it will be added to the particle list. This is the logic inside the while loop.
Any pointers will be wonderful!
Thanks
Nicholas
// Diffusion Limited Aggregation
// MAIN PROGRAM
// create Random class instance
Random rn = new Random();
// create custom defined class instance
ConstrainValues CV = new ConstrainValues();
// create empty list to store all points in simulation
List<Point3d> particleList = new List<Point3d> ();
// define particle radius
double particleRadius = 2.0;
// set initial point in center of screen
particleList.Insert(0, new Point3d(0, 0, 0));
// run simulation
if(run)
{
// create a walker at a random Point in the screen, for now screen
// dimensions are hard coded
Point3d walker = new Point3d(Util.GetRandomPoint(0, 20, 0, 20, 0, 0));
bool stuck = false;
while(!stuck)
{
for (int i = 0; i < particleList.Count;i++)
{
double distance = walker.DistanceTo(particleList[i]);
if(distance < particleRadius * 2)
{
stuck = true;
break;
}
}
walker.X += rn.Next(-1, 2);
walker.Y += rn.Next(-1, 2);
walker.X = CV.Constrain(walker.X, 0, 20);
walker.Y = CV.Constrain(walker.Y, 0, 20);
//particleList.Add(walker);
}
// when stuck is true, add walker to particle list
particleList.Add(walker);
for (int j = 0; j < particleList.Count;j++)
{
Point3d particle = new Point3d(particleList[j].X, particleList[j].Y, 0.0);
}
// if true, run every second
Component.ExpireSolution(true);
}
else
{
Print("standby");
}
// define outputs
A = particleList;
Aucun commentaire:
Enregistrer un commentaire