1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-02-23 00:52:30 +01:00
dotSCAD/examples/taiwan/spiral_cube.scad

87 lines
2.3 KiB
OpenSCAD
Raw Normal View History

2020-01-28 09:52:16 +08:00
use <crystal_ball.scad>;
2019-10-04 09:50:33 +08:00
2019-09-14 20:59:50 +08:00
leng = 30;
leng_diff = 3;
min_leng = 2;
2020-01-28 09:52:16 +08:00
model = "Cube"; // [Cube, Base]
2019-09-14 20:59:50 +08:00
module spiral_cube(leng, leng_diff, min_leng) {
2019-09-15 08:06:45 +08:00
thickness = leng_diff / 3;
2019-09-14 20:59:50 +08:00
starting_leng = leng + leng_diff * 2 + thickness * 2.5;
half_leng = leng / 2;
pow_leng_diff = pow(leng_diff, 2);
module spiral_stack(current_leng, pre_height = 0, i = 0) {
factor = current_leng / starting_leng;
2019-09-15 08:06:45 +08:00
if(current_leng > min_leng && current_leng > leng_diff && half_leng > pre_height) {
2019-09-14 20:59:50 +08:00
translate([0, 0, pre_height])
2019-09-26 08:53:47 +08:00
scale([factor, factor, 1])
children();
2019-09-14 20:59:50 +08:00
rotate(atan2(leng_diff, current_leng - leng_diff))
2019-09-26 08:53:47 +08:00
spiral_stack(
sqrt(pow_leng_diff + pow(current_leng - leng_diff, 2)),
thickness + pre_height,
i + 1
) children();
2019-09-14 20:59:50 +08:00
}
2019-09-15 08:06:45 +08:00
else if(half_leng > pre_height) {
2019-09-14 20:59:50 +08:00
translate([0, 0, pre_height])
2019-09-26 08:53:47 +08:00
scale([factor, factor, (half_leng - pre_height) / thickness])
children();
2019-09-14 20:59:50 +08:00
}
}
module spiral_squares() {
2019-09-15 08:06:45 +08:00
difference() {
translate([0, 0, -half_leng])
2019-09-26 08:53:47 +08:00
spiral_stack(leng)
translate([0, 0, thickness / 2])
cube([leng , leng, thickness], center = true);
2019-09-15 08:06:45 +08:00
translate([0, 0, 0.001])
2019-09-26 08:53:47 +08:00
linear_extrude(leng)
square(leng, center = true);
2019-09-15 08:06:45 +08:00
}
2019-09-14 20:59:50 +08:00
}
module pair_spiral_squares() {
spiral_squares();
2019-09-15 08:06:45 +08:00
// mirror([0, 0, 1])
rotate([180, 0, 0])
2019-09-14 20:59:50 +08:00
spiral_squares();
}
difference() {
cube(leng * 0.99, center = true);
union() {
pair_spiral_squares();
rotate([90, 0, 0]) pair_spiral_squares();
rotate([0, 90, 0]) pair_spiral_squares();
}
}
}
module base(leng) {
$fn = 96;
r = leng / 3;
difference() {
2019-10-04 09:50:33 +08:00
crystal_ball(
radius = r,
theta = 360,
phi = 90
);
2019-09-14 20:59:50 +08:00
translate([0, 0, leng * sqrt(3) / 2 + leng / 15])
2019-09-26 08:53:47 +08:00
rotate([45, atan2(1, sqrt(2)), 0])
cube(leng * 0.99, center = true);
2019-09-14 20:59:50 +08:00
}
}
if(model == "Cube") {
spiral_cube(leng, leng_diff, min_leng);
} else if(model == "Base") {
base(leng);
2019-09-15 08:45:58 +08:00
}
2019-09-14 20:59:50 +08:00