From c09a74b4c979f772b93e13919c32d21aee0c5da8 Mon Sep 17 00:00:00 2001 From: Chris Palmer Date: Thu, 27 Feb 2020 09:39:05 +0000 Subject: [PATCH] Added center option to spring and documented the origin of rods, etc. --- readme.md | 6 +++++- vitamins/rod.scad | 2 ++ vitamins/spring.scad | 23 ++++++++++++++--------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/readme.md b/readme.md index 125f86e..bdb3469 100644 --- a/readme.md +++ b/readme.md @@ -2474,6 +2474,8 @@ Rocker switch. Also used for neon indicator in the same form factor. ## Rod Steel rods and studding with chamfered ends. +These items are sysmtrical, so by default the origin is in the centre but it can be changed to the bottom. + [vitamins/rod.scad](vitamins/rod.scad) Implementation. @@ -2885,6 +2887,8 @@ Filament spool models ## Springs Compression springs. Can be tapered, have open, closed or ground ends. Ground ends will render a lot slower. +By default springs have their origin at the bottom but can be centered. + [vitamins/springs.scad](vitamins/springs.scad) Object definitions. @@ -2913,7 +2917,7 @@ Compression springs. Can be tapered, have open, closed or ground ends. Ground en ### Modules | Module | Description | |:--- |:--- | -| ```comp_spring(type, l = 0)``` | Draw specified spring, l can be set to specify the compressed length. | +| ```comp_spring(type, l = 0, center = false)``` | Draw specified spring, l can be set to specify the compressed length. | ![springs](tests/png/springs.png) diff --git a/vitamins/rod.scad b/vitamins/rod.scad index fbcee60..c195b12 100644 --- a/vitamins/rod.scad +++ b/vitamins/rod.scad @@ -19,6 +19,8 @@ // //! Steel rods and studding with chamfered ends. +//! +//! These items are sysmtrical, so by default the origin is in the centre but it can be changed to the bottom. // include <../core.scad> use <../utils/thread.scad> diff --git a/vitamins/spring.scad b/vitamins/spring.scad index a3a99b4..ee30ece 100644 --- a/vitamins/spring.scad +++ b/vitamins/spring.scad @@ -19,6 +19,8 @@ // //! Compression springs. Can be tapered, have open, closed or ground ends. Ground ends will render a lot slower. +//! +//! By default springs have their origin at the bottom but can be centered. // include <../core.scad> @@ -64,7 +66,7 @@ function comp_spring(type, l = 0) = //! Calculate the mesh for spring profile = circle_points(wire_d / 2 - eps, $fn = 16) ) concat(type, [concat(sweep(path, profile), [l])]); -module comp_spring(type, l = 0) { //! Draw specified spring, l can be set to specify the compressed length. +module comp_spring(type, l = 0, center = false) { //! Draw specified spring, l can be set to specify the compressed length. length = spring_length(type); closed = spring_closed(type); od = spring_od(type); @@ -79,14 +81,17 @@ module comp_spring(type, l = 0) { //! Draw specified spring, l can be set to spe mesh = len(type) > 9 ? spring_mesh(type) : spring_mesh(comp_spring(type, l)); assert(l == mesh[2], "can't change the length of a pre-generated spring"); - color(spring_colour(type)) - if(ground) - clip(zmin = 0, zmax = h) + len = l ? l : length; + translate_z(center ? - len / 2 : 0) { + color(spring_colour(type)) + if(ground) + clip(zmin = 0, zmax = h) + polyhedron(mesh[0], mesh[1]); + else polyhedron(mesh[0], mesh[1]); - else - polyhedron(mesh[0], mesh[1]); - if($children) - translate_z(l) - children(); + if($children) + translate_z(len) + children(); + } }