Skip to content

Instantly share code, notes, and snippets.

@KarimAziev
Created June 10, 2025 18:49
Show Gist options
  • Select an option

  • Save KarimAziev/d451c8d1bbac2c41f40f05ea6fa3d082 to your computer and use it in GitHub Desktop.

Select an option

Save KarimAziev/d451c8d1bbac2c41f40f05ea6fa3d082 to your computer and use it in GitHub Desktop.
Debug Polygon #scad
module debug_polygon(points, paths=undef, convexity=undef, debug=false,
arrow_size=1, font_size=4, font_color="red",
show_arrows=true) {
polygon(points=points, paths=paths, convexity=convexity);
if (debug) {
for (i = [0 : len(points) - 1]) {
pt = points[i];
color(font_color)
translate([pt[0], pt[1], 0.1])
linear_extrude(height = 0.5)
text(str(i), size = font_size, valign="center", halign="center");
color("yellow")
translate([pt[0], pt[1]])
circle(r = 0.5);
}
if (show_arrows) {
all_paths = paths == undef ? [ [ for (i = [0 : len(points)-1]) i ] ] : paths;
for (path = all_paths)
for (i = [0 : len(path)-1]) {
a = points[path[i]];
b = points[path[(i+1)%len(path)]];
dx = b[0] - a[0];
dy = b[1] - a[1];
angle = atan2(dy, dx);
mid = [ (a[0]+b[0])/2, (a[1]+b[1])/2 ];
color("green")
translate([mid[0], mid[1], 0.1])
rotate([0, 0, angle])
linear_extrude(height = 0.5)
polygon(points=[[0,0],[arrow_size,arrow_size/2],[arrow_size,-arrow_size/2]]);
}
}
}
}
points = [[0,0], [40,0], [40,20], [20,40], [0,20]];
paths = [[0, 1, 2, 3, 4]];
debug_polygon(points=points, paths=paths, debug=true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment