I am a little bit stuck with this simple problem; I have an arrayList of let’s say PVectors and I would like to draw random lines between two different points.( or have any other connection rule ), the number of points is pair.
no point should be connected to itself and no point should be connected to more than one point.!
is there any exemple I can consult about this kind of iteration through arrayLists
You could have a boolean variable to check if its been paired.
Then iterate through the array, for each pvector, and use an if statement to check if “this” and if “!paired”
I have tried something similar, but I don’t know where to store the Boolean variable. should I declare an other list ?
If you’re allowed to use classes then just store it in the object, if not create another arraylist with boolean variables tied to the position of your point in the array.
Do you have to keep the original oder of your Arraylist?
Otherwise you can just shuffle it and then connect them pairwise, (1-2, 3-4, 5-6, …).
thank you Benja,
it’s a really clever and elegant way !