mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-19 13:01:37 +02:00
support 2d/3d
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
function _vx_bezier_pt(p1, p2, p3, p4, pts) =
|
||||
function _vx_bezier_pt3(p1, p2, p3, p4, pts) =
|
||||
let(
|
||||
a1 = (p1 + p2) * 0.5,
|
||||
a2 = (p2 + p3) * 0.5,
|
||||
@@ -8,9 +8,26 @@ function _vx_bezier_pt(p1, p2, p3, p4, pts) =
|
||||
c = (b1 + b2) * 0.5,
|
||||
p = [round(c[0]), round(c[1]), round(c[2])]
|
||||
)
|
||||
_vx_bezier(c, b2, a3, p4, _vx_bezier(p1, a1, b1, c, concat(pts, [p])));
|
||||
_vx_bezier3(c, b2, a3, p4, _vx_bezier3(p1, a1, b1, c, concat(pts, [p])));
|
||||
|
||||
function _vx_bezier(p1, p2, p3, p4, pts) =
|
||||
function _vx_bezier3(p1, p2, p3, p4, pts) =
|
||||
(abs(p1[0] - p4[0]) < 1 && abs(p1[1] - p4[1]) < 1 && abs(p1[2] - p4[2]) < 1) ?
|
||||
pts :
|
||||
_vx_bezier_pt(p1, p2, p3, p4, pts);
|
||||
_vx_bezier_pt3(p1, p2, p3, p4, pts);
|
||||
|
||||
function _vx_bezier_pt2(p1, p2, p3, p4, pts) =
|
||||
let(
|
||||
a1 = (p1 + p2) * 0.5,
|
||||
a2 = (p2 + p3) * 0.5,
|
||||
a3 = (p3 + p4) * 0.5,
|
||||
b1 = (a1 + a2) * 0.5,
|
||||
b2 = (a2 + a3) * 0.5,
|
||||
c = (b1 + b2) * 0.5,
|
||||
p = [round(c[0]), round(c[1])]
|
||||
)
|
||||
_vx_bezier2(c, b2, a3, p4, _vx_bezier2(p1, a1, b1, c, concat(pts, [p])));
|
||||
|
||||
function _vx_bezier2(p1, p2, p3, p4, pts) =
|
||||
(abs(p1[0] - p4[0]) < 1 && abs(p1[1] - p4[1]) < 1) ?
|
||||
pts :
|
||||
_vx_bezier_pt2(p1, p2, p3, p4, pts);
|
@@ -5,7 +5,7 @@ use <_impl/_vx_bezier_impl.scad>;
|
||||
function vx_bezier(p1, p2, p3, p4) =
|
||||
let(
|
||||
is2d = len(p1) == 2,
|
||||
pts = is2d ? _vx_bezier(__to3d(p1), __to3d(p2), __to3d(p3), __to3d(p4), []) :
|
||||
_vx_bezier(p1, p2, p3, p4, [])
|
||||
pts = is2d ? _vx_bezier2(__to3d(p1), __to3d(p2), __to3d(p3), __to3d(p4), []) :
|
||||
_vx_bezier3(p1, p2, p3, p4, [])
|
||||
)
|
||||
is2d ? [for(p = pts) __to2d(p)] : pts;
|
Reference in New Issue
Block a user