mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-10 00:36:40 +02:00
refactored
This commit is contained in:
18
src/__private__/__pie_for_rounding.scad
Normal file
18
src/__private__/__pie_for_rounding.scad
Normal 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)
|
||||||
|
]]
|
||||||
|
);
|
@@ -12,14 +12,13 @@
|
|||||||
|
|
||||||
include <__private__/__is_vector.scad>;
|
include <__private__/__is_vector.scad>;
|
||||||
include <__private__/__frags.scad>;
|
include <__private__/__frags.scad>;
|
||||||
|
include <__private__/__pie_for_rounding.scad>;
|
||||||
|
|
||||||
module rounded_cylinder(radius, h, round_r, convexity = 2, center = false) {
|
module rounded_cylinder(radius, h, round_r, convexity = 2, center = false) {
|
||||||
is_vt = __is_vector(radius);
|
is_vt = __is_vector(radius);
|
||||||
r1 = is_vt ? radius[0] : radius;
|
r1 = is_vt ? radius[0] : radius;
|
||||||
r2 = is_vt ? radius[1] : 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;
|
function round_frags(sector_angle) = __frags(round_r) * sector_angle / 360;
|
||||||
|
|
||||||
function step_a(sector_angle, round_frags) =
|
function step_a(sector_angle, round_frags) =
|
||||||
@@ -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_leng = r2 - round_r * tan(t_sector_angle / 2);
|
||||||
t_round_frags = round_frags(t_sector_angle);
|
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)
|
translate(center ? [0, 0, -h/2] : [0, 0, 0]) rotate(180) rotate_extrude(convexity = convexity)
|
||||||
polygon(
|
polygon(
|
||||||
concat(
|
concat(
|
||||||
[[0, 0], [b_leng, 0]],
|
[[0, 0], [b_leng, 0]],
|
||||||
[
|
b_corner,
|
||||||
for(ang = [-90:step_a(b_sector_angle, b_round_frags):b_end_angle])
|
t_corner,
|
||||||
[
|
|
||||||
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
|
|
||||||
]],
|
|
||||||
[[t_leng, h], [0, h]]
|
[[t_leng, h], [0, h]]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user