/// <summary> /// Generates the randrom particles. /// </summary> /// <param name="material">Particles material.</param> /// <param name="radius">The radius of the sphere.</param> /// <param name="count">Particles count.</param> public static List<Particle> GenerateRandromParticlesInSphere( Material material, double radius, int count ) { var res = new List<Particle>(); var rand = new Random(); for( int i = 0; i < count; i++ ) { var particle = new Particle( material ); particle.RadiusVector = new Vector( ( rand.NextDouble() - 0.5 ) * radius, ( rand.NextDouble() - 0.5 ) * radius, ( rand.NextDouble() - 0.5 ) * radius ); // TODO: Improve algorithm to avoid intersections bool isIntersected = res.Any( particle.isIntersected ); if( isIntersected ) { i--; continue; } res.Add( particle ); } return res; }
public bool isIntersected( Particle that ) { var diff = RadiusVector - that.RadiusVector; var distance = diff.Mod(); return distance < ( Material.Radius + that.Material.Radius ); }