Added center option to spring and documented the origin of rods, etc.

This commit is contained in:
Chris Palmer 2020-02-27 09:39:05 +00:00
parent ad719dad5a
commit c09a74b4c9
3 changed files with 21 additions and 10 deletions

View File

@ -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)

View File

@ -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>

View File

@ -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();
}
}