mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-13 02:04:16 +02:00
refactor
This commit is contained in:
@@ -61,16 +61,14 @@ module along_with(points, angles, twist = 0, scale = 1.0, method = "AXIS_ANGLE")
|
|||||||
leng_rot_matrice_minus_one = leng_rot_matrice - 1,
|
leng_rot_matrice_minus_one = leng_rot_matrice - 1,
|
||||||
leng_rot_matrice_minus_two = leng_rot_matrice - 2
|
leng_rot_matrice_minus_two = leng_rot_matrice - 2
|
||||||
)
|
)
|
||||||
leng_rot_matrice == 0 ? [identity_matrix] : (
|
leng_rot_matrice == 0 ? [identity_matrix] :
|
||||||
leng_rot_matrice == 1 ? [rot_matrice[0], identity_matrix] : (
|
leng_rot_matrice == 1 ? [rot_matrice[0], identity_matrix] :
|
||||||
i == leng_rot_matrice_minus_two ?
|
i == leng_rot_matrice_minus_two ?
|
||||||
[
|
[
|
||||||
rot_matrice[leng_rot_matrice_minus_one],
|
rot_matrice[leng_rot_matrice_minus_one],
|
||||||
rot_matrice[leng_rot_matrice_minus_two] * rot_matrice[leng_rot_matrice_minus_one]
|
rot_matrice[leng_rot_matrice_minus_two] * rot_matrice[leng_rot_matrice_minus_one]
|
||||||
]
|
]
|
||||||
: axis_angle_cumulated_rot_matrice_sub(i, rot_matrice)
|
: axis_angle_cumulated_rot_matrice_sub(i, rot_matrice);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
function axis_angle_cumulated_rot_matrice_sub(i, rot_matrice) =
|
function axis_angle_cumulated_rot_matrice_sub(i, rot_matrice) =
|
||||||
let(
|
let(
|
||||||
|
@@ -10,8 +10,9 @@
|
|||||||
|
|
||||||
use <__comm__/__to3d.scad>;
|
use <__comm__/__to3d.scad>;
|
||||||
use <__comm__/__angy_angz.scad>;
|
use <__comm__/__angy_angz.scad>;
|
||||||
use <ptf/ptf_rotate.scad>;
|
|
||||||
use <sweep.scad>;
|
use <sweep.scad>;
|
||||||
|
use <matrix/m_scaling.scad>;
|
||||||
|
use <matrix/m_translation.scad>;
|
||||||
use <matrix/m_rotation.scad>;
|
use <matrix/m_rotation.scad>;
|
||||||
|
|
||||||
module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale = 1.0, closed = false, method = "AXIS_ANGLE") {
|
module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale = 1.0, closed = false, method = "AXIS_ANGLE") {
|
||||||
@@ -20,18 +21,13 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
|
|||||||
|
|
||||||
len_path_pts = len(pth_pts);
|
len_path_pts = len(pth_pts);
|
||||||
len_path_pts_minus_one = len_path_pts - 1;
|
len_path_pts_minus_one = len_path_pts - 1;
|
||||||
|
|
||||||
|
m_rot_90_0_n90 = m_rotation([90, 0, -90]);
|
||||||
|
|
||||||
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) =
|
|
||||||
[
|
|
||||||
for(p = pts) [p.x * s.x, p.y * s.y, p.z * s.z]
|
|
||||||
];
|
|
||||||
|
|
||||||
function translate_pts(pts, t) = [for(p = pts) p + t];
|
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) ?
|
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] :
|
||||||
@@ -72,16 +68,15 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
|
|||||||
];
|
];
|
||||||
|
|
||||||
function cumulated_rot_matrice(i) =
|
function cumulated_rot_matrice(i) =
|
||||||
leng_rot_matrice == 0 ? [identity_matrix] : (
|
leng_rot_matrice == 0 ? [identity_matrix] :
|
||||||
leng_rot_matrice == 1 ? [rot_matrice[0], identity_matrix] :
|
leng_rot_matrice == 1 ? [rot_matrice[0], identity_matrix] :
|
||||||
(
|
i == leng_rot_matrice_minus_two ?
|
||||||
i == leng_rot_matrice_minus_two ?
|
[
|
||||||
[
|
rot_matrice[leng_rot_matrice_minus_one],
|
||||||
rot_matrice[leng_rot_matrice_minus_one],
|
rot_matrice[leng_rot_matrice_minus_two] * rot_matrice[leng_rot_matrice_minus_one]
|
||||||
rot_matrice[leng_rot_matrice_minus_two] * rot_matrice[leng_rot_matrice_minus_one]
|
]
|
||||||
]
|
:
|
||||||
: cumulated_rot_matrice_sub(i))
|
cumulated_rot_matrice_sub(i);
|
||||||
);
|
|
||||||
|
|
||||||
function cumulated_rot_matrice_sub(i) =
|
function cumulated_rot_matrice_sub(i) =
|
||||||
let(
|
let(
|
||||||
@@ -93,17 +88,19 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
|
|||||||
|
|
||||||
cumu_rot_matrice = cumulated_rot_matrice(0);
|
cumu_rot_matrice = cumulated_rot_matrice(0);
|
||||||
|
|
||||||
|
|
||||||
// get all sections
|
// get all sections
|
||||||
|
|
||||||
function init_section(a, s) =
|
function init_section(a, s) =
|
||||||
let(angleyz = __angy_angz(pth_pts[0], pth_pts[1]))
|
let(
|
||||||
rotate_pts(
|
angleyz = __angy_angz(pth_pts[0], pth_pts[1]),
|
||||||
rotate_pts(
|
transform_m = m_rotation([0, -angleyz[0], angleyz[1]]) * m_rot_90_0_n90 * m_rotation(a) * m_scaling(s)
|
||||||
rotate_pts(
|
)
|
||||||
scale_pts(sh_pts, s), a
|
[
|
||||||
), [90, 0, -90]
|
for(p = sh_pts)
|
||||||
), [0, -angleyz[0], angleyz[1]]
|
let(transformed = transform_m * [each p, 1])
|
||||||
);
|
[transformed.x, transformed.y, transformed.z]
|
||||||
|
];
|
||||||
|
|
||||||
function local_rotate_section(j, init_a, init_s) =
|
function local_rotate_section(j, init_a, init_s) =
|
||||||
j == 0 ?
|
j == 0 ?
|
||||||
@@ -112,8 +109,6 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
|
|||||||
|
|
||||||
function local_rotate_section_sub(j, init_a, init_s) =
|
function local_rotate_section_sub(j, init_a, init_s) =
|
||||||
let(
|
let(
|
||||||
vt0 = pth_pts[j] - pth_pts[j - 1],
|
|
||||||
vt1 = pth_pts[j + 1] - pth_pts[j],
|
|
||||||
ms = cumu_rot_matrice[j - 1],
|
ms = cumu_rot_matrice[j - 1],
|
||||||
ms0 = ms[0],
|
ms0 = ms[0],
|
||||||
ms1 = ms[1],
|
ms1 = ms[1],
|
||||||
@@ -164,20 +159,20 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
|
|||||||
|
|
||||||
function section(p1, p2, i) =
|
function section(p1, p2, i) =
|
||||||
let(
|
let(
|
||||||
length = norm(p1 - p2),
|
|
||||||
angy_angz = __angy_angz(p1, p2),
|
angy_angz = __angy_angz(p1, p2),
|
||||||
ay = -angy_angz[0],
|
ay = -angy_angz[0],
|
||||||
az = angy_angz[1]
|
az = angy_angz[1],
|
||||||
|
transform_m = m_translation(p1) *
|
||||||
|
m_rotation([0, ay, az]) *
|
||||||
|
m_translation([i == 0 ? 0 : norm(p1 - p2), 0, 0]) *
|
||||||
|
m_rot_90_0_n90 *
|
||||||
|
m_rotation(twist_step * i) *
|
||||||
|
m_scaling([1 + scale_step_vt.x * i, 1 + scale_step_vt.y * i, 1])
|
||||||
)
|
)
|
||||||
[
|
[
|
||||||
for(p = sh_pts)
|
for(p = sh_pts)
|
||||||
let(scaled_p = [p.x * (1 + scale_step_vt.x * i), p.y * (1 + scale_step_vt.y * i), p.z])
|
let(transformed = transform_m * [each p, 1])
|
||||||
ptf_rotate(
|
[transformed.x, transformed.y, transformed.z]
|
||||||
ptf_rotate(
|
|
||||||
ptf_rotate(scaled_p, twist_step * i), [90, 0, -90]
|
|
||||||
) + [i == 0 ? 0 : length, 0, 0],
|
|
||||||
[0, ay, az]
|
|
||||||
) + p1
|
|
||||||
];
|
];
|
||||||
|
|
||||||
path_extrude_inner =
|
path_extrude_inner =
|
||||||
|
@@ -26,10 +26,10 @@ function _q_rotate_p_3d(p, a, v) =
|
|||||||
wy = w * y2,
|
wy = w * y2,
|
||||||
wz = w * z2
|
wz = w * z2
|
||||||
)
|
)
|
||||||
[
|
p * [
|
||||||
[1 - yy - zz, yx - wz, zx + wy] * p,
|
[1 - yy - zz, yx + wz, zx - wy],
|
||||||
[yx + wz, 1 - xx - zz, zy - wx] * p,
|
[yx - wz, 1 - xx - zz, zy + wx],
|
||||||
[zx - wy, zy + wx, 1 - xx - yy] * p
|
[zx + wy, zy - wx, 1 - xx - yy]
|
||||||
];
|
];
|
||||||
|
|
||||||
function _rotx(pt, a) =
|
function _rotx(pt, a) =
|
||||||
|
@@ -16,8 +16,4 @@ function shape_circle(radius, n) =
|
|||||||
step_a = 360 / _frags,
|
step_a = 360 / _frags,
|
||||||
end = (is_undef(n) || n > _frags) ? _frags - 1: n - 1
|
end = (is_undef(n) || n > _frags) ? _frags - 1: n - 1
|
||||||
)
|
)
|
||||||
[
|
[for(a = [0:step_a:end * step_a]) [radius * cos(a), radius * sin(a)]];
|
||||||
for(i = [0:end])
|
|
||||||
let(a = i * step_a)
|
|
||||||
[radius * cos(a), radius * sin(a)]
|
|
||||||
];
|
|
||||||
|
@@ -20,14 +20,14 @@ function shape_cyclicpolygon(sides, circle_r, corner_r) =
|
|||||||
corner_circle_center = circle_r - corner_r / sin(corner_a / 2),
|
corner_circle_center = circle_r - corner_r / sin(corner_a / 2),
|
||||||
first_corner = [
|
first_corner = [
|
||||||
for(
|
for(
|
||||||
pt = __pie_for_rounding(
|
pt = __pie_for_rounding(
|
||||||
corner_r,
|
corner_r,
|
||||||
-half_corner_circle_a,
|
-half_corner_circle_a,
|
||||||
half_corner_circle_a,
|
half_corner_circle_a,
|
||||||
__frags(corner_r) * corner_circle_a / 360
|
__frags(corner_r) * corner_circle_a / 360
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
[pt.x + corner_circle_center, pt.y]
|
[pt.x + corner_circle_center, pt.y]
|
||||||
]
|
]
|
||||||
|
|
||||||
)
|
)
|
||||||
@@ -35,15 +35,12 @@ function shape_cyclicpolygon(sides, circle_r, corner_r) =
|
|||||||
first_corner,
|
first_corner,
|
||||||
[
|
[
|
||||||
for(side = 1; side < sides; side = side + 1)
|
for(side = 1; side < sides; side = side + 1)
|
||||||
for(pt = first_corner)
|
let(
|
||||||
let(
|
a = frag_a * side,
|
||||||
a = frag_a * side,
|
sina = sin(a),
|
||||||
sina = sin(a),
|
cosa = cos(a)
|
||||||
cosa = cos(a)
|
)
|
||||||
)
|
// for(pt = first_corner) [pt.x * cosa - pt.y * sina, pt.x * sina + pt.y * cosa]
|
||||||
[
|
each first_corner * [[cosa, sina], [-sina, cosa]]
|
||||||
pt.x * cosa - pt.y * sina,
|
|
||||||
pt.x * sina + pt.y * cosa
|
|
||||||
]
|
|
||||||
]
|
]
|
||||||
);
|
);
|
Reference in New Issue
Block a user