Skip to content

Instantly share code, notes, and snippets.

@brad
Forked from anoved/star.scad
Created December 27, 2020 04:45
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 brad/ba483726b25a41e62ac46910f37b0ced to your computer and use it in GitHub Desktop.
Save brad/ba483726b25a41e62ac46910f37b0ced to your computer and use it in GitHub Desktop.
OpenSCAD pointed star module
// points = number of points (minimum 3)
// outer = radius to outer points
// inner = radius to inner points
module Star(points, outer, inner) {
// polar to cartesian: radius/angle to x/y
function x(r, a) = r * cos(a);
function y(r, a) = r * sin(a);
// angular width of each pie slice of the star
increment = 360/points;
union() {
for (p = [0 : points-1]) {
// outer is outer point p
// inner is inner point following p
// next is next outer point following p
assign( x_outer = x(outer, increment * p),
y_outer = y(outer, increment * p),
x_inner = x(inner, (increment * p) + (increment/2)),
y_inner = y(inner, (increment * p) + (increment/2)),
x_next = x(outer, increment * (p+1)),
y_next = y(outer, increment * (p+1))) {
polygon(points = [[x_outer, y_outer], [x_inner, y_inner], [x_next, y_next], [0, 0]], paths = [[0, 1, 2, 3]]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment