Simple ArrayIndex problem

If you want to iterate over pairs of vertices in a closed shape, you can also use modulo %.

for (int i=0; i<pos.size(); i++) {
   a = pos.get(i);
   b = pos.get( (i+1)%pos.size() );
}

This works for any size. For a size of 3, this will generate:

0,1 – 1,2 – 2,0

2 Likes