79 lines
2.2 KiB
OpenSCAD
79 lines
2.2 KiB
OpenSCAD
/// Chamfering OpenSCAD Example
|
|
/// Written by Robert Quattlebaum, 2022-12-14
|
|
///
|
|
/// This example shows a method for adding a chamfer to a certain
|
|
/// class of 3D objects where the profile in the Z dimension doesn't
|
|
/// change significantly.
|
|
///
|
|
/// You must specify the size of the chamfer, the height of the child
|
|
/// and the Z-offset for the bottom of the object. You can also specify
|
|
/// the shape of the chamfer, which can be either "cone", "curve", "curve-in",
|
|
/// or "pyramid".
|
|
///
|
|
/// This process is ultimately slow, but should be faster than using minkowski.
|
|
|
|
module chamfer(size=2, child_h=5, child_bot=0, shape="curve") {
|
|
chamfer_size=size;
|
|
|
|
module chamfer_shape() {
|
|
if (shape == "cone") {
|
|
$fn=16;
|
|
cylinder(chamfer_size/2,chamfer_size/2,0);
|
|
} else if (shape == "curve") {
|
|
$fn=4;
|
|
for( y = [0:1/$fn:1]) {
|
|
cylinder(chamfer_size/2*(1-y),chamfer_size/2/cos(180/$fn)*y,0);
|
|
}
|
|
} else if (shape == "curve-in") {
|
|
$fn=16;
|
|
intersection() {
|
|
sphere(chamfer_size/2/cos(180/$fn));
|
|
translate([0,0,chamfer_size/2])
|
|
cube(chamfer_size, center=true);
|
|
}
|
|
} else if (shape == "pyramid") {
|
|
$fn=4;
|
|
cylinder(chamfer_size/2/cos(180/$fn),chamfer_size/2,0);
|
|
}
|
|
}
|
|
|
|
module lower_chamfer() {
|
|
minkowski()
|
|
{
|
|
linear_extrude(0.0001) difference() {
|
|
square([1000,1000],center=true);
|
|
projection()children(0);
|
|
}
|
|
chamfer_shape();
|
|
}
|
|
}
|
|
|
|
module upper_chamfer() {
|
|
scale([1,1,-1])lower_chamfer()children();
|
|
}
|
|
|
|
render()difference() {
|
|
children();
|
|
translate([0,0,child_bot])lower_chamfer()children();
|
|
translate([0,0,child_bot+child_h])upper_chamfer()children();
|
|
}
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
module my_shape(h=5) {
|
|
translate([0,0,h/2]) {
|
|
difference() {
|
|
cube([50,50,h],center=true);
|
|
cube([20,20,h+1],center=true);
|
|
}
|
|
translate([20,21,0])cylinder(h=h,r=20,center=true);
|
|
}
|
|
}
|
|
|
|
|
|
h=5;
|
|
|
|
chamfer(3, child_h=h, shape="cone")
|
|
my_shape(h);
|