-
-
Save scruss/09600e55e140e0d394cf815d028b752d to your computer and use it in GitHub Desktop.
module chamfer_extrude(height = 2, angle = 10, center = false) { | |
/* | |
chamfer_extrude - OpenSCAD operator module to approximate | |
chamfered/tapered extrusion of a 2D path | |
(C) 2019-02, Stewart Russell (scruss) - CC-BY-SA | |
NOTE: generates _lots_ of facets, as many as | |
6 * path_points + 4 * $fn - 4 | |
Consequently, use with care or lots of memory. | |
Example: | |
chamfer_extrude(height=5,angle=15,$fn=8)square(10); | |
generates a 3D object 5 units high with top surface a | |
10 x 10 square with sides flaring down and out at 15 | |
degrees with roughly rounded corners. | |
Usage: | |
chamfer_extrude ( | |
height = object height: should be positive | |
for reliable results , | |
angle = chamfer angle: degrees , | |
center = false|true: centres object on z-axis [ , | |
$fn = smoothness of chamfer: higher => smoother | |
] | |
) ... 2D path(s) to extrude ... ; | |
$fn in the argument list should be set between 6 .. 16: | |
< 6 can result in striking/unwanted results | |
> 12 is likely a waste of resources. | |
Lower values of $fn can result in steeper sides than expected. | |
Extrusion is not truly trapezoidal, but has a very thin | |
(0.001 unit) parallel section at the base. This is a | |
limitation of OpenSCAD operators available at the time. | |
*/ | |
// shift base of 3d object to origin or | |
// centre at half height if center == true | |
translate([ 0, | |
0, | |
(center == false) ? (height - 0.001) : | |
(height - 0.002) / 2 ]) { | |
minkowski() { | |
// convert 2D path to very thin 3D extrusion | |
linear_extrude(height = 0.001) { | |
children(); | |
} | |
// generate $fn-sided pyramid with apex at origin, | |
// rotated "point-up" along the y-axis | |
rotate(270) { | |
rotate_extrude() { | |
polygon([ | |
[ 0, 0.001 - height ], | |
[ height * tan(angle), 0.001 - height ], | |
[ 0, 0 ] | |
]); | |
} | |
} | |
} | |
} | |
} |
Glad you like it. It could use a little work, but I've made a lot of PET-G signage with it.
The rotate(270)
does have a use if $fn
is small or not even. It ensures that one of the apexes points "north". This was mostly done for aesthetic reasons.
Thank you so much, this is really cool! I find myself stuck between inscrutable CAD software and nearly inscrutable OpenSCAD code, but at least you are in control in the SCAD world. I have no idea how your brilliant little code works, but it solved my problem after hours of hair pulling with other methods.
I have no idea how your brilliant little code works ...
I'd call it useful rather than brilliant, but I'll take it! I should have included a link to the explanatory article: Symmetric chamfered extrusion in OpenSCAD
I find it useful for making signage.
Hello again. I wanted to let you know that your code has been very useful to me for making flexible reproduction feet. If I have the original in good condition, I can usually just trace it on paper, photograph with my phone, and use inkscape to convert it into a path to input to your code which extrudes the 3D version. Like this example: https://drive.google.com/file/d/1mynpQRnZxPLk0iUJqVjRHzwzVHwBZS2T/view?usp=sharing
But sometimes I need them to extrude at a different angle on one or more sides. Any chance your routine can be modified to do this? A typical example of this would be the front and sides at a primary bevel, but the back little or no angle. Currently, I use the output of your code as a starting point, with much painful editing to achieve the final sculpted effect with an angle change. Thanks for any ideas!
I suppose you could do it as the hull between to arbitrary thin polygons, but it wouldn't be easy or work in every situation
This is very helpful - thanks for posting!
I'm curious why the
rotate(270)
is required, as it doesn't seem to affect the example code's behavior since therotate_extrude()
is a 360 deg rotation?