1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-17 14:18:13 +01:00

refactored

This commit is contained in:
Justin Lin 2017-05-14 10:53:36 +08:00
parent f5233faf0e
commit 2a504293d7
2 changed files with 31 additions and 24 deletions

View File

@ -0,0 +1,18 @@
function __pie_for_rounding(r, begin_a, end_a, frags) =
let(
sector_angle = end_a - begin_a,
step_a = sector_angle / frags,
is_integer = frags % 1 == 0
)
concat([
for(ang = [begin_a:step_a:end_a])
[
r * cos(ang),
r * sin(ang)
]
],
is_integer ? [] : [[
r * cos(end_a),
r * sin(end_a)
]]
);

View File

@ -12,13 +12,12 @@
include <__private__/__is_vector.scad>;
include <__private__/__frags.scad>;
include <__private__/__pie_for_rounding.scad>;
module rounded_cylinder(radius, h, round_r, convexity = 2, center = false) {
is_vt = __is_vector(radius);
r1 = is_vt ? radius[0] : radius;
r2 = is_vt ? radius[1] : radius;
function is_integer(n) = n % 1 == 0;
function round_frags(sector_angle) = __frags(round_r) * sector_angle / 360;
@ -35,32 +34,22 @@ module rounded_cylinder(radius, h, round_r, convexity = 2, center = false) {
t_leng = r2 - round_r * tan(t_sector_angle / 2);
t_round_frags = round_frags(t_sector_angle);
b_corner = [
for(pt = __pie_for_rounding(round_r, -90, b_end_angle, b_round_frags))
[pt[0] + b_leng, pt[1] + round_r]
];
t_corner = [
for(pt = __pie_for_rounding(round_r, 90 - t_sector_angle, 90, t_round_frags))
[pt[0] + t_leng, pt[1] + h - round_r]
];
translate(center ? [0, 0, -h/2] : [0, 0, 0]) rotate(180) rotate_extrude(convexity = convexity)
polygon(
concat(
[[0, 0], [b_leng, 0]],
[
for(ang = [-90:step_a(b_sector_angle, b_round_frags):b_end_angle])
[
round_r * cos(ang) + b_leng,
round_r * sin(ang) + round_r
]
],
is_integer(b_round_frags) ? [] : [[
round_r * cos(b_end_angle) + b_leng,
round_r * sin(b_end_angle) + round_r
]],
[
for(ang = [90 - t_sector_angle:step_a(t_sector_angle, t_round_frags):90])
[
round_r * cos(ang) + t_leng,
round_r * sin(ang) + h - round_r
]
],
is_integer(t_round_frags) ? [] : [[
t_leng,
round_r + h - round_r
]],
b_corner,
t_corner,
[[t_leng, h], [0, h]]
)
);