1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-02-24 01:22:27 +01:00
dotSCAD/examples/spiral_polygons/fidget_polygon.scad

111 lines
2.6 KiB
OpenSCAD
Raw Normal View History

2021-06-07 11:31:57 +08:00
model = "POLYGON"; // [POLYGON, BASE, BOTH]
2021-06-01 06:43:33 +08:00
beginning_radius = 7.5;
2021-06-02 10:46:21 +08:00
fn = 4;
2021-06-02 10:51:22 +08:00
number_of_polygons = 10;
2021-06-02 12:45:22 +08:00
height = 20;
2021-06-01 06:43:33 +08:00
thickness = 1.5;
2021-06-03 10:19:42 +08:00
spacing = 0.5 * thickness;
2021-06-06 09:39:43 +08:00
slope = 1.2;
2021-06-07 11:31:57 +08:00
base_height = height * 1.75;
2021-06-01 06:43:33 +08:00
2021-06-07 11:31:57 +08:00
fidget_polygon(model, beginning_radius, fn, number_of_polygons, height, thickness, spacing, slope, base_height);
2021-06-01 06:43:33 +08:00
2021-06-07 11:31:57 +08:00
module fidget_polygon(model, beginning_radius, fn, n, height, thickness, spacing, slope, base_height) {
2021-06-01 06:43:33 +08:00
theta = 180 / fn;
2021-06-02 10:46:21 +08:00
2021-06-01 06:43:33 +08:00
y = beginning_radius - beginning_radius * cos(theta);
2021-06-03 10:19:42 +08:00
dr = y / cos(theta) + thickness + spacing;
2021-06-01 06:43:33 +08:00
pw = pow((beginning_radius + dr) * sin(theta), 2);
2021-06-03 10:19:42 +08:00
// function a(ri, ro, i) = acos((pow(ro, 2) + pow(ri, 2) - pw * pow(0.985, i)) / (2 * ro * ri));
2021-06-01 06:43:33 +08:00
module drawPolygon(r) {
circle(r, $fn = fn);
}
2021-06-07 11:31:57 +08:00
rs = [for(i = [0: n + 1]) beginning_radius + i * dr];
2021-06-01 06:43:33 +08:00
//as = [for(i = [1: n]) a(rs[i - 1], rs[i], i) / 2];
half_height = height / 2;
2021-06-03 10:19:42 +08:00
2021-06-07 11:31:57 +08:00
s = [for(i = [1: n + 1]) (rs[i] + slope * half_height) / rs[i]];
2021-06-06 09:39:43 +08:00
2021-06-01 06:43:33 +08:00
module half() {
translate([0, 0, -half_height]) {
linear_extrude(half_height, scale = s[0])
difference() {
drawPolygon(beginning_radius);
drawPolygon(beginning_radius - thickness);
}
2021-06-02 10:51:22 +08:00
for(i = [1:n - 1]) {
2021-06-01 06:43:33 +08:00
//rotate(as[i] * 2)
linear_extrude(half_height, scale = s[i])
difference() {
drawPolygon(rs[i]);
drawPolygon(rs[i] - thickness);
}
}
}
}
2021-06-07 11:31:57 +08:00
if(model == "POLYGON" || model == "BOTH") {
half();
mirror([0, 0, 1])
half();
}
// base
ring_thickness = thickness * 1.5;
module base_ring() {
translate([0, 0, -ring_thickness])
difference() {
linear_extrude(ring_thickness, scale = 1.02)
offset(ring_thickness / 3, $fn = n)
drawPolygon(rs[n] * s[n] - thickness);
linear_extrude(thickness * 4, center = true)
drawPolygon(rs[n] * s[n] - ring_thickness);
}
}
if(model == "BASE" || model == "BOTH") {
color("white") {
// plate
translate([0, 0, -half_height])
linear_extrude(half_height, scale = s[n])
difference() {
drawPolygon(rs[n]);
drawPolygon(rs[n] - thickness);
}
// ring
base_ring();
mirror([0, 0, 1])
base_ring();
translate([0, 0, -base_height + ring_thickness])
mirror([0, 0, 1])
scale([1, 1, 1.5])
base_ring();
// stick
d = rs[n] * s[n];
off_h = -base_height + ring_thickness;
a = 180 / fn;
stick_r = thickness * 1.75;
stick_h = base_height - ring_thickness;
for(i = [0:fn - 1]) {
rotate(360 / fn * i)
translate([d, 0, off_h])
rotate(a) {
linear_extrude(stick_h)
circle(stick_r, $fn = fn);
translate([0, 0, stick_h])
linear_extrude(ring_thickness, scale = 0.75)
circle(stick_r, $fn = fn);
}
}
}
}
2021-06-01 06:43:33 +08:00
}