problem with rotation & translation when designing a reuleaux triangle
in
Programming Questions
•
2 years ago
I am attempting to design a function that will draw a reuleaux triangle.
My approach is to translate to the centre of the Processing window and then use the Beziervertex functions to draw each arc, but before each conscutive arc, implement a rotation translation, such that the same code for the first arc is simply repeated for the 2 other arcs.
This strangely failed as I had to manually vary the controls for the curves in the Bezier functions, seemingly due to the translation not working as I expected.
Any help would be appreciated (code below)....... (see lines 47, 50, 53)
int w = 400; //window width
int h = 200; //window height
int l = h/2; //equilateral triangle side size
float p = 24;
void setup() {
background(255);
size(w,h);
noFill();
//translate to centre
translate(w/2,h/2);
// calculate trigonometric variables
float r = ( (l/2) / (cos(PI/6) ) );
float p = r * sin(PI/6);
float x = p / tan(PI/6);
// draw background outlines
ellipse(0,0,2*r,2*r);
line(0,0,0,-h/2);
rotate(2*(PI/3));
line(0,0,0,-h/2);
rotate(2*(PI/3));
line(0,0,0,-h/2);
rotate(2*(PI/3));
strokeWeight(3);
// left lower point
point(x, p);
// right lower point
point(-x, p);
// top point
point(0, -r);
// reuleaux triangle shape
noStroke();
smooth();
fill(175,200);
beginShape();
// lower left vertex
vertex(x, p);
// bottom arc
bezierVertex(x, p, 0, h/10*3, -x, p);
// left arc
rotate(2*(PI/3));
bezierVertex(-x, p, -h/10*2.5, -h/10*1, 0, -r);
// right arc
rotate(4*(PI/3));
bezierVertex(0, -r, h/10*2.2, -h/10*2, x, p);
endShape();
}
My approach is to translate to the centre of the Processing window and then use the Beziervertex functions to draw each arc, but before each conscutive arc, implement a rotation translation, such that the same code for the first arc is simply repeated for the 2 other arcs.
This strangely failed as I had to manually vary the controls for the curves in the Bezier functions, seemingly due to the translation not working as I expected.
Any help would be appreciated (code below)....... (see lines 47, 50, 53)
int w = 400; //window width
int h = 200; //window height
int l = h/2; //equilateral triangle side size
float p = 24;
void setup() {
background(255);
size(w,h);
noFill();
//translate to centre
translate(w/2,h/2);
// calculate trigonometric variables
float r = ( (l/2) / (cos(PI/6) ) );
float p = r * sin(PI/6);
float x = p / tan(PI/6);
// draw background outlines
ellipse(0,0,2*r,2*r);
line(0,0,0,-h/2);
rotate(2*(PI/3));
line(0,0,0,-h/2);
rotate(2*(PI/3));
line(0,0,0,-h/2);
rotate(2*(PI/3));
strokeWeight(3);
// left lower point
point(x, p);
// right lower point
point(-x, p);
// top point
point(0, -r);
// reuleaux triangle shape
noStroke();
smooth();
fill(175,200);
beginShape();
// lower left vertex
vertex(x, p);
// bottom arc
bezierVertex(x, p, 0, h/10*3, -x, p);
// left arc
rotate(2*(PI/3));
bezierVertex(-x, p, -h/10*2.5, -h/10*1, 0, -r);
// right arc
rotate(4*(PI/3));
bezierVertex(0, -r, h/10*2.2, -h/10*2, x, p);
endShape();
}
1