 # Compare the angle between several spinning objects

#1

Hello dear community,

I made a grid of spinning lines. Now I wonder how to know when a line and is neighbours are matching in the vertical or horizontal axis to change theris colors for that moment in which the share the same position.

Here is the code I have so far for better understanding of what I need to accomplish.

Many thanks in advance!

``````Pulsar[] pulsars;

int columns = 5;
int rows = 5;
int total = columns*rows;

float stepX, stepY;

void setup() {

size(500, 500);
strokeWeight(2);

stepX = width/ columns;
stepY = height/ rows;

pulsars = new Pulsar[total];

int index = 0;
for (int j = 0; j < rows; j++) {
for (int i = 0; i < columns; i++) {
// Arrange lines in a grid
pulsars[index] = new Pulsar(i * stepX +  (stepX/2), j * stepY + (stepY/2));

// update counter
index ++;
//reset counter
if (index == total) index = 0;
}
}
}

void draw() {
background(10);

int index = 0;

for (int j = 0; j < rows; j++) {
for (int i = 0; i < columns; i++) {
// new velocity for every line
float vel = (index + 1) * 0.003;

stroke(255);
pulsars[index].display(vel);

// update counter
index ++;
//reset counter
if (index == total) index = 0;
}
}
}

// ROTATING OBJECT
class Pulsar {
float posX, posY, vel;
float angle = 0;

Pulsar(float posX_, float posY_) {
posX = posX_;
posY = posY_;
}

void display(float vel) {
pushMatrix();
translate(posX, posY);
rotate(angle);

// draw forms
ellipse(0, 0, 4, 4);
line(-width/(rows*2), 0, height/(rows*2), 0);

// uopdate angle
angle += vel;
popMatrix();
}
}

``````
#2

http://www.jeffreythompson.org/collision-detection/line-line.php ;
but that requires that you know where the lines are!
so instead working with
push / translate / rotate / line(x1,y1,x2,y2) / pop
better work with array for x1,y1,x2,y2 and calculate/fill that by some math first.
( just a idea )

1 Like
#3

I was hoping that using the angle rotation were the soulution but the more I think it the more I see is a nonsense.

How many arrays you think I would need? A 2D array like this [[x1, y1, x2, y2], [x3, y3, x4, y4] … ] would be enough?

Thank you @kll!

#4

Another question is if I can’t use rotate or any transformation function, cause this wouldn’t works with collision detection, how cant y make them spin?