# Rectangle intersections 3D

**URL:** <https://discourse.processing.org/t/rectangle-intersections-3d/35170>\
**Category:** Coding Questions\
**Created:** [February 14, 2022, 11:38pm UTC](https://discourse.processing.org/t/rectangle-intersections-3d/35170 "2022-02-14T23:38:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bruno.pace](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@bruno.pace](https://discourse.processing.org/u/bruno.pace)\
**Post date:** [February 14, 2022, 11:38pm UTC](https://discourse.processing.org/t/rectangle-intersections-3d/35170/1 "2022-02-14T23:38:11Z")

</div>

Hi there,

I am trying to place some rotated rectangles in 3D but the rendering would be much better if the intersection lines between them would be visible. Can anyone help me do that?

```auto
float x,y,z,a,b ;
int num = 300 ; 
int side = 500;
int imax = 0; 
float y0 = 2./3;
int radius;

int previousDisplayTime; // Keep track of the last time a frame of the animation was displayed
int deltaTime; 

boolean sense = true;
boolean pause = false;

void setup() {
  size(1000,1000,P3D);
  lights();
  //ortho();
  y0 = height;///2+side/2;
  println(y0);
  x = width/2;
  y = y0;
  z = 0;
  a = 0;
  b = 0;
  
  directionalLight(255, 255, 255, 0, -1, -1);
  
  deltaTime = 100;
  previousDisplayTime = 0;  
  
  //float fov = PI/2;
  //float cameraZ = (4000) / tan(fov/2.0);
  //perspective(fov, float(width)/float(height), 
  // cameraZ/10.0, cameraZ*10.0);
}

void draw() {
  radius = side + mouseX;
  lights();
  //stroke(220);
  stroke(255*1/4);
  //noStroke();
  background(220, 220, 220);  
  //background(255);
  //fill(255, 0, 0, 10);
  camera(//width, 0, width/3, // eyeX, eyeY, eyeZ
         width/2-10*width/4, height/2-10*width/4, radius-10*width/4,
         0, 0, 0,
         //3*width/4, width/4, width/8, // centerX, centerY, centerZ
         0.0, 1.0, 0.0);

  perspective(PI/3.0, float(width)/float(height), mouseX, 10*radius-100*width/4);//1, 25*radius);
  
  
  if ((millis() > previousDisplayTime + deltaTime) & sense & !pause) {
    imax++;
    if (imax > num) { 
      sense = false;
    }
    previousDisplayTime = millis();
  }

  if ((millis() > previousDisplayTime + deltaTime) & !sense & !pause) {
    imax--;
    if (imax < 0) { 
      sense = true;
    }
    previousDisplayTime = millis();
  }

  for (int i=0; i < imax; i++) {
      x = radius * cos(i*2*PI/num);
      y = radius * sin(i*2*PI/num); 
      drawSheet(i);
      //y-=side/(num-1); // The rectangle moves forward as z increments.
      a+=0.02*mouseX/width*20;
      b+=0.02*mouseY/width*20;
  }
  
  a = 0;
  b = 0;
  y = y0;
  x=width/2;

}

void mousePressed() {
 pause = !pause; 
}

void drawSheet(int i) {
  pushMatrix();
  translate(x,y,0);
  rectMode(CENTER);
  fill(255);
  //rotateX(-PI/6);
  //rotateY(PI/3);
  rotateX(PI/2);
  rotateY(2*PI/num*i);
  rotateZ(a);
  rotateY(b);
  rect(0,0,side,side);
  popMatrix();
}

```
