1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-07-31 20:10:36 +02:00

added rounded_cylinder

This commit is contained in:
Justin Lin
2017-05-11 15:24:02 +08:00
parent 5141099b96
commit be87196286
4 changed files with 81 additions and 0 deletions

View File

@@ -43,6 +43,7 @@ Too many dependencies? Because OpenSCAD doesn't provide namespace management, I
- 3D
- [rounded_cube](https://openhome.cc/eGossip/OpenSCAD/lib-rounded_cube.html)
- [rounded_cylinder](https://openhome.cc/eGossip/OpenSCAD/lib-rounded_cylinder.html)
- [line3d](https://openhome.cc/eGossip/OpenSCAD/lib-line3d.html)
- [polyline3d](https://openhome.cc/eGossip/OpenSCAD/lib-polyline3d.html)
- [hull_polyline3d](https://openhome.cc/eGossip/OpenSCAD/lib-hull_polyline3d.html)

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -0,0 +1,26 @@
# rounded_cylinder
Creates a rounded cylinder.
## Parameters
- `radius` : The radius of the cylinder. It also accepts a vector `[r1, r2]`. `r1` is the bottom radius and `r2` is the top radius of a cone.
- `h` : The height of the cylinder or cone.
- `round_r` : The sphere radius which fits the edges of the bottom and the top.
- `center` : `false` (default), z ranges from 0 to h. `true`, z ranges from -h/2 to +h/2
- `convexity` : See [Rotate Extrude](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_the_2D_Subsystem#Rotate_Extrude) for details.
- `slices` : The fragments of the rounded edge.
- `$fa`, `$fs`, `$fn` : Used to control the eight quadrants. Check [the circle module](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_the_2D_Subsystem#circle) for more details. The final fragments of a sphere will be a multiple of 4 to fit edges.
## Examples
include <rounded_cylinder.scad>;
rounded_cylinder(
radius = [20, 10],
h = 25,
round_r = 3
);
![rounded_cylinder](images/lib-rounded_cylinder-1.JPG)

54
src/rounded_cylinder.scad Normal file
View File

@@ -0,0 +1,54 @@
/**
* rounded_cylinder.scad
*
* Creates a rounded cylinder.
*
* @copyright Justin Lin, 2017
* @license https://opensource.org/licenses/lgpl-3.0.html
*
* @see https://openhome.cc/eGossip/OpenSCAD/lib-rounded_cylinder.html
*
**/
include <__private__/__is_vector.scad>;
include <__private__/__frags.scad>;
module rounded_cylinder(radius, h, round_r, convexity = 2, center = false, slices = undef) {
is_vt = __is_vector(radius);
r1 = is_vt ? radius[0] : radius;
r2 = is_vt ? radius[1] : radius;
frags = __frags(round_r);
function step_a(sector_angle) =
sector_angle / (slices == undef ? frags * sector_angle / 360 : slices);
b_ang = atan2(h, r1 - r2);
b_sector_angle = 180 - b_ang;
b_leng = r1 - round_r / tan(b_ang / 2);
t_sector_angle = b_ang;
t_leng = r2 - round_r * tan(t_sector_angle / 2);
translate(center ? [0, 0, -h/2] : [0, 0, 0]) rotate_extrude(convexity = convexity)
polygon(
concat(
[[0, 0], [b_leng, 0]],
[
for(ang = [-90:step_a(b_sector_angle):-90 + b_sector_angle])
[
round_r * cos(ang) + b_leng,
round_r * sin(ang) + round_r
]
],
[
for(ang = [90 - t_sector_angle:step_a(t_sector_angle):90])
[
round_r * cos(ang) + t_leng,
round_r * sin(ang) + h - round_r
]
],
[[t_leng, h], [0, h]]
)
);
}