Skip to content

Instantly share code, notes, and snippets.

@tmshv
Created May 24, 2012 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmshv/2781828 to your computer and use it in GitHub Desktop.
Save tmshv/2781828 to your computer and use it in GitHub Desktop.
How to draw arc shape in Processing
void drawArc(int center_x, int center_y, float start_a, float finish_a, float inner_radius, float outer_radius) {
fill(color(0, 0, 0));
float angle_delta = finish_a - start_a;
int pass_length = 1;
int pass_number = 0;
float angular_step = 0;
float cur_x = 0;
float cur_y = 0;
float current_angle = 0;
float arc_length = 0;
beginShape();
angular_step = 2 * asin(pass_length/inner_radius/2);
arc_length = angle_delta * inner_radius;
pass_number = (int)(arc_length / pass_length);
current_angle = start_a;
for (int i=0; i<pass_number; i++) {
cur_x = center_x + (cos(current_angle) * inner_radius);
cur_y = center_y + (sin(current_angle) * inner_radius);
vertex((int) cur_x, (int) cur_y);
current_angle += angular_step;
}
angular_step = 2 * asin(pass_length/outer_radius/2);
arc_length = angle_delta * outer_radius;
pass_number = (int)(arc_length / pass_length);
current_angle = finish_a;
for (int i=0; i<pass_number; i++) {
cur_x = center_x + (cos(current_angle) * outer_radius);
cur_y = center_y + (sin(current_angle) * outer_radius);
vertex((int) cur_x, (int) cur_y);
current_angle -= angular_step;
}
endShape(CLOSE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment