Rotating a Block of Points About Another Point Magnifies and Diminishes the Block Size

I am trying to rotate points about another point, but the rotated points are either further away from each other or they are closer to each other than their original separation. I want to rotate them so that when they are rotated I want them to preserve the distance between them. I do not want to use the “rotate(angle)” method that rotates the screen. Here is the Processing code:

import toxi.geom.*;
import toxi.physics2d.*;
import toxi.physics2d.behaviors.*;
import toxi.physics2d.constraints.*;
import controlP5.*;

void setup() {
  size(800, 800);
  physics = new VerletPhysics2D();
  particles_1 = new VerletParticle2D[columns][rows];
  vecs = new Vec2D[columns][rows];
  
  for (int j = 0; j < rows; j++) {
    for (int i = 0; i < columns; i++) {
      vecs[i][j] = new Vec2D(400 + i * w, 400 + j * w);
    }
  }

  controller = new ControlP5(this);
  Slider bP = controller.addSlider("angle", 0, TWO_PI, 0, 10, 270, 100, 20);
  controller.addBang("rotateBlock", 20, 300, 28, 28).setLabel("rotateBlock");
}

void draw() {
  background(0);
  physics.update();
  
  for (int j = 0; j < rows; j++) {
    for (int i = 0; i < columns; i++) {
      ellipse(vecs[i][j].x, vecs[i][j].y, 10, 10);
    }
  }
}

void rotateBlock() {
  for (int j = 0; j < rows; j++) {
    for (int i = 0; i < columns; i++) {
      Vec2D position = rotatePoint(vecs[i][j].x, vecs[i][j].y, angle, vecs[10][10].x, vecs[10][10].y);
      vecs[i][j].x = position.x;
      vecs[i][j].y = position.y;
    }
  }
}

Vec2D rotatePoint(float cx, float cy, float angle , float px, float py) {
  float x = cx + (px - cx) * cos(angle) - (py - cy) * sin(angle);
  float y = cy + (px - cx) * sin(angle) + (py - cy) * cos(angle);
  return new Vec2D(x, y);
}

VerletPhysics2D physics;
ControlP5 controller;
float x = 0;
float y = 0;
float w = 10;
int rows = 21;
int columns = 21;
VerletParticle2D[][] particles_1;
float angle = 0;
Vec2D[][] vecs;
Vec2D position;

Hello @Ermi ,

Take a look at this:
Vec2D rotatePoint(float cx, float cy, float angle , float px, float py)

Are you passing the correct variables?
Try swapping them around to see what happens.

:)