mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-18 20:41:18 +02:00
change dir
This commit is contained in:
38
examples/spiral_polygons/spiral_polygons.scad
Normal file
38
examples/spiral_polygons/spiral_polygons.scad
Normal file
@@ -0,0 +1,38 @@
|
||||
use <shape_circle.scad>;
|
||||
use <hull_polyline2d.scad>;
|
||||
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);
|
||||
|
||||
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);
|
||||
hull_polyline2d(concat(pts, [pts[0]]), width = line_width, $fn = 12);
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
83
examples/spiral_polygons/stick_tower.scad
Normal file
83
examples/spiral_polygons/stick_tower.scad
Normal file
@@ -0,0 +1,83 @@
|
||||
use <line3d.scad>;
|
||||
|
||||
/* [Basic] */
|
||||
|
||||
stick_leng = 80;
|
||||
stick_diameter = 5;
|
||||
inner_square_leng = 60;
|
||||
leng_diff = 1.75;
|
||||
min_leng = 13;
|
||||
stick_fn = 24;
|
||||
|
||||
/* [Advanced] */
|
||||
|
||||
cap_style = "CAP_CIRCLE"; // [CAP_BUTT, CAP_CIRCLE, CAP_SPHERE]
|
||||
angle_offset = 5;
|
||||
layer_offset = 1.2;
|
||||
|
||||
module stick_square(inner_square_leng, stick_leng, stick_diameter, cap_style) {
|
||||
diff_leng = stick_leng - inner_square_leng;
|
||||
half_inner_square_leng = inner_square_leng / 2;
|
||||
half_stick_leng = stick_leng / 2;
|
||||
|
||||
module stick() {
|
||||
line3d(
|
||||
[0, -half_stick_leng, 0],
|
||||
[0, half_stick_leng, 0],
|
||||
stick_diameter,
|
||||
cap_style,
|
||||
cap_style
|
||||
);
|
||||
}
|
||||
|
||||
module sticks() {
|
||||
translate([-half_inner_square_leng, 0, 0])
|
||||
stick();
|
||||
translate([half_inner_square_leng, 0, 0])
|
||||
stick();
|
||||
}
|
||||
|
||||
sticks();
|
||||
translate([0, 0, stick_diameter])
|
||||
rotate(90)
|
||||
sticks();
|
||||
}
|
||||
|
||||
module spiral_stack(orig_leng, orig_height, current_leng, leng_diff, min_leng, angle_offset, pre_height = 0, i = 0) {
|
||||
if(current_leng > min_leng) {
|
||||
angle = atan2(leng_diff, current_leng - leng_diff);
|
||||
|
||||
factor = current_leng / orig_leng;
|
||||
|
||||
translate([0, 0, pre_height])
|
||||
scale(factor)
|
||||
children();
|
||||
|
||||
next_square_leng = sqrt(pow(leng_diff, 2) + pow(current_leng - leng_diff, 2));
|
||||
|
||||
height = factor * orig_height + pre_height;
|
||||
|
||||
rotate(angle + angle_offset)
|
||||
spiral_stack(
|
||||
orig_leng,
|
||||
orig_height,
|
||||
next_square_leng,
|
||||
leng_diff,
|
||||
min_leng,
|
||||
angle_offset,
|
||||
height,
|
||||
i + 1
|
||||
) children();
|
||||
}
|
||||
}
|
||||
|
||||
height = stick_diameter * layer_offset;
|
||||
$fn = stick_fn;
|
||||
|
||||
spiral_stack(inner_square_leng, stick_diameter * 2, inner_square_leng, leng_diff, min_leng, angle_offset)
|
||||
stick_square(
|
||||
inner_square_leng,
|
||||
stick_leng,
|
||||
height,
|
||||
cap_style
|
||||
);
|
Reference in New Issue
Block a user