Skip to content

Instantly share code, notes, and snippets.

@turingbirds
Last active March 15, 2022 13:24
Show Gist options
  • Save turingbirds/f43b65e15db90c0f305f8db155ae3ce3 to your computer and use it in GitHub Desktop.
Save turingbirds/f43b65e15db90c0f305f8db155ae3ce3 to your computer and use it in GitHub Desktop.
Beveled wedge shape for OpenSCAD
// Beveled wedge shape for OpenSCAD
// Written by C.A.P. Linssen <charl@itfromb.it>, Sept 2018
// This software is distributed under the "CC0 1.0 Universal (CC0 1.0)" license.
// You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
// module bwedge
// @param size vector specifying the size along the [x, y, z] axes
// @param ratio wedge tapering ratio, 0 for a cube, higher for a sharper wedge
// @param wedge_axis the sharp end of the wedge will point towards the positive axis specified by `wedge_axis` [0..2]
// @param br bevel sphere radius
module bwedge(size, ratio, wedge_axis=2, br=0)
{
bsize = size - 2 * [br, br, br];
a = (wedge_axis == 0) ? 90 :
((wedge_axis == 1) ? 0 :
((wedge_axis == 2) ? 90 : 0));
v = (wedge_axis == 0) ? [0, 0, -1] :
((wedge_axis == 1) ? [1, 0, 0] :
((wedge_axis == 2) ? [1, 0, 0] : [1, 0, 0]));
x = (wedge_axis == 0) ? bsize[1]/2 :
((wedge_axis == 1) ? bsize[0]/2 :
((wedge_axis == 2) ? bsize[0]/2 : 0));
y = (wedge_axis == 0) ? bsize[2]/2 :
((wedge_axis == 1) ? bsize[2]/2 :
((wedge_axis == 2) ? bsize[1]/2 : 0));
z = (wedge_axis == 0) ? bsize[0]/2 :
((wedge_axis == 1) ? bsize[1]/2 :
((wedge_axis == 2) ? bsize[2]/2 : 0));
if (x <= 0 || y <= 0 || z <= 0) {
echo("ERROR: width of the shape is less than bevel radius");
}
minkowski() {
rotate(a=a, v=v)
translate([0, 0, -y])
linear_extrude(height=2*y) polygon([[-x, -z], [x, -z], [ratio*x, z], [-ratio*x, z]]);
sphere(r=br, center=true);
}
}
// example:
bwedge([300, 20, 40], ratio=.5, br=5, wedge_axis=2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment