From 00756bee24fda4dc0be568bdda10522e1e74be43 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sun, 28 Feb 2021 10:34:56 +0800 Subject: [PATCH] add theta_maze --- examples/maze/theta_maze.scad | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 examples/maze/theta_maze.scad diff --git a/examples/maze/theta_maze.scad b/examples/maze/theta_maze.scad new file mode 100644 index 00000000..96be35e5 --- /dev/null +++ b/examples/maze/theta_maze.scad @@ -0,0 +1,54 @@ +use ; +use ; +use ; + +rows = 16; +begining_columns = 8; +divided_ratio = 1.5; +cell_width = 10; +wall_thickness = 2; +wall_height = 5; + +theta_maze(rows, begining_columns, divided_ratio, cell_width, wall_thickness, wall_height); + +module theta_maze(rows, begining_columns, divided_ratio, cell_width, wall_thickness, wall_height) { + + function vt_from_angle(theta, r) = [r * cos(theta), r * sin(theta)]; + + maze = mz_theta_cells(rows, begining_columns, divided_ratio); + + linear_extrude(wall_height) { + for(rows = maze) { + for(cell = rows) { + ri = mz_theta_get(cell, "r"); + ci = mz_theta_get(cell, "c"); + wallType = mz_theta_get(cell, "t"); + thetaStep = 360 / len(maze[ri]); + innerR = (ri + 1) * cell_width; + outerR = (ri + 2) * cell_width; + theta1 = thetaStep * ci; + theta2 = thetaStep * (ci + 1); + + innerVt1 = vt_from_angle(theta1, innerR); + innerVt2 = vt_from_angle(theta2, innerR); + outerVt2 = vt_from_angle(theta2, outerR); + + if(wallType == "INWARD_WALL" || wallType == "INWARD_CCW_WALL") { + hull_polyline2d([innerVt1, innerVt2], width = wall_thickness); + } + + if(wallType == "CCW_WALL" || wallType == "INWARD_CCW_WALL") { + hull_polyline2d([innerVt2, outerVt2], width = wall_thickness); + } + } + } + + thetaStep = 360 / len(maze[rows - 1]); + r = cell_width * (rows + 1); + for(theta = [0:thetaStep:360 - thetaStep]) { + vt1 = vt_from_angle(theta, r); + vt2 = vt_from_angle(theta + thetaStep, r); + hull_polyline2d([vt1, vt2], width = wall_thickness); + } + } +} \ No newline at end of file