need help with somekind of arc function
in
Programming Questions
•
2 years ago
I'm trying to make a function to draw something like the red shape based on the given coordinates in the image.
I only want the edge between 2 and 3 and between 4 and 1 to follow the circulair movement.
This involves some math to calculate the control points for the bezierVertex that i can't do.
Could someone help?
- void setup() {
- size(600, 600);
- smooth();
- }
- void draw() {
- background(255);
- pushMatrix();
- translate(width/2, height/2);
- noFill();
- strokeWeight(0.3);
- ellipseMode(RADIUS);
- ellipse(0, 0, 150, 150);
- ellipse(0, 0, 200, 200);
- // create the points
- float cx = screenX(0, 0);
- float cy = screenY(0, 0);
- float x1 = screenX(150, 0);
- float y1 = screenY(150, 0);
- float x2 = screenX(200, 0);
- float y2 = screenY(200, 0);
- rotate(radians(20));
- float x4 = screenX(150, 0);
- float y4 = screenY(150, 0);
- float x3 = screenX(200, 0);
- float y3 = screenY(200, 0);
- popMatrix();
- // draw the points
- strokeWeight(4);
- point(cx, cy);
- point(x1, y1);
- point(x2, y2);
- point(x3, y3);
- point(x4, y4);
- // show the shape
- fill(255, 0, 0);
- strokeWeight(1);
- arc2(cx, cy, x1, y1, x2, y2, x3, y3, x4, y4);
- }
- void arc2(float cx,float cy,float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4) {
- beginShape();
- vertex(x1, y1);
- vertex(x2, y2);
- // calculate cx1, cy1 and cx2, cy2 with help of cx and cy
- // in other words, the control points must be somehow calculated
- float cx1 = x2; // wrong
- float cy1 = y2; // wrong
- float cx2 = x3; // wrong
- float cy2 = y3; // wrong
- bezierVertex(cx1, cy1, cx2, cy2, x3, y3);
- vertex(x4, y4);
- // calculate cx1, cy1 and cx2, cy2 with help of cx and cy
- // in other words, the control points must be somehow calculated
- cx1 = x4; // wrong
- cy1 = y4; // wrong
- cx2 = x1; // wrong
- cy2 = y1; // wrong
- bezierVertex(cx1, cy1, cx2, cy2, x4, y4);
- endShape();
- }
edit:
in theory (i think) it should also be possible to not use x2, y2 and x4, y4 so leaving them out is fine.
1