1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-10 00:36:40 +02:00
This commit is contained in:
Justin Lin
2021-12-04 11:52:25 +08:00
parent e7c38fa876
commit 134ca1b364
22 changed files with 61 additions and 79 deletions

View File

@@ -23,9 +23,9 @@ module along_with(points, angles, twist = 0, scale = 1.0, method = "AXIS_ANGLE")
scale_step_vt = is_num(scale) ?
let(s = (scale - 1) / leng_points_minus_one) [s, s, s] :
[
(scale[0] - 1) / leng_points_minus_one,
(scale[1] - 1) / leng_points_minus_one,
is_undef(scale[2]) ? 0 : (scale[2] - 1) / leng_points_minus_one
(scale.x - 1) / leng_points_minus_one,
(scale.y - 1) / leng_points_minus_one,
is_undef(scale.z) ? 0 : (scale.z - 1) / leng_points_minus_one
];
/*

View File

@@ -10,9 +10,9 @@
module bend(size, angle, frags = 24) {
x = size[0];
y = size[1];
z = size[2];
x = size.x;
y = size.y;
z = size.z;
frag_width = x / frags;
frag_angle = angle / frags;
half_frag_width = 0.5 * frag_width;

View File

@@ -9,8 +9,8 @@
**/
module bend_extrude(size, thickness, angle, frags = 24) {
x = size[0];
y = size[1];
x = size.x;
y = size.y;
frag_width = x / frags ;
frag_angle = angle / frags;
half_frag_width = 0.5 * frag_width;

View File

@@ -18,17 +18,14 @@ function cross_sections(shape_pts, path_pts, angles, twist = 0, scale = 1.0) =
pth_pts = len(path_pts[0]) == 3 ? path_pts : [for(p = path_pts) __to3d(p)],
scale_step_vt = is_num(scale) ?
[(scale - 1) / len_path_pts_minus_one, (scale - 1) / len_path_pts_minus_one] :
[(scale[0] - 1) / len_path_pts_minus_one, (scale[1] - 1) / len_path_pts_minus_one]
,
scale_step_x = scale_step_vt[0],
scale_step_y = scale_step_vt[1],
[(scale[0] - 1) / len_path_pts_minus_one, (scale[1] - 1) / len_path_pts_minus_one],
twist_step = twist / len_path_pts_minus_one
)
[
for(i = 0; i <= len_path_pts_minus_one; i = i + 1)
[
for(p = sh_pts)
let(scaled_p = [p[0] * (1 + scale_step_x * i), p[1] * (1 + scale_step_y * i), p[2]])
let(scaled_p = [p.x * (1 + scale_step_vt.x * i), p.y * (1 + scale_step_vt.y * i), p.z])
ptf_rotate(
ptf_rotate(scaled_p, twist_step * i)
, angles[i]

View File

@@ -58,7 +58,7 @@ module ellipse_extrude(semi_minor_axis, height, center = false, convexity = 10,
}
}
center_offset = [0, 0, center == true ? -h / 2 : 0];
center_offset = [0, 0, center ? -h / 2 : 0];
translate(center_offset)
extrude()
children();

View File

@@ -14,8 +14,8 @@ use <__comm__/__nearest_multiple_of_4.scad>;
module line2d(p1, p2, width = 1, p1Style = "CAP_SQUARE", p2Style = "CAP_SQUARE") {
half_width = 0.5 * width;
atan_angle = atan2(p2[1] - p1[1], p2[0] - p1[0]);
leng = sqrt(pow(p2[0] - p1[0], 2) + pow(p2[1] - p1[1], 2));
atan_angle = atan2(p2.y - p1.y, p2.x - p1.x);
leng = sqrt(pow(p2.x - p1.x, 2) + pow(p2.y - p1.y, 2));
frags = __nearest_multiple_of_4(__frags(half_width));

View File

@@ -17,9 +17,9 @@ module line3d(p1, p2, diameter = 1, p1Style = "CAP_CIRCLE", p2Style = "CAP_CIRCL
frags = __nearest_multiple_of_4(__frags(r));
half_fa = 180 / frags;
dx = p2[0] - p1[0];
dy = p2[1] - p1[1];
dz = p2[2] - p1[2];
dx = p2.x - p1.x;
dy = p2.y - p1.y;
dz = p2.z - p1.z;
length = sqrt(pow(dx, 2) + pow(dy, 2) + pow(dz, 2));
ay = 90 - atan2(dz, sqrt(pow(dx, 2) + pow(dy, 2)));

View File

@@ -13,4 +13,4 @@ use <_impl/_pnoise2_impl.scad>;
function nz_perlin2s(points, seed) =
let(sd = is_undef(seed) ? floor(rand(0, 256)) : seed % 256)
[for(p = points) _pnoise2(p[0], p[1], sd)];
[for(p = points) _pnoise2(p.x, p.y, sd)];

View File

@@ -13,4 +13,4 @@ use <_impl/_pnoise3_impl.scad>;
function nz_perlin3s(points, seed) =
let(sd = is_undef(seed) ? floor(rand(0, 256)) : seed % 256)
[for(p = points) _pnoise3(p[0], p[1], p[2], sd)];
[for(p = points) _pnoise3(p.x, p.y, p.z, sd)];

View File

@@ -24,22 +24,21 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
module axis_angle_path_extrude() {
twist_step_a = twist / len_path_pts;
function scale_pts(pts, s) = [
for(p = pts) [p[0] * s[0], p[1] * s[1], p[2] * s[2]]
function scale_pts(pts, s) =
[
for(p = pts) [p.x * s.x, p.y * s.y, p.z * s.z]
];
function translate_pts(pts, t) = [
for(p = pts) [p[0] + t[0], p[1] + t[1], p[2] + t[2]]
];
function translate_pts(pts, t) = [for(p = pts) p + t];
function rotate_pts(pts, a, v) = [for(p = pts) ptf_rotate(p, a, v)];
scale_step_vt = is_num(scale) ?
let(s = (scale - 1) / len_path_pts_minus_one) [s, s, s] :
[
(scale[0] - 1) / len_path_pts_minus_one,
(scale[1] - 1) / len_path_pts_minus_one,
is_undef(scale[2]) ? 0 : (scale[2] - 1) / len_path_pts_minus_one
(scale.x - 1) / len_path_pts_minus_one,
(scale.y - 1) / len_path_pts_minus_one,
is_undef(scale[2]) ? 0 : (scale.z - 1) / len_path_pts_minus_one
];
// get rotation matrice for sections
@@ -157,10 +156,8 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
module euler_angle_path_extrude() {
scale_step_vt = is_num(scale) ?
[(scale - 1) / len_path_pts_minus_one, (scale - 1) / len_path_pts_minus_one] :
[(scale[0] - 1) / len_path_pts_minus_one, (scale[1] - 1) / len_path_pts_minus_one];
[(scale.x - 1) / len_path_pts_minus_one, (scale.y - 1) / len_path_pts_minus_one];
scale_step_x = scale_step_vt[0];
scale_step_y = scale_step_vt[1];
twist_step = twist / len_path_pts_minus_one;
function section(p1, p2, i) =
@@ -172,7 +169,7 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
)
[
for(p = sh_pts)
let(scaled_p = [p[0] * (1 + scale_step_x * i), p[1] * (1 + scale_step_y * i), p[2]])
let(scaled_p = [p.x * (1 + scale_step_vt.x * i), p.y * (1 + scale_step_vt.y * i), p.z])
ptf_rotate(
ptf_rotate(
ptf_rotate(scaled_p, twist_step * i), [90, 0, -90]

View File

@@ -17,7 +17,7 @@ function path_scaling_sections(shape_pts, edge_path) =
base_leng = norm(start_point),
scaling_matrice = [
for(p = edge_path)
let(s = norm([p[0], p[1], 0]) / base_leng)
let(s = norm([p.x, p.y, 0]) / base_leng)
m_scaling([s, s, 1])
],
leng_edge_path = len(edge_path)
@@ -26,7 +26,7 @@ function path_scaling_sections(shape_pts, edge_path) =
for(i = 0; i < leng_edge_path; i = i + 1)
[
for(p = shape_pts)
let(scaled_p = scaling_matrice[i] * [p[0], p[1], edge_path[i][2], 1])
[scaled_p[0], scaled_p[1], scaled_p[2]]
let(scaled_p = scaling_matrice[i] * [p.x, p.y, edge_path[i].z, 1])
[scaled_p.x, scaled_p.y, scaled_p.z]
]
]);

View File

@@ -51,7 +51,7 @@ module polyline2d(points, width = 1, startingStyle = "CAP_SQUARE", endingStyle =
c = cross(v1, v2); // c > 0: ct_clk
a = angle(p1, p2, p3);
v1a = atan2(v1[1], v1[0]);
v1a = atan2(v1.y, v1.x);
ra = c > 0 ? (-90 + v1a) : (90 + v1a - a);
if(joinStyle == "JOIN_ROUND") {

View File

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

View File

@@ -16,4 +16,4 @@ function ptf_ring(size, point, radius, angle = 360, twist = 0) =
a_step = angle / size.y,
twisted = ptf_y_twist(size, point, twist)
)
ptf_rotate([radius + twisted[0], 0, twisted[2]], a_step * twisted[1]);
ptf_rotate([radius + twisted.x, 0, twisted.z], a_step * twisted.y);

View File

@@ -12,18 +12,14 @@ use <ptf_rotate.scad>;
function ptf_torus(size, point, radius, angle = [360, 360], twist = 0) =
let(
xlen = size[0],
ylen = size[1],
x = point[0],
y = point[1],
R = radius[0],
r = radius[1] + (is_undef(point[2]) ? 0 : point[2]),
r = radius[1] + (is_undef(point.z) ? 0 : point.z),
A = angle[0],
a = angle[1],
ya_step = a / xlen,
za_step = A / ylen,
twa_step = twist / ylen,
ya = 180 - x * ya_step + twa_step * y,
za = za_step * y
ya_step = a / size.x,
za_step = A / size.y,
twa_step = twist / size.y,
ya = 180 - point.x * ya_step + twa_step * point.y,
za = za_step * point.y
)
ptf_rotate([r * cos(ya) + R + r, 0, r * sin(ya)], za);

View File

@@ -12,10 +12,8 @@ use <ptf_rotate.scad>;
function ptf_x_twist(size, point, angle) =
let(
xlen = size[0],
ylen = size[1],
y_offset = ylen / 2,
a_step = angle / xlen,
y_centered = [point[0], point[1], is_undef(point[2]) ? 0 : point[2]] + [0, -y_offset, 0]
y_offset = size.y / 2,
a_step = angle / size.x,
y_centered = [point.x, point.y, is_undef(point.z) ? 0 : point.z] + [0, -y_offset, 0]
)
ptf_rotate(y_centered, [point[0] * a_step, 0, 0]) + [0, y_offset, 0];
ptf_rotate(y_centered, [point.x * a_step, 0, 0]) + [0, y_offset, 0];

View File

@@ -12,10 +12,8 @@ use <ptf_rotate.scad>;
function ptf_y_twist(size, point, angle) =
let(
xlen = size[0],
ylen = size[1],
x_offset = xlen / 2,
a_step = angle / ylen,
x_centered = [point[0], point[1], is_undef(point[2]) ? 0 : point[2]] + [-x_offset, 0, 0]
x_offset = size.x / 2,
a_step = angle / size.y,
x_centered = [point.x, point.y, is_undef(point.z) ? 0 : point.z] + [-x_offset, 0, 0]
)
ptf_rotate(x_centered, [0, point[1] * a_step, 0]) + [x_offset, 0, 0];
ptf_rotate(x_centered, [0, point.y * a_step, 0]) + [x_offset, 0, 0];

View File

@@ -13,9 +13,9 @@ use <__comm__/__nearest_multiple_of_4.scad>;
module rounded_cube(size, corner_r, center = false) {
is_flt = is_num(size);
x = is_flt ? size : size[0];
y = is_flt ? size : size[1];
z = is_flt ? size : size[2];
x = is_flt ? size : size.x;
y = is_flt ? size : size.y;
z = is_flt ? size : size.z;
corner_frags = __nearest_multiple_of_4(__frags(corner_r));
edge_d = corner_r * cos(180 / corner_frags);

View File

@@ -12,8 +12,8 @@ use <__comm__/__frags.scad>;
module rounded_extrude(size, round_r, angle = 90, twist = 0, convexity = 10) {
is_flt = is_num(size);
x = is_flt ? size : size[0];
y = is_flt ? size : size[1];
x = is_flt ? size : size.x;
y = is_flt ? size : size.y;
q_corner_frags = __frags(round_r) / 4;

View File

@@ -12,8 +12,8 @@ use <__comm__/__trapezium.scad>;
module rounded_square(size, corner_r, center = false) {
is_flt = is_num(size);
x = is_flt ? size : size[0];
y = is_flt ? size : size[1];
x = is_flt ? size : size.x;
y = is_flt ? size : size.y;
position = center ? [0, 0] : [x / 2, y / 2];
points = __trapezium(

View File

@@ -27,7 +27,7 @@ function shape_cyclicpolygon(sides, circle_r, corner_r) =
__frags(corner_r) * corner_circle_a / 360
)
)
[pt[0] + corner_circle_center, pt[1]]
[pt.x + corner_circle_center, pt.y]
]
)
@@ -38,14 +38,12 @@ function shape_cyclicpolygon(sides, circle_r, corner_r) =
for(pt = first_corner)
let(
a = frag_a * side,
x = pt[0],
y = pt[1],
sina = sin(a),
cosa = cos(a)
)
[
x * cosa - y * sina,
x * sina + y * cosa
pt.x * cosa - pt.y * sina,
pt.x * sina + pt.y * cosa
]
]
);

View File

@@ -13,8 +13,8 @@ use <__comm__/__trapezium.scad>;
function shape_square(size, corner_r = 0) =
let(
is_flt = is_num(size),
x = is_flt ? size : size[0],
y = is_flt ? size : size[1]
x = is_flt ? size : size.x,
y = is_flt ? size : size.y
)
__trapezium(
length = x,