mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-11 09:14:29 +02:00
dot notation indexing
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
function angle_between_ccw_2d(v1, v2) =
|
function angle_between_ccw_2d(v1, v2) =
|
||||||
let(a = atan2(v1[0] * v2[1] - v1[1] * v2[0], v1 * v2))
|
let(a = atan2(v1.x * v2.y - v1.y * v2.x, v1 * v2))
|
||||||
a >= 0 ? a : a + 360;
|
a >= 0 ? a : a + 360;
|
||||||
|
|
||||||
function angle_between_ccw_3d(v1, v2) =
|
function angle_between_ccw_3d(v1, v2) =
|
||||||
let(
|
let(
|
||||||
dot = v1 * v2,
|
dot = v1 * v2,
|
||||||
lenSq1 = v1[0] ^ 2 + v1[1] ^ 2 + v1[2] ^ 2,
|
lenSq1 = v1.x ^ 2 + v1.y ^ 2 + v1.z ^ 2,
|
||||||
lenSq2 = v2[0] ^ 2 + v2[1] ^ 2 + v2[2] ^ 2,
|
lenSq2 = v2.x ^ 2 + v2.y ^ 2 + v2.z ^ 2,
|
||||||
a = acos(dot / sqrt(lenSq1 * lenSq2))
|
a = acos(dot / sqrt(lenSq1 * lenSq2))
|
||||||
)
|
)
|
||||||
a >= 0 ? a : a + 360;
|
a >= 0 ? a : a + 360;
|
@@ -5,8 +5,8 @@ function _bijection_inward_edge_normal(edge) =
|
|||||||
let(
|
let(
|
||||||
pt1 = edge[0],
|
pt1 = edge[0],
|
||||||
pt2 = edge[1],
|
pt2 = edge[1],
|
||||||
dx = pt2[0] - pt1[0],
|
dx = pt2.x - pt1.x,
|
||||||
dy = pt2[1] - pt1[1],
|
dy = pt2.y - pt1.y,
|
||||||
edge_leng = norm([dx, dy])
|
edge_leng = norm([dx, dy])
|
||||||
)
|
)
|
||||||
[-dy / edge_leng, dx / edge_leng];
|
[-dy / edge_leng, dx / edge_leng];
|
||||||
@@ -26,8 +26,8 @@ function _bijection__bijection_offset_edges(edges, d) =
|
|||||||
for(edge = edges)
|
for(edge = edges)
|
||||||
let(
|
let(
|
||||||
ow_normal = _bijection_outward_edge_normal(edge),
|
ow_normal = _bijection_outward_edge_normal(edge),
|
||||||
dx = ow_normal[0] * d,
|
dx = ow_normal.x * d,
|
||||||
dy = ow_normal[1] * d
|
dy = ow_normal.y * d
|
||||||
)
|
)
|
||||||
_bijection_offset_edge(edge, dx, dy)
|
_bijection_offset_edge(edge, dx, dy)
|
||||||
];
|
];
|
||||||
|
@@ -2,9 +2,9 @@ use <../util/lerp.scad>;
|
|||||||
|
|
||||||
function interpolated_pt(p0, p1, threshold) =
|
function interpolated_pt(p0, p1, threshold) =
|
||||||
lerp(
|
lerp(
|
||||||
[p0[0], p0[1], p0[2]],
|
[p0.x, p0.y, p0.z],
|
||||||
[p1[0], p1[1], p1[2]],
|
[p1.x, p1.y, p1.z],
|
||||||
(threshold - p0[2]) / (p1[2] - p0[2])
|
(threshold - p0.z) / (p1.z - p0.z)
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -21,7 +21,7 @@ function interpolated_pt(p0, p1, threshold) =
|
|||||||
function _isolines_pn_label(pts, threshold) =
|
function _isolines_pn_label(pts, threshold) =
|
||||||
[
|
[
|
||||||
for(row = pts)
|
for(row = pts)
|
||||||
[for(p = row) [p[0], p[1], p[2], p[2] >= threshold]]
|
[for(p = row) [p.x, p.y, p.z, p.z >= threshold]]
|
||||||
];
|
];
|
||||||
|
|
||||||
function _isolines_corner_value(cell_pts) =
|
function _isolines_corner_value(cell_pts) =
|
||||||
|
@@ -2,14 +2,14 @@ use <__comm__/__in_line.scad>;
|
|||||||
|
|
||||||
function _in_shape_in_line_equation(edge, pt) =
|
function _in_shape_in_line_equation(edge, pt) =
|
||||||
let(
|
let(
|
||||||
x1 = edge[0][0],
|
x1 = edge[0].x,
|
||||||
y1 = edge[0][1],
|
y1 = edge[0].y,
|
||||||
x2 = edge[1][0],
|
x2 = edge[1].x,
|
||||||
y2 = edge[1][1],
|
y2 = edge[1].y,
|
||||||
a = (y2 - y1) / (x2 - x1),
|
a = (y2 - y1) / (x2 - x1),
|
||||||
b = y1 - a * x1
|
b = y1 - a * x1
|
||||||
)
|
)
|
||||||
(pt[1] == a * pt[0] + b);
|
(pt.y == a * pt.x + b);
|
||||||
|
|
||||||
function _in_shape_in_any_edges(edges, pt, epsilon) =
|
function _in_shape_in_any_edges(edges, pt, epsilon) =
|
||||||
let(
|
let(
|
||||||
@@ -19,13 +19,13 @@ function _in_shape_in_any_edges(edges, pt, epsilon) =
|
|||||||
is_undef(maybe_last);
|
is_undef(maybe_last);
|
||||||
|
|
||||||
function _in_shape_interpolate_x(y, p1, p2) =
|
function _in_shape_interpolate_x(y, p1, p2) =
|
||||||
p1[1] == p2[1] ? p1[0] : (
|
p1.y == p2.y ? p1.x : (
|
||||||
p1[0] + (p2[0] - p1[0]) * (y - p1[1]) / (p2[1] - p1[1])
|
p1.x + (p2.x - p1.x) * (y - p1.y) / (p2.y - p1.y)
|
||||||
);
|
);
|
||||||
|
|
||||||
function _in_shape_does_pt_cross(pts, i, j, pt) =
|
function _in_shape_does_pt_cross(pts, i, j, pt) =
|
||||||
((pts[i][1] > pt[1]) != (pts[j][1] > pt[1])) &&
|
((pts[i].y > pt.y) != (pts[j].y > pt.y)) &&
|
||||||
(pt[0] < _in_shape_interpolate_x(pt[1], pts[i], pts[j]));
|
(pt.x < _in_shape_interpolate_x(pt.y, pts[i], pts[j]));
|
||||||
|
|
||||||
|
|
||||||
function _in_shape_sub(shapt_pts, leng, pt, cond, i, j) =
|
function _in_shape_sub(shapt_pts, leng, pt, cond, i, j) =
|
||||||
|
@@ -16,9 +16,9 @@ function _liquid_splitting_pie_curve(radius, centre_dist, tangent_angle) =
|
|||||||
function _liquid_splitting_bezier(radius, centre_dist, tangent_angle, t_step, ctrl_p1) =
|
function _liquid_splitting_bezier(radius, centre_dist, tangent_angle, t_step, ctrl_p1) =
|
||||||
let(
|
let(
|
||||||
ctrl_p = ptf_rotate([radius * tan(tangent_angle), -radius], tangent_angle),
|
ctrl_p = ptf_rotate([radius * tan(tangent_angle), -radius], tangent_angle),
|
||||||
ctrl_p2 = [-ctrl_p[0], ctrl_p[1]] + [centre_dist / 2, 0],
|
ctrl_p2 = [-ctrl_p.x, ctrl_p.y] + [centre_dist / 2, 0],
|
||||||
ctrl_p3 = [-ctrl_p2[0], ctrl_p2[1]],
|
ctrl_p3 = [-ctrl_p2.x, ctrl_p2.y],
|
||||||
ctrl_p4 = [-ctrl_p1[0], ctrl_p1[1]]
|
ctrl_p4 = [-ctrl_p1.x, ctrl_p1.y]
|
||||||
)
|
)
|
||||||
bezier_curve(
|
bezier_curve(
|
||||||
t_step,
|
t_step,
|
||||||
@@ -34,7 +34,7 @@ function _liquid_splitting_lower_half_curve(curve_pts, leng) =
|
|||||||
[
|
[
|
||||||
for(i = 0; i < leng; i = i + 1)
|
for(i = 0; i < leng; i = i + 1)
|
||||||
let(p = curve_pts[leng - 1 - i])
|
let(p = curve_pts[leng - 1 - i])
|
||||||
if(p[0] >= 0) p
|
if(p.x >= 0) p
|
||||||
];
|
];
|
||||||
|
|
||||||
function _liquid_splitting_half_liquid_splitting(radius, centre_dist, tangent_angle, t_step) =
|
function _liquid_splitting_half_liquid_splitting(radius, centre_dist, tangent_angle, t_step) =
|
||||||
@@ -46,7 +46,7 @@ function _liquid_splitting_half_liquid_splitting(radius, centre_dist, tangent_an
|
|||||||
upper_curve_pts = [
|
upper_curve_pts = [
|
||||||
for(i = 0; i < leng_half_curve_pts; i = i + 1)
|
for(i = 0; i < leng_half_curve_pts; i = i + 1)
|
||||||
let(pt = lower_curve_pts[leng_half_curve_pts - 1 - i])
|
let(pt = lower_curve_pts[leng_half_curve_pts - 1 - i])
|
||||||
[pt[0], -pt[1]]
|
[pt.x, -pt.y]
|
||||||
]
|
]
|
||||||
) concat(
|
) concat(
|
||||||
lower_curve_pts,
|
lower_curve_pts,
|
||||||
@@ -61,6 +61,6 @@ function _shape_liquid_splitting_impl(radius, centre_dist, tangent_angle, t_step
|
|||||||
left_half_liquid_splittings = [
|
left_half_liquid_splittings = [
|
||||||
for(i = 0; i < leng_half_liquid_splittings; i = i + 1)
|
for(i = 0; i < leng_half_liquid_splittings; i = i + 1)
|
||||||
let(pt = half_liquid_splittings[leng_half_liquid_splittings - 1 - i])
|
let(pt = half_liquid_splittings[leng_half_liquid_splittings - 1 - i])
|
||||||
[-pt[0], pt[1]]
|
[-pt.x, pt.y]
|
||||||
]
|
]
|
||||||
) concat(half_liquid_splittings, left_half_liquid_splittings);
|
) concat(half_liquid_splittings, left_half_liquid_splittings);
|
@@ -25,10 +25,10 @@ function _trim_sub(lines, leng, epsilon) =
|
|||||||
// no intersecting pt, collect current_p and trim remain lines
|
// no intersecting pt, collect current_p and trim remain lines
|
||||||
inter_p == [] ? (concat([current_p], _trim_shape_trim_lines(lines_from_next, epsilon))) : (
|
inter_p == [] ? (concat([current_p], _trim_shape_trim_lines(lines_from_next, epsilon))) : (
|
||||||
// collect current_p, intersecting pt and the last pt
|
// collect current_p, intersecting pt and the last pt
|
||||||
(leng == 3 || (inter_p[0] == (leng_lines_from_next2 - 1))) ? [current_p, inter_p[1], lines[leng - 1]] : (
|
(leng == 3 || (inter_p.x == (leng_lines_from_next2 - 1))) ? [current_p, inter_p.y, lines[leng - 1]] : (
|
||||||
// collect current_p, intersecting pt and trim remain lines
|
// collect current_p, intersecting pt and trim remain lines
|
||||||
concat([current_p, inter_p[1]],
|
concat([current_p, inter_p.x],
|
||||||
_trim_shape_trim_lines([for(i = inter_p[0] + 1; i < leng_lines_from_next2; i = i + 1) lines_from_next2[i]], epsilon)
|
_trim_shape_trim_lines([for(i = inter_p.x + 1; i < leng_lines_from_next2; i = i + 1) lines_from_next2[i]], epsilon)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user