Files
phone-case/primitives.scad

37 lines
1.2 KiB
OpenSCAD

function _toRad(r=undef, d=undef) = (r != undef) ? r : d/2;
module translateIf(cond, amount) {
if (cond) {
translate(amount) children();
} else {
children();
}
}
/// cylinder() where `center=false` behaves like for `cube(center=false)`,
/// i.e. circle center is not at (0, 0) but (r, r)
module cylinderZ(d=undef, r=undef, h=undef, center=false) {
translateIf(!center, [_toRad(r=r, d=d), _toRad(r=r, d=d), 0]) {
cylinder(d=d, r=r, h=h, center=center);
}
}
/// cylinder() but with the axis on the x axis instead of the z axis.
/// and where `center=false` behaves like for `cube(center=false)`,
/// i.e. circle center is not at (0, 0) but (r, r)
module cylinderX(d=undef, r=undef, h=undef, center=false) {
translateIf(!center, [0, _toRad(r=r, d=d), _toRad(r=r, d=d)]) {
rotate(a=[0,-90,0]) cylinder(d=d, r=r, h=h, center=center);
}
}
/// cylinder() but with the axis on the y axis instead of the z axis
/// and where `center=false` behaves like for `cube(center=false)`,
/// i.e. circle center is not at (0, 0) but (r, r)
module cylinderY(d=undef, r=undef, h=undef, center=false) {
translateIf(!center, [_toRad(r=r, d=d), 0, _toRad(r=r, d=d)]) {
rotate(a=[-90,0,0]) cylinder(d=d, r=r, h=h, center=center);
}
}