1
0
mirror of https://github.com/nophead/NopSCADlib.git synced 2025-08-10 17:33:57 +02:00

poly_cylinder() now has a twist parameter.

This commit is contained in:
Chris Palmer
2020-12-18 09:22:39 +00:00
parent fa658d9eaa
commit 73d814d2fe
4 changed files with 96 additions and 17 deletions

View File

@@ -22,6 +22,16 @@
//! it gets the linear dimensions right. See <https://hydraraptor.blogspot.com/2011/02/polyholes.html>
//!
//! The module provides `poly_circle()`, `poly_cylinder()` and `poly_ring()` that is useful for making printed washers and pillars.
//!
//! `poly_cylinder()` has a `twist` parameter which can be set to make the polygon rotate each layer.
//! This can be used to mitigate the number of sides being small and make small holes stronger and more round, but is quite slow due to the
//! large increase in the number of facets.
//! When set to 1 the polygons alternate each layer, when set higher the rotation takes `twist + 1` layers to repeat.
//! A small additional rotation is added to make the polygon rotate one more side over the length of the hole to make it appear round when
//! veiwed end on.
//!
//! When `twist` is set the resulting cylinder is extended by `eps` at each end so that the exact length of the hole can be used without
//! leaving a scar on either surface.
//
function sides(r) = max(round(4 * r), 3); //! Optimium number of sides for specified radius
function corrected_radius(r, n = 0) = r / cos(180 / (n ? n : sides(r))); //! Adjusted radius to make flats lie on the circle
@@ -32,9 +42,26 @@ module poly_circle(r, sides = 0) { //! Make a circle adjusted to print the corre
circle(r = corrected_radius(r,n), $fn = n);
}
module poly_cylinder(r, h, center = false, sides = 0, chamfer = false) {//! Make a cylinder adjusted to print the correct size
extrude_if(h, center)
poly_circle(r, sides);
module poly_cylinder(r, h, center = false, sides = 0, chamfer = false, twist = 0) {//! Make a cylinder adjusted to print the correct size
if(twist) {
slices = ceil(h / layer_height);
twist = min(twist, slices - 1);
sides = sides ? sides : sides(r);
rot = 360 / sides / (twist + 1) * (1 + 1 / slices);
if(center)
for(side = [0, 1])
mirror([0, 0, side])
poly_cylinder(r = r, h = h / 2, sides = sides, twist = twist);
else
render(convexity = 5)
for(i = [0 : slices - 1])
translate_z(i * layer_height - eps)
rotate(rot * i)
poly_cylinder(r = r, h = layer_height + 2 * eps, sides = sides);
}
else
extrude_if(h, center)
poly_circle(r, sides);
if(h && chamfer)
poly_cylinder(r + layer_height, center ? layer_height * 2 : layer_height, center, sides = sides ? sides : sides(r));