1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-11 17:24:20 +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) ? scale_step_vt = is_num(scale) ?
let(s = (scale - 1) / leng_points_minus_one) [s, s, s] : let(s = (scale - 1) / leng_points_minus_one) [s, s, s] :
[ [
(scale[0] - 1) / leng_points_minus_one, (scale.x - 1) / leng_points_minus_one,
(scale[1] - 1) / leng_points_minus_one, (scale.y - 1) / leng_points_minus_one,
is_undef(scale[2]) ? 0 : (scale[2] - 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) { module bend(size, angle, frags = 24) {
x = size[0]; x = size.x;
y = size[1]; y = size.y;
z = size[2]; z = size.z;
frag_width = x / frags; frag_width = x / frags;
frag_angle = angle / frags; frag_angle = angle / frags;
half_frag_width = 0.5 * frag_width; half_frag_width = 0.5 * frag_width;

View File

@@ -9,8 +9,8 @@
**/ **/
module bend_extrude(size, thickness, angle, frags = 24) { module bend_extrude(size, thickness, angle, frags = 24) {
x = size[0]; x = size.x;
y = size[1]; y = size.y;
frag_width = x / frags ; frag_width = x / frags ;
frag_angle = angle / frags; frag_angle = angle / frags;
half_frag_width = 0.5 * frag_width; 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)], pth_pts = len(path_pts[0]) == 3 ? path_pts : [for(p = path_pts) __to3d(p)],
scale_step_vt = is_num(scale) ? scale_step_vt = is_num(scale) ?
[(scale - 1) / len_path_pts_minus_one, (scale - 1) / len_path_pts_minus_one] : [(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[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],
twist_step = twist / 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(i = 0; i <= len_path_pts_minus_one; i = i + 1)
[ [
for(p = sh_pts) 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) ptf_rotate(scaled_p, twist_step * i)
, angles[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) translate(center_offset)
extrude() extrude()
children(); 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") { module line2d(p1, p2, width = 1, p1Style = "CAP_SQUARE", p2Style = "CAP_SQUARE") {
half_width = 0.5 * width; half_width = 0.5 * width;
atan_angle = atan2(p2[1] - p1[1], p2[0] - p1[0]); atan_angle = atan2(p2.y - p1.y, p2.x - p1.x);
leng = sqrt(pow(p2[0] - p1[0], 2) + pow(p2[1] - p1[1], 2)); leng = sqrt(pow(p2.x - p1.x, 2) + pow(p2.y - p1.y, 2));
frags = __nearest_multiple_of_4(__frags(half_width)); 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)); frags = __nearest_multiple_of_4(__frags(r));
half_fa = 180 / frags; half_fa = 180 / frags;
dx = p2[0] - p1[0]; dx = p2.x - p1.x;
dy = p2[1] - p1[1]; dy = p2.y - p1.y;
dz = p2[2] - p1[2]; dz = p2.z - p1.z;
length = sqrt(pow(dx, 2) + pow(dy, 2) + pow(dz, 2)); length = sqrt(pow(dx, 2) + pow(dy, 2) + pow(dz, 2));
ay = 90 - atan2(dz, sqrt(pow(dx, 2) + pow(dy, 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) = function nz_perlin2s(points, seed) =
let(sd = is_undef(seed) ? floor(rand(0, 256)) : seed % 256) 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) = function nz_perlin3s(points, seed) =
let(sd = is_undef(seed) ? floor(rand(0, 256)) : seed % 256) 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() { module axis_angle_path_extrude() {
twist_step_a = twist / len_path_pts; twist_step_a = twist / len_path_pts;
function scale_pts(pts, s) = [ function scale_pts(pts, s) =
for(p = pts) [p[0] * s[0], p[1] * s[1], p[2] * s[2]] [
for(p = pts) [p.x * s.x, p.y * s.y, p.z * s.z]
]; ];
function translate_pts(pts, t) = [ function translate_pts(pts, t) = [for(p = pts) p + t];
for(p = pts) [p[0] + t[0], p[1] + t[1], p[2] + t[2]]
];
function rotate_pts(pts, a, v) = [for(p = pts) ptf_rotate(p, a, v)]; function rotate_pts(pts, a, v) = [for(p = pts) ptf_rotate(p, a, v)];
scale_step_vt = is_num(scale) ? scale_step_vt = is_num(scale) ?
let(s = (scale - 1) / len_path_pts_minus_one) [s, s, s] : let(s = (scale - 1) / len_path_pts_minus_one) [s, s, s] :
[ [
(scale[0] - 1) / len_path_pts_minus_one, (scale.x - 1) / len_path_pts_minus_one,
(scale[1] - 1) / len_path_pts_minus_one, (scale.y - 1) / len_path_pts_minus_one,
is_undef(scale[2]) ? 0 : (scale[2] - 1) / len_path_pts_minus_one is_undef(scale[2]) ? 0 : (scale.z - 1) / len_path_pts_minus_one
]; ];
// get rotation matrice for sections // 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() { module euler_angle_path_extrude() {
scale_step_vt = is_num(scale) ? scale_step_vt = is_num(scale) ?
[(scale - 1) / len_path_pts_minus_one, (scale - 1) / len_path_pts_minus_one] : [(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; twist_step = twist / len_path_pts_minus_one;
function section(p1, p2, i) = 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) 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( ptf_rotate(
ptf_rotate(scaled_p, twist_step * i), [90, 0, -90] 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), base_leng = norm(start_point),
scaling_matrice = [ scaling_matrice = [
for(p = edge_path) 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]) m_scaling([s, s, 1])
], ],
leng_edge_path = len(edge_path) 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(i = 0; i < leng_edge_path; i = i + 1)
[ [
for(p = shape_pts) for(p = shape_pts)
let(scaled_p = scaling_matrice[i] * [p[0], p[1], edge_path[i][2], 1]) let(scaled_p = scaling_matrice[i] * [p.x, p.y, edge_path[i].z, 1])
[scaled_p[0], scaled_p[1], scaled_p[2]] [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 c = cross(v1, v2); // c > 0: ct_clk
a = angle(p1, p2, p3); 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); ra = c > 0 ? (-90 + v1a) : (90 + v1a - a);
if(joinStyle == "JOIN_ROUND") { if(joinStyle == "JOIN_ROUND") {

View File

@@ -11,11 +11,9 @@
function ptf_bend(size, point, radius, angle) = function ptf_bend(size, point, radius, angle) =
let( let(
// ignored: size.y, // ignored: size.y,
y = point[0], x = is_undef(point.z) ? 0 : point.z,
z = point[1],
x = is_undef(point[2]) ? 0 : point[2],
a_step = angle / size.x, a_step = angle / size.x,
a = a_step * y, a = a_step * point.x,
r = radius + 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, a_step = angle / size.y,
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.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) = function ptf_torus(size, point, radius, angle = [360, 360], twist = 0) =
let( let(
xlen = size[0],
ylen = size[1],
x = point[0],
y = point[1],
R = radius[0], 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[0],
a = angle[1], a = angle[1],
ya_step = a / xlen, ya_step = a / size.x,
za_step = A / ylen, za_step = A / size.y,
twa_step = twist / ylen, twa_step = twist / size.y,
ya = 180 - x * ya_step + twa_step * y, ya = 180 - point.x * ya_step + twa_step * point.y,
za = za_step * y za = za_step * point.y
) )
ptf_rotate([r * cos(ya) + R + r, 0, r * sin(ya)], za); 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) = function ptf_x_twist(size, point, angle) =
let( let(
xlen = size[0], y_offset = size.y / 2,
ylen = size[1], a_step = angle / size.x,
y_offset = ylen / 2, y_centered = [point.x, point.y, is_undef(point.z) ? 0 : point.z] + [0, -y_offset, 0]
a_step = angle / xlen,
y_centered = [point[0], point[1], is_undef(point[2]) ? 0 : point[2]] + [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) = function ptf_y_twist(size, point, angle) =
let( let(
xlen = size[0], x_offset = size.x / 2,
ylen = size[1], a_step = angle / size.y,
x_offset = xlen / 2, x_centered = [point.x, point.y, is_undef(point.z) ? 0 : point.z] + [-x_offset, 0, 0]
a_step = angle / ylen,
x_centered = [point[0], point[1], is_undef(point[2]) ? 0 : point[2]] + [-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) { module rounded_cube(size, corner_r, center = false) {
is_flt = is_num(size); is_flt = is_num(size);
x = is_flt ? size : size[0]; x = is_flt ? size : size.x;
y = is_flt ? size : size[1]; y = is_flt ? size : size.y;
z = is_flt ? size : size[2]; z = is_flt ? size : size.z;
corner_frags = __nearest_multiple_of_4(__frags(corner_r)); corner_frags = __nearest_multiple_of_4(__frags(corner_r));
edge_d = corner_r * cos(180 / corner_frags); 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) { module rounded_extrude(size, round_r, angle = 90, twist = 0, convexity = 10) {
is_flt = is_num(size); is_flt = is_num(size);
x = is_flt ? size : size[0]; x = is_flt ? size : size.x;
y = is_flt ? size : size[1]; y = is_flt ? size : size.y;
q_corner_frags = __frags(round_r) / 4; 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) { module rounded_square(size, corner_r, center = false) {
is_flt = is_num(size); is_flt = is_num(size);
x = is_flt ? size : size[0]; x = is_flt ? size : size.x;
y = is_flt ? size : size[1]; y = is_flt ? size : size.y;
position = center ? [0, 0] : [x / 2, y / 2]; position = center ? [0, 0] : [x / 2, y / 2];
points = __trapezium( points = __trapezium(

View File

@@ -27,7 +27,7 @@ function shape_cyclicpolygon(sides, circle_r, corner_r) =
__frags(corner_r) * corner_circle_a / 360 __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) for(pt = first_corner)
let( let(
a = frag_a * side, a = frag_a * side,
x = pt[0],
y = pt[1],
sina = sin(a), sina = sin(a),
cosa = cos(a) cosa = cos(a)
) )
[ [
x * cosa - y * sina, pt.x * cosa - pt.y * sina,
x * sina + y * cosa pt.x * sina + pt.y * cosa
] ]
] ]
); );

View File

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