How to do this programmatically (Combinatorics?)

Hello,

My original code with some updates from feedback:

/*
 Project:   Polygons
 Author:    GLV
 Date:      2024-06-17
 Version:   1.0.1
*/

size(300, 300);
translate(width/2, height/2);

int num = 7;
PVector [] v = new PVector [num];
int r = 100;

for(int i = 0; i<num; i++)
  {
  float angle = i*TAU/num - TAU/4;  
  float x = round(r*cos(angle));
  float y = round(r*sin(angle)); 
  v[i] = new PVector(x, y);
  }

strokeWeight(3);

for(int i = 0; i < num-1; i++)  // Updated
  {
  for(int j = i+1; j < num; j++)
    {
    println(i,j, ':', v[i], v[j]);
    line(v[i].x, v[i].y, v[j].x, v[j].y);
    }
  }

Rounding was for a clean console output (less decimal places) for the screen grab and rounding to nearest pixel will not be noticeable.

I had some fun with this back when and once again and posted in the gallery:

:)

1 Like