# Compare the angle between several spinning objects

**URL:** https://discourse.processing.org/t/compare-the-angle-between-several-spinning-objects/11194
**Category:** Coding Questions
**Created:** [May 13, 2019, 11:06am UTC](https://discourse.processing.org/t/compare-the-angle-between-several-spinning-objects/11194 "2019-05-13T11:06:32Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ale.moso](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ale.moso/32/5166_2.png) [@ale.moso](https://discourse.processing.org/u/ale.moso)
#### Post date: [May 13, 2019, 11:06am UTC](https://discourse.processing.org/t/compare-the-angle-between-several-spinning-objects/11194/1 "2019-05-13T11:06:32Z")

</div>

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!

```auto
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();
  }
}

```

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [May 13, 2019, 11:45am UTC](https://discourse.processing.org/t/compare-the-angle-between-several-spinning-objects/11194/2 "2019-05-13T11:45:29Z")

</div>

[http://www.jeffreythompson.org/collision-detection/line-line.php](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 )

---

<div class="post-metadata">

### Author: ![ale.moso](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ale.moso/32/5166_2.png) [@ale.moso](https://discourse.processing.org/u/ale.moso)
#### Post date: [May 13, 2019, 1:52pm UTC](https://discourse.processing.org/t/compare-the-angle-between-several-spinning-objects/11194/3 "2019-05-13T13:52:16Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![ale.moso](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ale.moso/32/5166_2.png) [@ale.moso](https://discourse.processing.org/u/ale.moso)
#### Post date: [May 13, 2019, 2:10pm UTC](https://discourse.processing.org/t/compare-the-angle-between-several-spinning-objects/11194/4 "2019-05-13T14:10:29Z")

</div>

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?
