Skip to content

Instantly share code, notes, and snippets.

@Feuermurmel
Last active August 29, 2015 14:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Feuermurmel/d453fc16992036b25f75 to your computer and use it in GitHub Desktop.
Save Feuermurmel/d453fc16992036b25f75 to your computer and use it in GitHub Desktop.
OpenSCAD minkowski() test cases
minkowski() {
cube();
intersection() {
cube();
translate([2, 2, 2]) {
cube();
}
}
}
minkowski() {
cube();
intersection() {
cube();
// Sharing a face with the other cube.
translate([1, 0, 0]) {
cube();
}
}
}
minkowski() {
cube();
intersection() {
cube();
// Sharing an edge with the other cube.
translate([1, 1, 0]) {
cube();
}
}
}
minkowski() {
cube();
intersection() {
cube();
// Sharing a corner with the other cube.
translate([1, 1, 1]) {
cube();
}
}
}
// Demonstrates that A ⊕ (B ∪ C) = (A ⊕ B) ∪ (A ⊕ C)
// This works correctly in at least version 2015.02
module empty() { }
module identity() {
translate([0, 0, 0]) {
minkowski() {
children(0);
union() {
children(1);
children(2);
}
}
}
translate([0, 5, 0]) {
union() {
minkowski() {
children(0);
children(1);
}
minkowski() {
children(0);
children(2);
}
}
}
}
translate([0, 0, 0]) {
identity() {
sphere($fn = 8);
cube();
translate([1 / 2, 1 / 2, 1 / 2]) cube();
}
}
translate([5, 0, 0]) {
identity() {
empty();
cube();
cube();
}
}
// t(A) ⊕ B = A ⊕ t(B) = t(A ⊕ B)
// This does not work correctly in at least version 2015.02
module empty() { }
module identity() {
// t(A) ⊕ B
translate([0, 5, 0]) {
minkowski() {
translate([0, 0, 2]) {
children(0);
}
children(1);
}
}
// A ⊕ t(B)
translate([0, 10, 0]) {
minkowski() {
children(0);
translate([0, 0, 2]) {
children(1);
}
}
}
// t(A ⊕ B)
translate([0, 0, 0]) {
translate([0, 0, 2]) {
minkowski() {
children(0);
children(1);
}
}
}
}
module empty() { }
translate([0, 0, 0]) {
identity() {
cube();
sphere($fn = 8);
}
}
translate([5, 0, 0]) {
identity() {
cube();
empty();
}
}
// This example demonstrates how the intersection() can be fixed by wrapping each child in a module that does a union with an empty set.
// Takes the union with an empty set. Mathematically this does nothing.
module _fix_empty() {
children(0);
difference() {
cube(1, center = true);
cube(2, center = true);
}
}
// Version of intersection() that treats empty children in a mathematically correct way.
module intersection_fixed() {
intersection() {
_fix_empty()
children(0);
_fix_empty()
children(1);
}
}
module empty() { }
module identity() {
// Intersection with the original intersection() operator.
translate([0, 0, 0]) {
intersection() {
children(0);
children(1);
}
}
// Intersection with the intersection_fixed() operator.
translate([0, 2, 0]) {
intersection_fixed() {
children(0);
children(1);
}
}
}
// Expected: Empty.
// 2015.02: Empty.
translate([0, 0, 0]) {
identity() {
empty();
empty();
}
}
// Expected: Empty.
// 2015.02: A cube (intersection), empty (intersection_fixed).
translate([2, 0, 0]) {
identity() {
empty();
cube();
}
}
// Expected: A cube.
// 2015.02: A cube (intersection), empty (intersection_fixed).
translate([4, 0, 0]) {
identity() {
echo();
cube();
}
}
minkowski() {
cube();
cube();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment