1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-16 11:44:50 +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) =
i == leng ? [] :
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]
)
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) =
go_maze(
start[0], start[1],
start.x, start.y,
is_undef(init_cells) ? mz_square_initialize(rows, columns) : init_cells,
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(
divided_ratio = 1.5,
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(
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,
axis = v / norm(v),
s = sin(half_a),
x = s * axis[0],
y = s * axis[1],
z = s * axis[2],
x = s * axis.x,
y = s * axis.y,
z = s * axis.z,
w = cos(half_a),
x2 = x + x,
@@ -36,31 +36,31 @@ function _rotx(pt, a) =
a == 0 ? pt :
let(cosa = cos(a), sina = sin(a))
[
pt[0],
pt[1] * cosa - pt[2] * sina,
pt[1] * sina + pt[2] * cosa
pt.x,
pt.y * cosa - pt[2] * sina,
pt.y * sina + pt[2] * cosa
];
function _roty(pt, a) =
a == 0 ? pt :
let(cosa = cos(a), sina = sin(a))
[
pt[0] * cosa + pt[2] * sina,
pt[1],
-pt[0] * sina + pt[2] * cosa,
pt.x * cosa + pt.z * sina,
pt.y,
-pt.x * sina + pt.z * cosa,
];
function _rotz(pt, a) =
a == 0 ? pt :
let(cosa = cos(a), sina = sin(a))
[
pt[0] * cosa - pt[1] * sina,
pt[0] * sina + pt[1] * cosa,
pt[2]
pt.x * cosa - pt.y * sina,
pt.x * sina + pt.y * cosa,
pt.z
];
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) =
let(angle = __to_ang_vect(a))

View File

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

View File

@@ -11,9 +11,9 @@
function ptf_circle(size, point) =
let(
p_offset = -size / 2,
p = [point[0] + p_offset[1], point[1] + p_offset[0]],
n = max(abs(p[0]), abs(p[1])),
p = [point.x + p_offset.y, point.y + p_offset.x],
n = max(abs(p.x), abs(p.y)),
r = n * 1.414,
a = atan2(p[0], p[1])
a = atan2(p.x, p.y)
)
[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) =
let(
yleng = size[1],
a_step = angle / yleng,
a_step = angle / size.y,
twisted = ptf_y_twist(size, point, twist)
)
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]) =
let(
x = point[0],
y = point[1],
z = is_undef(point[2]) ? 0 : point[2],
z = is_undef(point.z) ? 0 : point.z,
za = angle[0],
xa = angle[1],
xlen = size[0],
ylen = size[1],
za_step = za / ylen,
rza = za_step * y,
za_step = za / size.y,
rza = za_step * point.y,
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;

View File

@@ -9,8 +9,8 @@
**/
module vrn2_from(points, spacing = 1, r = 0, delta = 0, chamfer = false, region_type = "square") {
xs = [for(p = points) p[0]];
ys = [for(p = points) abs(p[1])];
xs = [for(p = points) p.x];
ys = [for(p = points) abs(p.y)];
region_size = max([(max(xs) - min(xs) / 2), (max(ys) - min(ys)) / 2]);
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]) {
v = p - pt;
translate((pt + p) / 2 - normalize(v) * offset_leng)
rotate(atan2(v[1], v[0]))
rotate(atan2(v.y, v.x))
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) {
v = p - pt;
translate((pt + p) / 2 - normalize(v) * offset_leng)
rotate(atan2(v[1], v[0]))
rotate(atan2(v.y, v.x))
children();
}
}

View File

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