The tricky part is not to invert the shape but to rotate it (and maybe translating it ?) so as it sticks to the preceding shape. I’ve been trying to use angleBetween() or atan2() but without success.

Hi,
maybe it would be easier to rotate when you start your shape at a corner (0,0) instead of in the middle. Then you have a nice reference for how you rotate?

My last question about angles was also left unanswered. Please tell me if I’m not clear enough when formulating the issue or if the question is too complex for the forum.

The angle of rotation seems correct but obviously there’s something off with the translation (either on the X or Y axis) and I can’t figure out what exactly.

I would really appreciate if someone could help me understand what I’m doing wrong and how to fix this problem.

int W = 40;
int H = 40;
int Yoffset = 10;
float[] p0 = {-W/2, -H/2};
float[] p1 = {W/2, -H/2 - Yoffset};
float[] p2 = {W/2, H/2};
float[] p3 = {-W/2, H/2};
PShape object;
void setup(){
size(600, 600, P2D);
smooth(8);
noFill();
}
void draw(){
background(255);
pushMatrix();
translate(width>>1, height>>1);
float angle = atan2(p1[1] - p0[1], p1[0] - p0[0]);
for (int i = 0; i < 6; i++){
int factor = (i % 2 == 0) ? 1 : -1;
//Height translation
translate(0, H*factor);
//Flip all quads except 1st one
if (i > 0){
scale(1, -1);
}
//Rotate once every 2 quads
if (i%2 == 1){
rotate(-angle*2);
}
object();
}
popMatrix();
}
void object() {
beginShape(QUADS);
vertex(p0[0], p0[1]);
vertex(p1[0], p1[1]);
vertex(p2[0], p2[1]);
vertex(p3[0], p3[1]);
endShape();
}