# Creating a structure of linked tetrahedra

**URL:** <https://discourse.processing.org/t/creating-a-structure-of-linked-tetrahedra/16955>\
**Category:** Coding Questions\
**Created:** [January 8, 2020, 1:05pm UTC](https://discourse.processing.org/t/creating-a-structure-of-linked-tetrahedra/16955 "2020-01-08T13:05:39Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [January 9, 2020, 1:06pm UTC](https://discourse.processing.org/t/creating-a-structure-of-linked-tetrahedra/16955/8 "2020-01-09T13:06:11Z")

</div>

> [@dauwpunt](#):
>
> I saw some posts about using the translate() and rotatex/y/z functions to move the grid. Could that be something useful?

I guess not, because translation will occur in Cartesian space.  
You can still build from the center using two points of a face and distance the other along the quadray axis.  
Below a code with one tetrahedron attached forming a triangular bipyramid, rotating around centroid of the center tetrahedron. I did not close all faces just to see through.  
Maybe you can build something using a PVector array like @kll suggested. Let us know if you succeed.

```auto

float rotX, rotY, s, t;

void setup(){
  size(720, 480, P3D);
  s = 60;  
  t = 2*sqrt(6)/3;
  noFill();
  stroke(255);
  hint ( DISABLE_DEPTH_TEST);
} 

void draw(){
  background(0);
  translate(width/2, height/2);
  rotateX(rotX); 
  rotateY(-rotY); 
  
  fill(255, 0, 0, 200); // first red face
  beginShape(TRIANGLES);
  strokeWeight(3); 
  vertex( s, s, s); 
  vertex(-s, -s, s);
  vertex(-s, s, -s); 
  endShape();
  
  fill(0, 255, 0, 200); // second green face
  beginShape(TRIANGLES);
  //stroke(255, 255, 0);
  vertex( s, -s, -s); 
  //stroke(255, 0, 0);
  vertex( s, s, s); 
  //stroke(0, 255, 0);
  vertex(-s, -s, s); 
  endShape();
  
  fill(255, 255, 0, 200); // third yellow face
  beginShape(TRIANGLES);
  vertex( -s, s, -s); 
  vertex( s, s, s); 
  vertex(s, -s, -s);
  endShape();
  
  // Using two points of first red face and distance the other
  fill(255, 0, 0, 200); 
  beginShape(TRIANGLES);
  strokeWeight(3);
  vertex( s, s, s); 
  vertex(-s, -s, s); 
  vertex(-t*s, t*s, t*s); 
  endShape();
  
  fill(255, 0, 0, 200); 
  beginShape(TRIANGLES);
  strokeWeight(3);
  vertex( s, s, s); 
  vertex(-t*s, t*s, t*s); 
  vertex(-s, s, -s); 
  endShape();
 
  // The axes
  stroke(200, 0, 0, 100);
  line(0, 0, 0, -4*s, -4*s, -4*s);
  stroke(255, 50, 50, 100);
  line(0, 0, 0, 4*s, 4*s, 4*s);
  stroke(0, 200, 0, 100);
  line(0, 0, 0, -4*s, -4*s, 4*s);
  stroke(50, 255, 50, 100);
  line(0, 0, 0, 4*s, 4*s, -4*s);
  stroke(0, 0, 200, 100);
  line(0, 0, 0, -4*s, 4*s, -4*s);
  stroke(50, 50, 255, 100);
  line(0, 0, 0, 4*s, -4*s, 4*s);
  stroke(255, 100);
  line(0, 0, 0, 4*s, -4*s, -4*s);
  stroke(150, 100);
  line(0, 0, 0, -4*s, 4*s, 4*s);
}

void mouseDragged() { 
  rotY -= (mouseX - pmouseX) * 0.01; 
  rotX -= (mouseY - pmouseY) * 0.01;
}

```

---

_[View the full topic](https://discourse.processing.org/t/creating-a-structure-of-linked-tetrahedra/16955)._
