Quantcast
Channel: Grasshopper Developer - McNeel Forum
Viewing all articles
Browse latest Browse all 3658

Random points are not generated inside brep despite a correct code

$
0
0

@youssef_aboualghar wrote:

Hello guys,

So I’m this code to make boids inside a brep and everything seems to work just fine except that I’m using a correct code to generate points inside a brep.
yet it doesn’t work.
can anybody tell me why > ?
here is the code :

public class FlockSystem
{
public List Agents;

    public double Timestep;
    public double NeighbourhoodRadius;
    public double AlignmentStrength;
    public double CohesionStrength;
    public double SeparationStrength;
    public double SeparationDistance;
    public List<Circle> Repellers;
    public bool UseParallel;
    public Brep Brep;
    Random random = new Random();

    public Box BBox { get; set; }  
    public Point3d Min { get; set; }
    public Point3d Max { get; set; }
    public FlockSystem(int agentCount,Brep brep)
    {
        Brep = brep;
        Agents = new List<FlockAgent>();

        var box = Box.Unset;
        brep.GetBoundingBox(Plane.WorldXY, out box);
        var min = box.PointAt(0,0,0);
        var max = box.PointAt(1, 1, 1);

        BBox = box;
        this.Min = min;
        this.Max = max;

      //for(int i =0;i<agentCount;i++)
        Parallel.For(0, agentCount, (i, loopState) =>
        {
            //var randPt = Util.GetRandomPoint(min.X, max.Y, min.Z, max.X, min.Y, max.Z);
            var randPt = box.PointAt(random.NextDouble(), random.NextDouble(), random.NextDouble());


            if (Brep.IsPointInside(randPt, 0.01, false))
            {
                FlockAgent agent = new FlockAgent(
                randPt,
                Util.GetRandomUnitVector() * 4.0);
                agent.FlockSystem = this;
                Agents.Add(agent);
            }
            if (Agents.Count == agentCount)
            {
                loopState.Break();
            }
        });
    }

thanks a lot :wink:

Posts: 12

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 3658

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>