1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-12 01:34:12 +02:00
This commit is contained in:
Justin Lin
2022-03-01 15:52:17 +08:00
parent 8475049fad
commit 96ec1e0c26
14 changed files with 96 additions and 167 deletions

View File

@@ -49,7 +49,7 @@ module along_with(points, angles, twist = 0, scale = 1.0, method = "AXIS_ANGLE")
let(
vt0 = pts[i] - pts[i - 1],
vt1 = pts[i + 1] - pts[i],
a = acos((vt0 * vt1) / (norm(vt0) * norm(vt1))),
a = acos((vt0 * vt1) / sqrt((vt0 * vt0) * (vt1 * vt1))),
v = cross(vt0, vt1)
)
[a, v]

View File

@@ -23,8 +23,8 @@ function _tri_circumcircle(shape_pts) =
)
det == 0 ? undef :
let(
x = (d1 * v0[1] - d0 * v1[1]) / det,
y = (d0 * v1[0] - d1 * v0[0]) / det,
x = (d1 * v0.y - d0 * v1.y) / det,
y = (d0 * v1.x - d1 * v0.x) / det,
center = [x, y],
v = p0 - center
)
@@ -179,10 +179,9 @@ function delaunayBadTriangles(d, p, _indices_hash) =
function inCircumcircle(t, p, circles, _indices_hash) =
let(
c = hashmap_get(circles, t, hash = _indices_hash),
ct = cc_center(c),
rr = (ct[0] - p[0]) ^ 2 + (ct[1] - p[1]) ^ 2
v = cc_center(c) - p
)
rr <= cc_rr(c);
v * v <= cc_rr(c);
function delaunayBoundaries(d, badTriangles, _indices_hash) =
let(

View File

@@ -14,13 +14,7 @@ function _triangulate_snipable(shape_pts, u, v, w, n, indices, epsilon = 0.0001)
a = shape_pts[indices[u]],
b = shape_pts[indices[v]],
c = shape_pts[indices[w]],
ax = a[0],
ay = a[1],
bx = b[0],
by = b[1],
cx = c[0],
cy = c[1],
determinant = cross([bx - ax, by - ay], [cx - ax, cy - ay])
determinant = cross([b.x - a.x, b.y - a.y], [c.x - a.x, c.y - a.y])
)
epsilon > determinant ?
false : _triangulate_snipable_sub(shape_pts, n, u, v, w, a, b, c, indices);
@@ -35,9 +29,7 @@ function _triangulate_snipable_sub(shape_pts, n, u, v, w, a, b, c, indices, p =
// remove the elem at idx v from indices
function _triangulate_remove_v(indices, v, num_of_vertices) =
let(
nv_minuns_one = num_of_vertices - 1
)
let(nv_minuns_one = num_of_vertices - 1)
v == 0 ? [for(i = 1; i <= nv_minuns_one; i = i + 1) indices[i]] : (
v == nv_minuns_one ? [for(i = 0; i < v; i = i + 1) indices[i]] : concat(
[for(i = 0; i < v; i = i + 1) indices[i]],

View File

@@ -20,6 +20,6 @@ function tri_circumcenter(shape_pts) =
det = -cross(v0 , v1)
)
det == 0 ? undef : [
(d1 * v0[1] - d0 * v1[1]) / det,
(d0 * v1[0] - d1 * v0[0]) / det
(d1 * v0.y - d0 * v1.y) / det,
(d0 * v1.x - d1 * v0.x) / det
];

View File

@@ -24,8 +24,8 @@ function tri_delaunay(points, ret = "TRI_INDICES") =
max_y = max(ys),
min_y = min(ys),
center = [max_x + min_x, max_y + min_y] / 2,
width = abs(max_x - center[0]) * 4,
height = abs(max_y - center[1]) * 4,
width = abs(max_x - center.x) * 4,
height = abs(max_y - center.y) * 4,
leng_pts = len(points),
d = _tri_delaunay(
delaunay_init(center, width, height, leng_pts, _indices_hash),

View File

@@ -10,4 +10,4 @@
use <../__comm__/__angy_angz.scad>;
function polar_coordinate(point) = [norm(point), atan2(point[1], point[0])]; // r, theta
function polar_coordinate(point) = [norm(point), atan2(point.y, point.x)]; // r, theta

View File

@@ -12,6 +12,6 @@ function spherical_coordinate(point) =
// mathematics [r, theta, phi]
[
norm(point),
atan2(point[1], point[0]),
atan2(sqrt(point[0]^2 + point[1]^2), point[2])
atan2(point.y, point.x),
atan2(sqrt(point.x ^ 2 + point.y ^ 2), point.z)
];

View File

@@ -8,4 +8,6 @@
*
**/
function sum(lt) = [for(i = [0:len(lt) - 1]) 1] * lt;
function sum(lt) =
let(leng = len(lt))
[for(i = 0; i < leng; i = i + 1) 1] * lt;

View File

@@ -26,7 +26,7 @@ _vx_contour_nxt_offset = [
];
function _vx_contour_travel(pts, p, fst) =
let(
dir_i = _vx_contour_dir(_vx_contour_corner_value(pts, p[0], p[1])),
dir_i = _vx_contour_dir(_vx_contour_corner_value(pts, p.x, p.y)),
nxt_p = p + _vx_contour_nxt_offset[dir_i]
)
nxt_p == fst ? [p] : [p, each _vx_contour_travel(pts, nxt_p, fst)];

View File

@@ -1,20 +1,18 @@
function _vx_cylinder_vx_circle(radius, filled, thickness) =
let(range = [-radius: radius - 1])
filled ? [
for(y = range)
for(x = range)
let(v = [x, y])
if(norm(v) < radius) v
for(y = range, x = range)
let(v = [x, y])
if(norm(v) < radius) v
] :
let(ishell = radius * radius - 2 * thickness * radius)
let(ishell = radius ^ 2 - 2 * thickness * radius)
[
for(y = range)
for(x = range)
let(
v = [x, y],
leng = norm(v)
)
if(leng < radius && (leng * leng) > ishell) v
for(y = range, x = range)
let(
v = [x, y],
leng = norm(v)
)
if(leng < radius && (leng ^ 2) > ishell) v
];
function _vx_cylinder_diff_r(r, h, filled, thickness) =
@@ -29,7 +27,7 @@ function _vx_cylinder_diff_r(r, h, filled, thickness) =
let(r = round(r1 + dr * i))
each [
for(pt = _vx_cylinder_vx_circle(r, filled, thickness))
[pt[0], pt[1], i]
[pt.x, pt.y, i]
]
];
@@ -39,7 +37,7 @@ function _vx_cylinder_same_r(r, h, filled, thickness) =
for(i = 0; i < h; i = i + 1)
each [
for(pt = c)
[pt[0], pt[1], i]
[pt.x, pt.y, i]
]
];

View File

@@ -11,55 +11,37 @@ function _vx_line_xdominant_z(z, zd, sz) = zd >= 0 ? z + sz : z;
function _vx_line_xdominant_zd(zd, ax, az) = (zd >= 0 ? zd - ax : zd) + az;
function _vx_line_xdominant(start, end, a, s) =
let(
x = start[0],
y = start[1],
z = start[2],
ax = a[0],
ay = a[1],
az = a[2],
sx = s[0],
sy = s[1],
sz = s[2],
shrx = floor(ax / 2),
yd = ay - shrx,
zd = az - shrx,
endx = end[0]
let(
shrx = floor(a.x / 2),
yd = a.y - shrx,
zd = a.z - shrx
)
[
start,
each _vx_line_xdominant_sub(
x + sx,
_vx_line_xdominant_y(y, yd, sy),
_vx_line_xdominant_z(z, zd, sz),
endx,
start.x + s.x,
_vx_line_xdominant_y(start.y, yd, s.y),
_vx_line_xdominant_z(start.z, zd, s.z),
end.x,
a,
s,
_vx_line_xdominant_yd(yd, ax, ay),
_vx_line_xdominant_zd(zd, ax, az)
_vx_line_xdominant_yd(yd, a.x, a.y),
_vx_line_xdominant_zd(zd, a.x, a.z)
)
];
function _vx_line_xdominant_sub(x, y, z, endx, a, s, yd, zd) =
let(
ax = a[0],
ay = a[1],
az = a[2],
sx = s[0],
sy = s[1],
sz = s[2]
)
x == endx ? [] : [
[x, y, z],
each _vx_line_xdominant_sub(
x + sx,
_vx_line_xdominant_y(y, yd, sy),
_vx_line_xdominant_z(z, zd, sz),
x + s.x,
_vx_line_xdominant_y(y, yd, s.y),
_vx_line_xdominant_z(z, zd, s.z),
endx,
a,
s,
_vx_line_xdominant_yd(yd, ax, ay),
_vx_line_xdominant_zd(zd, ax, az)
_vx_line_xdominant_yd(yd, a.x, a.y),
_vx_line_xdominant_zd(zd, a.x, a.z)
)
];
@@ -70,55 +52,37 @@ function _vx_line_ydominant_z(z, zd, sz) = zd >= 0 ? z + sz : z;
function _vx_line_ydominant_zd(zd, ay, az) = (zd >= 0 ? zd - ay : zd) + az;
function _vx_line_ydominant(start, end, a, s) =
let(
x = start[0],
y = start[1],
z = start[2],
ax = a[0],
ay = a[1],
az = a[2],
sx = s[0],
sy = s[1],
sz = s[2],
shry = floor(ay / 2),
xd = ax - shry,
zd = az - shry,
endy = end[1]
let(
shry = floor(a.y / 2),
xd = a.x - shry,
zd = a.z - shry
)
[
start,
each _vx_line_ydominant_sub(
_vx_line_ydominant_x(x, xd, sx),
y + sy,
_vx_line_ydominant_z(z, zd, sz),
endy,
_vx_line_ydominant_x(start.x, xd, s.x),
start.y + s.y,
_vx_line_ydominant_z(start.z, zd, s.z),
end.y,
a,
s,
_vx_line_ydominant_xd(xd, ax, ay),
_vx_line_ydominant_zd(zd, ay, az)
_vx_line_ydominant_xd(xd, a.x, a.y),
_vx_line_ydominant_zd(zd, a.y, a.z)
)
];
function _vx_line_ydominant_sub(x, y, z, endy, a, s, xd, zd) =
let(
ax = a[0],
ay = a[1],
az = a[2],
sx = s[0],
sy = s[1],
sz = s[2]
)
y == endy ? [] : [
[x, y, z],
each _vx_line_ydominant_sub(
_vx_line_ydominant_x(x, xd, sx),
y + sy,
_vx_line_ydominant_z(z, zd, sz),
_vx_line_ydominant_x(x, xd, s.x),
y + s.y,
_vx_line_ydominant_z(z, zd, s.z),
endy,
a,
s,
_vx_line_ydominant_xd(xd, ax, ay),
_vx_line_ydominant_zd(zd, ay, az)
_vx_line_ydominant_xd(xd, a.x, a.y),
_vx_line_ydominant_zd(zd, a.y, a.z)
)
];
@@ -130,55 +94,37 @@ function _vx_line_zdominant_y(y, yd, sy) = yd >= 0 ? y + sy : y;
function _vx_line_zdominant_yd(yd, ay, az) = (yd >= 0 ? yd - az : yd) + ay;
function _vx_line_zdominant(start, end, a, s) =
let(
x = start[0],
y = start[1],
z = start[2],
ax = a[0],
ay = a[1],
az = a[2],
sx = s[0],
sy = s[1],
sz = s[2],
shrz = floor(az / 2),
xd = ax - shrz,
yd = ay - shrz,
endz = end[2]
let(
shrz = floor(a.z / 2),
xd = a.x - shrz,
yd = a.y - shrz
)
[
start,
each _vx_line_zdominant_sub(
_vx_line_zdominant_x(x, xd, sx),
_vx_line_zdominant_y(y, yd, sy),
z + sz,
endz,
_vx_line_zdominant_x(start.x, xd, s.x),
_vx_line_zdominant_y(start.y, yd, s.y),
start.z + s.z,
end.z,
a,
s,
_vx_line_zdominant_xd(xd, ax, az),
_vx_line_zdominant_yd(yd, ay, az)
_vx_line_zdominant_xd(xd, a.x, a.z),
_vx_line_zdominant_yd(yd, a.y, a.z)
)
];
function _vx_line_zdominant_sub(x, y, z, endz, a, s, xd, yd) =
let(
ax = a[0],
ay = a[1],
az = a[2],
sx = s[0],
sy = s[1],
sz = s[2]
)
z == endz ? [] : [
[x, y, z],
each _vx_line_zdominant_sub(
_vx_line_zdominant_x(x, xd, sx),
_vx_line_zdominant_y(y, yd, sy),
z + sz,
_vx_line_zdominant_x(x, xd, s.x),
_vx_line_zdominant_y(y, yd, s.y),
z + s.z,
endz,
a,
s,
_vx_line_zdominant_xd(xd, ax, az),
_vx_line_zdominant_yd(yd, ay, az)
_vx_line_zdominant_xd(xd, a.x, a.z),
_vx_line_zdominant_yd(yd, a.y, a.z)
)
];

View File

@@ -12,5 +12,4 @@ use <_impl/_vx_circle_impl.scad>;
use <../util/dedup.scad>;
function vx_circle(radius, filled = false) =
let(all = _vx_circle_impl(radius, filled))
dedup(all);
dedup(_vx_circle_impl(radius, filled));

View File

@@ -12,17 +12,14 @@ use <_impl/_vx_curve_impl.scad>;
use <../util/dedup.scad>;
function vx_curve(points, tightness = 0) =
let(
leng = len(points),
pts = [
each [
for(i = [0:leng - 4])
let(
pts = _vx_catmull_rom_spline_4pts([for(j = [i:i + 3]) points[j]], tightness)
)
for(i = [0:len(pts) - 2]) pts[i]
],
points[leng - 2]
]
)
dedup(pts);
let(leng = len(points))
dedup([
each [
for(i = [0:leng - 4])
let(
pts = _vx_catmull_rom_spline_4pts([for(j = [i:i + 3]) points[j]], tightness)
)
for(i = [0:len(pts) - 2]) pts[i]
],
points[leng - 2]
]);

View File

@@ -11,21 +11,17 @@
function vx_sphere(radius, filled = false, thickness = 1) =
let(range = [-radius: radius - 1])
filled ? [
for(z = range)
for(y = range)
for(x = range)
let(v = [x, y, z])
if(norm(v) < radius) v
for(z = range, y = range, x = range)
let(v = [x, y, z])
if(norm(v) < radius) v
] :
let(ishell = radius * radius - 2 * thickness * radius)
[
for(z = range)
for(y = range)
for(x = range)
let(
v = [x, y, z],
leng = norm(v)
)
if(leng < radius && (leng * leng) > ishell) v
for(z = range, y = range, x = range)
let(
v = [x, y, z],
leng = norm(v)
)
if(leng < radius && (leng * leng) > ishell) v
];