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

**URL:** <https://discourse.processing.org/t/rotating-a-block-of-points-about-another-point-magnifies-and-diminishes-the-block-size/45757>\
**Category:** Libraries\
**Created:** [February 14, 2025, 6:21am UTC](https://discourse.processing.org/t/rotating-a-block-of-points-about-another-point-magnifies-and-diminishes-the-block-size/45757 "2025-02-14T06:21:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ermi](https://avatars.discourse-cdn.com/v4/letter/e/ee59a6/32.png) [@Ermi](https://discourse.processing.org/u/Ermi)\
**Post date:** [February 14, 2025, 6:21am UTC](https://discourse.processing.org/t/rotating-a-block-of-points-about-another-point-magnifies-and-diminishes-the-block-size/45757/1 "2025-02-14T06:21:59Z")

</div>

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:

```auto
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;

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [February 15, 2025, 8:54am UTC](https://discourse.processing.org/t/rotating-a-block-of-points-about-another-point-magnifies-and-diminishes-the-block-size/45757/2 "2025-02-15T08:54:59Z")

</div>

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.

`:)`
