mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-03-14 02:59:42 +01:00
add shape_liquid_splitting
This commit is contained in:
parent
872ad92bff
commit
b0cbe24fa8
66
src/_impl/_shape_liquid_splitting_impl.scad
Normal file
66
src/_impl/_shape_liquid_splitting_impl.scad
Normal file
@ -0,0 +1,66 @@
|
||||
use <../ptf/ptf_rotate.scad>;
|
||||
use <../shape_pie.scad>;
|
||||
use <../bezier_curve.scad>;
|
||||
|
||||
function _liquid_splitting_pie_curve(radius, centre_dist, tangent_angle) =
|
||||
let(
|
||||
begin_ang = 90 + tangent_angle,
|
||||
shape_pts = shape_pie(radius, [-begin_ang, begin_ang]),
|
||||
leng = len(shape_pts)
|
||||
)
|
||||
[
|
||||
for(i = 1; i < leng; i = i + 1)
|
||||
shape_pts[i] + [centre_dist / 2, 0]
|
||||
];
|
||||
|
||||
function _liquid_splitting_bezier(radius, centre_dist, tangent_angle, t_step, ctrl_p1) =
|
||||
let(
|
||||
ctrl_p = ptf_rotate([radius * tan(tangent_angle), -radius], tangent_angle),
|
||||
ctrl_p2 = [-ctrl_p[0], ctrl_p[1]] + [centre_dist / 2, 0],
|
||||
ctrl_p3 = [-ctrl_p2[0], ctrl_p2[1]],
|
||||
ctrl_p4 = [-ctrl_p1[0], ctrl_p1[1]]
|
||||
)
|
||||
bezier_curve(
|
||||
t_step,
|
||||
[
|
||||
ctrl_p1,
|
||||
ctrl_p2,
|
||||
ctrl_p3,
|
||||
ctrl_p4
|
||||
]
|
||||
);
|
||||
|
||||
function _liquid_splitting_lower_half_curve(curve_pts, leng) =
|
||||
[
|
||||
for(i = 0; i < leng; i = i + 1)
|
||||
let(p = curve_pts[leng - 1 - i])
|
||||
if(p[0] >= 0) p
|
||||
];
|
||||
|
||||
function _liquid_splitting_half_liquid_splitting(radius, centre_dist, tangent_angle, t_step) =
|
||||
let(
|
||||
pie_curve_pts = _liquid_splitting_pie_curve(radius, centre_dist, tangent_angle),
|
||||
curve_pts = _liquid_splitting_bezier(radius, centre_dist, tangent_angle, t_step, pie_curve_pts[0]),
|
||||
lower_curve_pts = _liquid_splitting_lower_half_curve(curve_pts, len(curve_pts)),
|
||||
leng_half_curve_pts = len(lower_curve_pts),
|
||||
upper_curve_pts = [
|
||||
for(i = 0; i < leng_half_curve_pts; i = i + 1)
|
||||
let(pt = lower_curve_pts[leng_half_curve_pts - 1 - i])
|
||||
[pt[0], -pt[1]]
|
||||
]
|
||||
) concat(
|
||||
lower_curve_pts,
|
||||
pie_curve_pts,
|
||||
upper_curve_pts
|
||||
);
|
||||
|
||||
function _shape_liquid_splitting_impl(radius, centre_dist, tangent_angle, t_step) =
|
||||
let(
|
||||
half_liquid_splittings = _liquid_splitting_half_liquid_splitting(radius, centre_dist, tangent_angle, t_step),
|
||||
leng_half_liquid_splittings = len(half_liquid_splittings),
|
||||
left_half_liquid_splittings = [
|
||||
for(i = 0; i < leng_half_liquid_splittings; i = i + 1)
|
||||
let(pt = half_liquid_splittings[leng_half_liquid_splittings - 1 - i])
|
||||
[-pt[0], pt[1]]
|
||||
]
|
||||
) concat(half_liquid_splittings, left_half_liquid_splittings);
|
15
src/shape_liquid_splitting.scad
Normal file
15
src/shape_liquid_splitting.scad
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
/**
|
||||
* shape_liquid_splitting.scad
|
||||
*
|
||||
* @copyright Justin Lin, 2020
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
* @see https://openhome.cc/eGossip/OpenSCAD/lib2x-shape_liquid_splitting.html
|
||||
*
|
||||
**/
|
||||
|
||||
use <_impl/_shape_liquid_splitting_impl.scad>;
|
||||
|
||||
function shape_liquid_splitting(radius, centre_dist, tangent_angle = 30, t_step = 0.1) =
|
||||
_shape_liquid_splitting_impl(radius, centre_dist, tangent_angle, t_step);
|
Loading…
x
Reference in New Issue
Block a user