圓柱與環面迷宮

March 17, 2022

圓柱迷宮

half_thickness = wall_thickness / 2;
polyline_join([[radius, 0, 0], [arc_x, arc_y, 0]]) {
sphere(half_thickness, \$fn = 5);
rotate(a)
sphere(half_thickness, \$fn = 5);
}
}

dotSCAD 的 mz_square 可以設定 x_wrapping 參數為 true，讓 x 方向的路徑像圓柱接合後可以左右互通，因此想完成圓柱迷宮可以如下撰寫：

\$fn = 36;
layers = 5;
wall_thickness = 6;

half_thickness = wall_thickness / 2;
polyline_join([[radius, 0, 0], [arc_x, arc_y, 0]]) {
sphere(half_thickness, \$fn = 5);
rotate(a)
sphere(half_thickness, \$fn = 5);
}
}

rows = layers;
columns = \$fn;

cell_width = 2 * PI * radius / \$fn;
a_step = 360 / \$fn;
half_thickness = wall_thickness / 2;

cells = mz_square(rows, columns, x_wrapping = true);

for(row = cells, cell = row) {
x = mz_square_get(cell, "x");
y = mz_square_get(cell, "y");
type = mz_square_get(cell, "t");

h = y * cell_width;
a = a_step * x;

rotate(a)
translate([0, 0, h])
// 繪製單一細胞的牆
{
if(type == "TOP_WALL" || type == "TOP_RIGHT_WALL") {
translate([0, 0, cell_width])
}

if(type == "RIGHT_WALL" || type == "TOP_RIGHT_WALL") {
rotate(a_step)
sphere(half_thickness, \$fn = 5);
}
}

// 繪製最底層的牆
if(y == 0) {
rotate(a)
}
}
}

ptf_bend 函式

\$fn = 36;
layers = 5;
wall_thickness = 6;

rows = layers;
columns = \$fn;

cell_width = 2 * PI * radius / \$fn;
half_thickness = wall_thickness / 2;
size = [columns, rows] * cell_width;

cells = mz_square(rows, columns, x_wrapping = true);
walls = mz_squarewalls(cells, cell_width, left_border = false);

for(wall = walls) {
bended = [for(p = wall) ptf_bend(size, p, radius, 360)];
polyline_join(bended)
sphere(half_thickness, \$fn = 5);
}
}

環面迷宮／ptf_torus

\$fn = 12;
r1 = 100;
r2 = 50;
wall_thickness = 10;

torus_maze(r1, r2, wall_thickness);

module torus_maze(r1, r2, wall_thickness) {
rows = \$fn * 3;
columns = \$fn;

cell_width = 2 * PI * r1 / \$fn;
half_thickness = wall_thickness / 2;
size = [columns, rows] * cell_width;

cells = mz_square(rows, columns, x_wrapping = true, y_wrapping = true);
walls = mz_squarewalls(cells, cell_width, left_border = false);

for(wall = walls) {
bended = [for(p = wall) ptf_torus(size, p, [r1, r2], [360, 360])];
polyline_join(bended)
sphere(half_thickness, \$fn = 5);
}
}

color("black")
rotate_extrude()
translate([r1 + r2, 0])
circle(r2);