We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey guys,
I would like to dynamically add new triangles (defined by its vertexes being PVectors). I don't know how many triangles I will have, so I would like to use a 2D Arraylist.
How do I add elements to this double array? My code doesn't work because array.get(i) (obviously) returns null. How do I add a new PVector to i,j?
Here is my code so far:
ArrayList<ArrayList<PVector>> array = new ArrayList<ArrayList<PVector>>();
void setup()
{
for (int i=0; i<1; i++) {
for (int j=0; j<3; j++) {
array.get(i).get(j).add(new PVector(0, 0, 0));
}
}
for (int i=0; i<array.size(); i++) {
for (int j=0; j<array.get(i).size(); j++) {
println(array.get(i).get(j).x);
}
}
}
Thanks for any reply:)
(I have found this discussion but I'm missing the iterration: https://forum.processing.org/one/topic/2d-arraylist.html)
Answers
When yoi have a ClassTriangle your ArrayList could be of that type
Much easier (in the longrun)
Thank you for that answer, Ill try to do it that way:)
However, if anyone is interested in a more generic solution, I made it work:
@szemy2, you can replace the internal ArrayList<PVector> w/ just PVector[]: *-:)