1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-17 22:28:16 +01:00
dotSCAD/examples/spiral_polygons/spiral_polygons.scad

41 lines
1.0 KiB
OpenSCAD
Raw Normal View History

2021-03-24 08:34:07 +08:00
use <shape_circle.scad>;
2021-10-08 09:36:01 +08:00
use <polyline_join.scad>;
2021-03-24 08:34:07 +08:00
use <util/sum.scad>;
beginning_radius = 10;
line_width = 2;
fn = 3;
number_of_polygons = 10;
height = 2;
linear_extrude(height)
spiral_polygons(beginning_radius, line_width, fn, number_of_polygons);
module spiral_polygons(beginning_radius, line_width, fn, n) {
theta = 180 / fn;
y = beginning_radius - beginning_radius * cos(theta);
dr = y / cos(theta);
pw = pow((beginning_radius + dr) * sin(theta), 2);
2021-10-08 09:36:01 +08:00
half_line_width = line_width / 2;
2021-03-24 08:34:07 +08:00
function a(ri, ro, i) = acos((pow(ro, 2) + pow(ri, 2) - pw * pow(0.985, i)) / (2 * ro * ri));
module drawPolygon(r) {
pts = shape_circle(radius = r, $fn = fn);
polyline_join([each pts, pts[0]])
2021-10-08 09:36:01 +08:00
circle(half_line_width, $fn = 12);
2021-03-24 08:34:07 +08:00
}
rs = [for(i = [0: n - 1]) beginning_radius + i * dr];
as = [for(i = [1: n - 1]) a(rs[i - 1], rs[i], i) / 2];
rotate(-as[0])
drawPolygon(beginning_radius);
for(i = [1:n - 1]) {
rotate(sum([for(j = [0:i - 1]) as[j]]))
drawPolygon(rs[i]);
}
}