1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-17 12:10:47 +02:00

dot notation indexing

This commit is contained in:
Justin Lin
2021-12-04 10:16:45 +08:00
parent 14a6348771
commit 324693a38f
11 changed files with 33 additions and 40 deletions

View File

@@ -48,7 +48,7 @@ _mz_hamiltonian_nxt_offset = [
function _mz_hamiltonian_travel(dot_pts, p, leng, i = 0) = function _mz_hamiltonian_travel(dot_pts, p, leng, i = 0) =
i == leng ? [] : i == leng ? [] :
let( let(
dir_i = _mz_hamiltonian_dir(_mz_hamiltonian_corner_value(dot_pts, p[0], p[1])), dir_i = _mz_hamiltonian_dir(_mz_hamiltonian_corner_value(dot_pts, p.x, p.y)),
nxt_p = p + _mz_hamiltonian_nxt_offset[dir_i] nxt_p = p + _mz_hamiltonian_nxt_offset[dir_i]
) )
concat( concat(

View File

@@ -13,7 +13,7 @@ use <mz_square_initialize.scad>;
function mz_square_cells(rows, columns, start = [0, 0], init_cells, x_wrapping = false, y_wrapping = false, seed) = function mz_square_cells(rows, columns, start = [0, 0], init_cells, x_wrapping = false, y_wrapping = false, seed) =
go_maze( go_maze(
start[0], start[1], start.x, start.y,
is_undef(init_cells) ? mz_square_initialize(rows, columns) : init_cells, is_undef(init_cells) ? mz_square_initialize(rows, columns) : init_cells,
rows, columns, x_wrapping, y_wrapping, seed rows, columns, x_wrapping, y_wrapping, seed
); );

View File

@@ -14,7 +14,7 @@ function mz_theta_cells(rows, beginning_number, start = [0, 0], seed) =
let( let(
divided_ratio = 1.5, divided_ratio = 1.5,
before_traveled = config_nbrs(init_theta_maze(rows, beginning_number, divided_ratio)), before_traveled = config_nbrs(init_theta_maze(rows, beginning_number, divided_ratio)),
s = set_visited(before_traveled[start[0]][start[1]]) s = set_visited(before_traveled[start.x][start.y])
) )
backtracker( backtracker(
update_maze(before_traveled, s), start, rows, seed); update_maze(before_traveled, s), start, rows, seed);

View File

@@ -7,9 +7,9 @@ function _q_rotate_p_3d(p, a, v) =
half_a = a / 2, half_a = a / 2,
axis = v / norm(v), axis = v / norm(v),
s = sin(half_a), s = sin(half_a),
x = s * axis[0], x = s * axis.x,
y = s * axis[1], y = s * axis.y,
z = s * axis[2], z = s * axis.z,
w = cos(half_a), w = cos(half_a),
x2 = x + x, x2 = x + x,
@@ -36,31 +36,31 @@ function _rotx(pt, a) =
a == 0 ? pt : a == 0 ? pt :
let(cosa = cos(a), sina = sin(a)) let(cosa = cos(a), sina = sin(a))
[ [
pt[0], pt.x,
pt[1] * cosa - pt[2] * sina, pt.y * cosa - pt[2] * sina,
pt[1] * sina + pt[2] * cosa pt.y * sina + pt[2] * cosa
]; ];
function _roty(pt, a) = function _roty(pt, a) =
a == 0 ? pt : a == 0 ? pt :
let(cosa = cos(a), sina = sin(a)) let(cosa = cos(a), sina = sin(a))
[ [
pt[0] * cosa + pt[2] * sina, pt.x * cosa + pt.z * sina,
pt[1], pt.y,
-pt[0] * sina + pt[2] * cosa, -pt.x * sina + pt.z * cosa,
]; ];
function _rotz(pt, a) = function _rotz(pt, a) =
a == 0 ? pt : a == 0 ? pt :
let(cosa = cos(a), sina = sin(a)) let(cosa = cos(a), sina = sin(a))
[ [
pt[0] * cosa - pt[1] * sina, pt.x * cosa - pt.y * sina,
pt[0] * sina + pt[1] * cosa, pt.x * sina + pt.y * cosa,
pt[2] pt.z
]; ];
function _rotate_p_3d(point, a) = function _rotate_p_3d(point, a) =
_rotz(_roty(_rotx(point, a[0]), a[1]), a[2]); _rotz(_roty(_rotx(point, a.x), a.y), a.z);
function _rotate_p(p, a) = function _rotate_p(p, a) =
let(angle = __to_ang_vect(a)) let(angle = __to_ang_vect(a))

View File

@@ -10,13 +10,11 @@
function ptf_bend(size, point, radius, angle) = function ptf_bend(size, point, radius, angle) =
let( let(
xlen = size[0], // ignored: size.y,
// ignored
// ylen = size[1],
y = point[0], y = point[0],
z = point[1], z = point[1],
x = is_undef(point[2]) ? 0 : point[2], x = is_undef(point[2]) ? 0 : point[2],
a_step = angle / xlen, a_step = angle / size.x,
a = a_step * y, a = a_step * y,
r = radius + x r = radius + x
) )

View File

@@ -11,9 +11,9 @@
function ptf_circle(size, point) = function ptf_circle(size, point) =
let( let(
p_offset = -size / 2, p_offset = -size / 2,
p = [point[0] + p_offset[1], point[1] + p_offset[0]], p = [point.x + p_offset.y, point.y + p_offset.x],
n = max(abs(p[0]), abs(p[1])), n = max(abs(p.x), abs(p.y)),
r = n * 1.414, r = n * 1.414,
a = atan2(p[0], p[1]) a = atan2(p.x, p.y)
) )
[r * cos(a), r * sin(a)]; [r * cos(a), r * sin(a)];

View File

@@ -13,8 +13,7 @@ use <ptf_y_twist.scad>;
function ptf_ring(size, point, radius, angle = 360, twist = 0) = function ptf_ring(size, point, radius, angle = 360, twist = 0) =
let( let(
yleng = size[1], a_step = angle / size.y,
a_step = angle / yleng,
twisted = ptf_y_twist(size, point, twist) twisted = ptf_y_twist(size, point, twist)
) )
ptf_rotate([radius + twisted[0], 0, twisted[2]], a_step * twisted[1]); ptf_rotate([radius + twisted[0], 0, twisted[2]], a_step * twisted[1]);

View File

@@ -12,16 +12,12 @@ use <ptf_rotate.scad>;
function ptf_sphere(size, point, radius, angle = [180, 360]) = function ptf_sphere(size, point, radius, angle = [180, 360]) =
let( let(
x = point[0], z = is_undef(point.z) ? 0 : point.z,
y = point[1],
z = is_undef(point[2]) ? 0 : point[2],
za = angle[0], za = angle[0],
xa = angle[1], xa = angle[1],
xlen = size[0], za_step = za / size.y,
ylen = size[1], rza = za_step * point.y,
za_step = za / ylen,
rza = za_step * y,
rzpt = [(radius + z) * cos(rza), (radius + z) * sin(rza), 0], rzpt = [(radius + z) * cos(rza), (radius + z) * sin(rza), 0],
rxpt = ptf_rotate(rzpt, [90 - xa / xlen * x, 90, 0]) rxpt = ptf_rotate(rzpt, [90 - xa / size.x * point.x, 90, 0])
) )
rxpt; rxpt;

View File

@@ -9,8 +9,8 @@
**/ **/
module vrn2_from(points, spacing = 1, r = 0, delta = 0, chamfer = false, region_type = "square") { module vrn2_from(points, spacing = 1, r = 0, delta = 0, chamfer = false, region_type = "square") {
xs = [for(p = points) p[0]]; xs = [for(p = points) p.x];
ys = [for(p = points) abs(p[1])]; ys = [for(p = points) abs(p.y)];
region_size = max([(max(xs) - min(xs) / 2), (max(ys) - min(ys)) / 2]); region_size = max([(max(xs) - min(xs) / 2), (max(ys) - min(ys)) / 2]);
half_region_size = 0.5 * region_size; half_region_size = 0.5 * region_size;
@@ -22,7 +22,7 @@ module vrn2_from(points, spacing = 1, r = 0, delta = 0, chamfer = false, region_
intersection_for(p = [for(p = points) if(pt != p) p]) { intersection_for(p = [for(p = points) if(pt != p) p]) {
v = p - pt; v = p - pt;
translate((pt + p) / 2 - normalize(v) * offset_leng) translate((pt + p) / 2 - normalize(v) * offset_leng)
rotate(atan2(v[1], v[0])) rotate(atan2(v.y, v.x))
children(); children();
} }
} }

View File

@@ -51,7 +51,7 @@ module vrn2_space(size, grid_w, seed, spacing = 1, r = 0, delta = 0, chamfer = f
intersection_for(p = points) { intersection_for(p = points) {
v = p - pt; v = p - pt;
translate((pt + p) / 2 - normalize(v) * offset_leng) translate((pt + p) / 2 - normalize(v) * offset_leng)
rotate(atan2(v[1], v[0])) rotate(atan2(v.y, v.x))
children(); children();
} }
} }

View File

@@ -13,9 +13,9 @@ use <__comm__/__angy_angz.scad>;
// slow but workable // slow but workable
module vrn3_from(points, spacing = 1) { module vrn3_from(points, spacing = 1) {
xs = [for(p = points) p[0]]; xs = [for(p = points) p.x];
ys = [for(p = points) abs(p[1])]; ys = [for(p = points) abs(p.y)];
zs = [for(p = points) abs(p[2])]; zs = [for(p = points) abs(p.z)];
space_size = max([max(xs) - min(xs), max(ys) - min(ys), max(zs) - min(zs)]); space_size = max([max(xs) - min(xs), max(ys) - min(ys), max(zs) - min(zs)]);
half_space_size = 0.5 * space_size; half_space_size = 0.5 * space_size;