1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-13 18:24:28 +02:00
This commit is contained in:
Justin Lin
2022-04-16 12:59:58 +08:00
parent 6c78b0e090
commit 07343e9e37
2 changed files with 11 additions and 11 deletions

View File

@@ -5,4 +5,7 @@ function __in_line(line_pts, pt, epsilon = 0.0001) =
v1 = pts[0] - pt3d,
v2 = pts[1] - pt3d
)
(norm(cross(v1, v2)) < epsilon) && ((v1 * v2) <= epsilon);
v1 * v2 <= epsilon && (
let(v = cross(v1, v2))
v * v < (epsilon ^ 2)
);

View File

@@ -2,11 +2,10 @@ use <__comm__/__in_line.scad>;
function _in_shape_in_line_equation(edge, pt) =
let(
v = edge[1] - edge[0],
a = v.y / v.x,
b = edge[0].y - a * edge[0].x
p0 = edge[0],
v = edge[1] - p0
)
(pt.y == a * pt.x + b);
pt.y == (v.y / v.x) * (pt.x - p0.x) + p0.y;
function _in_shape_in_any_edges(edges, pt, epsilon) =
let(
@@ -16,15 +15,13 @@ function _in_shape_in_any_edges(edges, pt, epsilon) =
is_undef(maybe_last);
function _in_shape_interpolate_x(y, p1, p2) =
p1.y == p2.y ? p1.x : (
p1.x + (p2.x - p1.x) * (y - p1.y) / (p2.y - p1.y)
);
p1.y == p2.y ? p1.x :
let(v = p2 - p1) p1.x + v.x * (y - p1.y) / v.y;
function _in_shape_does_pt_cross(pts, i, j, pt) =
((pts[i].y > pt.y) != (pts[j].y > pt.y)) &&
(pt.x < _in_shape_interpolate_x(pt.y, pts[i], pts[j]));
let(pi = pts[i], pj = pts[j])
((pi.y - pt.y) * (pj.y - pt.y) < 0) && (pt.x < _in_shape_interpolate_x(pt.y, pi, pj));
function _in_shape_sub(shapt_pts, leng, pt, cond, i, j) =
j == leng ? cond : _in_shape_sub(shapt_pts, leng, pt, _in_shape_does_pt_cross(shapt_pts, i, j, pt) ? !cond : cond, j, j + 1);