1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-29 17:30:11 +02:00
This commit is contained in:
Justin Lin
2019-06-08 08:10:04 +08:00
parent ff63835009
commit 6854c86f90
3 changed files with 11 additions and 13 deletions

View File

@@ -0,0 +1,8 @@
function __in_line(line_pts, pt, epsilon = 0.0001) =
let(
pts = len(line_pts[0]) == 2 ? [for(pt = line_pts) __to3d(pt)] : line_pts,
pt3d = len(pt) == 2 ? __to3d(pt) : pt,
v1 = pts[0] - pt3d,
v2 = pts[1] - pt3d
)
(norm(cross(v1, v2)) < epsilon) && ((v1 * v2) <= epsilon);

View File

@@ -1,6 +0,0 @@
function __in_line2d(line_pts, pt, epsilon = 0.0001) =
let(
v1 = line_pts[0] - pt,
v2 = line_pts[1] - pt
)
(norm(cross(v1, v2)) < epsilon) && ((v1 * v2) <= epsilon);

View File

@@ -1,16 +1,12 @@
include <__private__/__to3d.scad>; include <__private__/__to3d.scad>;
include <__private__/__in_line2d.scad>; include <__private__/__in_line.scad>;
function _in_polyline_sub(pts, pt, epsilon, iend, i = 0) = function _in_polyline_sub(pts, pt, epsilon, iend, i = 0) =
i == iend ? false : ( i == iend ? false : (
__in_line2d([pts[i], pts[i + 1]], pt, epsilon) ? true : __in_line([pts[i], pts[i + 1]], pt, epsilon) ? true :
_in_polyline_sub(pts, pt, epsilon, iend, i + 1) _in_polyline_sub(pts, pt, epsilon, iend, i + 1)
); );
function in_polyline(line_pts, pt, epsilon = 0.0001) = function in_polyline(line_pts, pt, epsilon = 0.0001) =
let( _in_polyline_sub(line_pts, pt, epsilon, len(pts) - 1);
pts = len(line_pts[0]) == 2 ? [for(pt = line_pts) __to3d(pt)] : line_pts,
pt3d = len(pt) == 2 ? __to3d(pt) : pt
)
_in_polyline_sub(pts, pt3d, epsilon, len(pts) - 1);