Grasshopper

algorithmic modeling for Rhino

Hello,

its me again.

i am still trying to master the intersectionevents.(Here it is probably more a list issue)

In the example i intersect various lines in a foreach loop.Then i put the boolean values into a list to check:if (boolList.All(x => x == false))

to add them when they dont intersect.

Now my booleanList just shows up 1 value.i checked in the if condition above with a print and i get all values of the intersection event(not just one,like in the booleanList).

Hope the screencapture explanis it better

here also the code:

 private void RunScript(int numberLines, int max, int length, ref object A, ref object B)
  {
    List<Line> lineList = new List<Line>();

    Line l1 = makeLine(max, length);//making the first line in the list so that it isnt empty
    lineList.Add(l1);



    for (int i = 0; i < numberLines - 1; i++)
    {

      Line ltemp = makeLine(max, length);//making new line


      foreach (Line l in lineList){//cheking for the line interserctoin event with evey other line in the list

        double a;double b;bool ie = Rhino.Geometry.Intersect.Intersection.LineLine(ltemp, l, out a, out b, 0.001, true);
 
        List<bool> boolList = new List<bool>();//adding values to list of booleans

        boolList.Add(ie);

        if (boolList.All(x => x == false)){//if alls values are false add the line
          Print("not intersected");
          
       

        BoolList = boolList;

      }
    }
}

    A = lineList;

  }

  // <Custom additional code>
  //makes random

  RangedRandom rand = new RangedRandom();
  class RangedRandom : System.Random {

    public RangedRandom(): base(){}
    public RangedRandom(int seed): base(seed){}

    public double NextDouble(double max){
      return NextDouble() * max;
    }

    public double NextDouble(double min, double max){
      return (max - min) * NextDouble() + min;
    }
  }


  //makes the random lines
  public Line makeLine(int max, int length){
    Point3d temPt = new Point3d(rand.Next(0, max), rand.Next(0, max), 0);
    Circle tempC = new Circle(temPt, length);
    Point3d temPt1 = tempC.PointAt(rand.NextDouble(max));
    Line l = new Line(temPt, temPt1);

    return l;
  }

  // </Custom additional code>

How do I obtain getting the Line just added when it doent intersect.

Thanks in advance!

Views: 931

Attachments:

Replies to This Discussion

See Attached!

List<bool> boolList = new List<bool>();

for (int i = 0; i < numberLines - 1; i++)

{

     ......

     boolList.Add(ie);

     ......

}

Attachments:

hi panda,thanks again!

i tried now to add the ltemp line just when they dont intersevt,but it when i do it the foreach loop i got an error message,think its cause i am changing the listcount, so i tried it in a new for loop,but then the machine freezes so i think i made a infinte loop or something.maybe you an help me in this too?

thanks!

See attached and make sure if it is what you want?

not sure, are you refering to the last attachment or it is missing?

Sorry,forgot to upload!

Attachments:

hi,

thanks again,

i think i am explaining myself really bad,sorry for that.

I try to just add the line when it doesnt intersect with any other line in the list.

But now i realized in the current version it wont be possible, because the random everytime a line gets added changed the position of th existing lines.

I try to use it as a base(exercise) to be able to populate without that the geometry clashes.

I hope i did not explained terribly again.


Thanks a lot for your effort.

regards!

also added my las try.

Not sure if a bigger change is necessary?

Attachments:

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service