mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-01-17 14:18:13 +01:00
refactored
This commit is contained in:
parent
5d30d8f688
commit
dcc05778e2
1
src/__private__/__to2d.scad
Normal file
1
src/__private__/__to2d.scad
Normal file
@ -0,0 +1 @@
|
||||
function __to2d(p) = [p[0], p[1]];
|
1
src/__private__/__to3d.scad
Normal file
1
src/__private__/__to3d.scad
Normal file
@ -0,0 +1 @@
|
||||
function __to3d(p) = [p[0], p[1], 0];
|
@ -11,13 +11,14 @@
|
||||
*
|
||||
**/
|
||||
|
||||
include <__private__/__to3d.scad>;
|
||||
include <__private__/__is_vector.scad>;
|
||||
|
||||
function cross_sections(shape_pts, path_pts, angles, twist = 0, scale = 1.0) =
|
||||
let(
|
||||
len_path_pts_minus_one = len(path_pts) - 1,
|
||||
sh_pts = len(shape_pts[0]) == 3 ? shape_pts : [for(p = shape_pts) [p[0], p[1], 0]],
|
||||
pth_pts = len(path_pts[0]) == 3 ? path_pts : [for(p = path_pts) [p[0], p[1], 0]],
|
||||
sh_pts = len(shape_pts[0]) == 3 ? shape_pts : [for(p = shape_pts) __to3d(p)],
|
||||
pth_pts = len(path_pts[0]) == 3 ? path_pts : [for(p = path_pts) __to3d(p)],
|
||||
scale_step_vt = __is_vector(scale) ?
|
||||
[(scale[0] - 1) / len_path_pts_minus_one, (scale[1] - 1) / len_path_pts_minus_one] :
|
||||
[(scale - 1) / len_path_pts_minus_one, (scale - 1) / len_path_pts_minus_one],
|
||||
|
@ -44,12 +44,10 @@ function _golden_spiral_from_ls_or_eql_to(from, to, point_distance, rt_dir) =
|
||||
a_step = 360 / $fn * rt_dir,
|
||||
arc_points_angles = (rt_dir == 1 ? [
|
||||
for(i = [0:len_pts - 1])
|
||||
// to 3D points because of rotate_p
|
||||
[[circle_pts[i][0], circle_pts[i][1], 0], a_step * i]
|
||||
[circle_pts[i], a_step * i]
|
||||
] : [
|
||||
for(i = [0:len_pts - 1]) let(idx = len_pts - i - 1)
|
||||
// to 3D points because of rotate_p
|
||||
[[circle_pts[idx][0], circle_pts[idx][1], 0], a_step * i]
|
||||
[circle_pts[idx], a_step * i]
|
||||
]),
|
||||
offset = f2 - f1
|
||||
) _remove_same_pts(
|
||||
@ -69,7 +67,4 @@ function _golden_spiral(from, to, point_distance, rt_dir) =
|
||||
_golden_spiral_from_ls_or_eql_to(from, to, point_distance, rt_dir) : [];
|
||||
|
||||
function golden_spiral(from, to, point_distance, rt_dir = "CT_CLK") =
|
||||
[
|
||||
for(pt_a = _golden_spiral(from, to, point_distance, (rt_dir == "CT_CLK" ? 1 : -1)))
|
||||
[[pt_a[0][0], pt_a[0][1]], pt_a[1]] // to 2D points
|
||||
];
|
||||
_golden_spiral(from, to, point_distance, (rt_dir == "CT_CLK" ? 1 : -1));
|
@ -17,10 +17,7 @@ include <__private__/__is_vector.scad>;
|
||||
|
||||
module path_extrude(shape_pts, path_pts, triangles = "RADIAL", twist = 0, scale = 1.0, closed = false) {
|
||||
|
||||
s_pts = to3d(shape_pts);
|
||||
pth_pts = to3d(path_pts);
|
||||
|
||||
len_path_pts = len(pth_pts);
|
||||
len_path_pts = len(path_pts);
|
||||
len_path_pts_minus_one = len_path_pts - 1;
|
||||
|
||||
scale_step_vt = __is_vector(scale) ?
|
||||
@ -31,13 +28,10 @@ module path_extrude(shape_pts, path_pts, triangles = "RADIAL", twist = 0, scale
|
||||
scale_step_y = scale_step_vt[1];
|
||||
twist_step = twist / len_path_pts_minus_one;
|
||||
|
||||
function to3d(pts) =
|
||||
len(pts[0]) == 3 ? pts : [for(p = pts) [p[0], p[1], 0]];
|
||||
|
||||
function first_section() =
|
||||
let(
|
||||
p1 = pth_pts[0],
|
||||
p2 = pth_pts[1],
|
||||
p1 = path_pts[0],
|
||||
p2 = path_pts[1],
|
||||
dx = p2[0] - p1[0],
|
||||
dy = p2[1] - p1[1],
|
||||
dz = p2[2] - p1[2],
|
||||
@ -45,7 +39,7 @@ module path_extrude(shape_pts, path_pts, triangles = "RADIAL", twist = 0, scale
|
||||
az = atan2(dy, dx)
|
||||
)
|
||||
[
|
||||
for(p = s_pts)
|
||||
for(p = shape_pts)
|
||||
rotate_p(p, [0, ay, az]) + p1
|
||||
];
|
||||
|
||||
@ -59,7 +53,7 @@ module path_extrude(shape_pts, path_pts, triangles = "RADIAL", twist = 0, scale
|
||||
az = atan2(dy, dx)
|
||||
)
|
||||
[
|
||||
for(p = s_pts)
|
||||
for(p = shape_pts)
|
||||
let(scaled_p = [p[0] * (1 + scale_step_x * i), p[1] * (1 + scale_step_y * i), p[2]])
|
||||
rotate_p(
|
||||
rotate_p(scaled_p, twist_step * i) + [0, 0, length],
|
||||
@ -70,11 +64,11 @@ module path_extrude(shape_pts, path_pts, triangles = "RADIAL", twist = 0, scale
|
||||
function path_extrude_inner(index) =
|
||||
index == len_path_pts ? [] :
|
||||
concat(
|
||||
[section(pth_pts[index - 1], pth_pts[index], index)],
|
||||
[section(path_pts[index - 1], path_pts[index], index)],
|
||||
path_extrude_inner(index + 1)
|
||||
);
|
||||
|
||||
if(closed && pth_pts[0] == pth_pts[len_path_pts_minus_one]) {
|
||||
if(closed && path_pts[0] == path_pts[len_path_pts_minus_one]) {
|
||||
// round-robin
|
||||
sections = path_extrude_inner(1);
|
||||
polysections(
|
||||
|
@ -11,6 +11,9 @@
|
||||
*
|
||||
**/
|
||||
|
||||
include <__private__/__to2d.scad>;
|
||||
include <__private__/__to3d.scad>;
|
||||
|
||||
function _rotx(pt, a) =
|
||||
let(cosa = cos(a), sina = sin(a))
|
||||
[
|
||||
@ -38,8 +41,6 @@ function _rotz(pt, a) =
|
||||
function _rotate_p_3d(point, a) =
|
||||
_rotz(_roty(_rotx(point, a[0]), a[1]), a[2]);
|
||||
|
||||
function _to2d(p) = [p[0], p[1]];
|
||||
|
||||
function to_avect(a) =
|
||||
len(a) == 3 ? a : (
|
||||
len(a) == 2 ? [a[0], a[1], 0] : (
|
||||
@ -51,6 +52,6 @@ function rotate_p(point, a) =
|
||||
let(angle = to_avect(a))
|
||||
len(point) == 3 ?
|
||||
_rotate_p_3d(point, angle) :
|
||||
_to2d(
|
||||
_rotate_p_3d([point[0], point[1], 0], angle)
|
||||
__to2d(
|
||||
_rotate_p_3d(__to3d(point), angle)
|
||||
);
|
||||
|
@ -12,6 +12,7 @@
|
||||
*
|
||||
**/
|
||||
|
||||
include <__private__/__is_vector.scad>;
|
||||
include <__private__/__frags.scad>;
|
||||
|
||||
function shape_square(size, corner_r = 0) =
|
||||
@ -20,8 +21,8 @@ function shape_square(size, corner_r = 0) =
|
||||
remain = frags % 4,
|
||||
corner_frags = (remain / 4) > 0.5 ? frags - remain + 4 : frags - remain,
|
||||
step_a = 360 / corner_frags,
|
||||
x = len(size) == undef ? size : size[0],
|
||||
y = len(size) == undef ? size : size[1],
|
||||
x = __is_vector(size) ? size[0] : size,
|
||||
y = __is_vector(size) ? size[1] : size,
|
||||
half_x = x / 2,
|
||||
half_y = y / 2,
|
||||
half_w = half_x - corner_r,
|
||||
|
@ -11,8 +11,6 @@
|
||||
*
|
||||
**/
|
||||
|
||||
include <line2d.scad>;
|
||||
|
||||
function _turtle2d_turtle(x, y, angle) = [[x, y], angle];
|
||||
|
||||
function _turtle2d_set_point(turtle, point) = [point, _turtle2d_get_angle(turtle)];
|
||||
|
Loading…
x
Reference in New Issue
Block a user