OpenSCAD Code for a Pyramidal Frustum
Here's the OpenSCAD code for my pyramidal frustum, along with a few notes. I realize the formatting here is pretty crappy; I'm going to have to figure out a way to copy code into one of these blocks while preserving decent formatting, ideally color coded as it is in the OpenSCAD dev environment.
I'm using an external file called PhiPlot.scad to build my Fibonacci spiral. I'll include that on another page sometime soon. The "random offset" variables were to allow centering of the spiral on the faces of the pyramid. Because it's a Fibonacci spiral rather than a symmetrical spiral, it's, well, not round. The origin of that object is not in the center of the object, so you can't just place the center of the spiral model over the center of the pyramid face.
I do everything in modules so that I can assemble bits and pieces in different configurations. In this case, the separation of the exports versus the object builders ("pyramid" and "etch") is important because my etched spiral isn't flush to the surface of the pyramid face. If you were to F5 pyramid() and etch() at the same time you'd see that the spiral actually sticks out of the pyramid face slightly. I can think of two ways to handle this:
- Calculate exactly the translation needed to position the spiral model flush to the pyramid faces despite said spiral and said face being sloped 58 degrees and the depth of the spiral being a bit uncertain since you're using scale() to fit it on the side correctly.
- Just let the models overlap and use those "export" modules with intersect() and difference() to force everything flush.
Incidentally, the argument for the makespiral() call controls the diameter of the points used to construct the spiral. I.e., the line of the spiral gets thicker when you increase that argument. There's a bit of a balancing act between that argument and the scale used for the spiral; when the spiral is too thick it starts to close up and looks like a skewed ampersand instead. You can also see in that module that I could have used a few more variables when I was dinking around with getting the scale just right.
/* ===== Some setup work ===== */
$fn = 50; // This makes the curves nice and curvy
use <PhiPlot.scad>; // Bring in the code that creates the Fibonacci Spiral
/* ===== Global variables ===== */
bs = 30; // Length of a side in the frustum base
ts = 10; // Length of a side in the frustum top
pr = 15; // 90 degree height of the frustum (not the length of a sloped side)
txts = 8; // Text size if etching text
fname = "Ariel:style=bold"; // Text font if etching text
rhoff = 3; // Random horizontal offset for centering the etching
rvoff = 2; // Random vertical offset for centering the etching
txt1 = "A"; // Some text to etch.
/* ===== Runtime ===== */
//baseexport(); // Export this one to print the base model
etchexport(); // Export this one to print the etching
//pyramid(); // Build the main pyramid (for quick test rendering)
//etch(); // Build the etching (for quick test rendering)
/* ===== Modules for exporting the STLs ===== */
module baseexport() {
difference() {
pyramid();
etch();
}
}
module etchexport() {
intersection() {
pyramid();
etch();
}
}
/* ===== Modules for building stuff ===== */
module pyramid() {
hull() {
cube([bs, bs, .1]);
translate([(bs-ts)/2, (bs-ts)/2, pr]) cube([ts, ts, 1]);
}
}
module etch() {
ssize = 40; // controls the general size of the spiral
translate([bs/2+rhoff, 5, pr/2-rvoff]) rotate([58, 0, 0]) scale([.05, .05, .2]) makespiral(ssize);
translate([bs-5, bs/2+rhoff, pr/2-rvoff]) rotate([58, 0, 90]) scale([.05, .05, .2]) makespiral(ssize);
translate([bs/2-rhoff, bs-5, pr/2-rvoff]) rotate([58, 0, 180]) scale([.05, .05, .2]) makespiral(ssize);
translate([5, bs/2-rhoff, pr/2-rvoff]) rotate([58, 0, -90]) scale([.05, .05, .2]) makespiral(ssize);
//translate([bs/2, 8, pr/2]) rotate([58, 0, 0]) linear_extrude(height=3)
// text(size=txts, font=fname, halign="center", valign="center", txt1);
}