Skip to content

Instantly share code, notes, and snippets.

@speendo
Created November 24, 2015 21:55
Show Gist options
  • Save speendo/c2125ab5732d82348faf to your computer and use it in GitHub Desktop.
Save speendo/c2125ab5732d82348faf to your computer and use it in GitHub Desktop.
// PieTest
/**
* @param float radius Radius of the pie
* @param float angle Angle (size) of the pie to slice
* @param float height Height (thickness) of the pie
* @param float spin Angle to spin the slice on the Z axis
*/
module pie(radius, angle, height, spin=0) {
// submodules
module pieCube() {
translate([-radius - 1, 0, -1]) {
cube([2*(radius + 1), radius, height + 2]);
}
}
ang = abs(angle % 360);
negAng = angle < 0 ? angle : 0;
rotate([0,0,negAng + spin]) {
if (angle == 0) {
cylinder(r=radius, h=height);
} else if (abs(angle) > 0 && ang <= 180) {
difference() {
intersection() {
cylinder(r=radius, h=height);
translate([0,0,0]) {
pieCube();
}
}
rotate([0, 0, ang]) {
pieCube();
}
}
} else if (ang > 180) {
intersection() {
cylinder(r=radius, h=height);
union() {
translate([0, 0, 0]) {
pieCube();
}
rotate([0, 0, ang - 180]) {
pieCube();
}
}
}
}
}
}
pie(radius=10, angle=100, height=20, spin = 20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment