[OpenSCAD] Problems making a negative space

Hans L thehans at gmail.com
Mon Oct 21 19:08:45 EDT 2019

```Hoo boy, there's a lot going on here.

1) Your main issue looks like you have the modules swapped around in your
difference operation.  You want the (cylinder minus the "inverse_lattice")
right?    A - B is not the same as B - A, so the module you list first
matters.
2) Your "module_inverse_proper" is unnecessary.  There's no reason to get
the intersection of your negative object with the same positive object that
its about to be subtracted from.
3) Learn to use "for" loops, instead of nesting dozens of calls, you could
probably shorten your code by 10x or so.
4) This is a really complex model and going to take quite a while to
You can get around the issue of exponentially exploding number of CSG
elements somewhat, by wrapping your lattice with a call to render() (
like so:

module lattice() {
render() rotate([45, 0, 0]) intersection() {
cube(C, center = true);
sphere(S);
}
}

5) sphere doesn't have a "center" parameter.  Its always centered, which is
why those warnings are showing.
6) You have these weird patterns of expression all around your code:
sqrt(pow(X,2) * Y)  OR   sqrt(pow(X,2) / Y)
sqrt(pow(X,2) * Y)  ==  ( X * sqrt(Y) ) since your X expression is always
positive anyways.  So they can be simplified for better readability.

- Hans

On Mon, Oct 21, 2019 at 2:55 PM matt meek via Discuss <

> Hello,
>
> I'm having issues making a negative space with difference. I'm trying to
> make a lattice, and have made all of what will be negative spaces, but when
> I try to invert them the difference function removed my whole model. I've
> tried offsetting the shape I'm subtracting, and that hasn't made a
> difference. I also tried increasing the number of facets in case it was a
> resolution issue, and also changing the order in which I use the difference
> function, but that also has made no difference.Please could someone help?
> Apologies for the unelegant code, I'm a newbie.
>
> Matt
>
>
>
>
> \$fn=20;
>
> R=10;
> n=12;
> C=sqrt((pow((2*PI*R)/n,2))/2);
> S=0.625*C;
>
> difference(){
> inverse_lattice_proper();
>     cyl();
> }
>
> module inverse_lattice_proper(){
> intersection(){
>   cyl();
>     inverse_lattice();
> }}
>
>
>
> module inverse_lattice(){
> layer_1();
> layer_2();
> layer_3();
> layer_4();
> layer_5();
> layer_6();
> }
>
> module layer_6(){
>     scale([(R-(sqrt(pow(C,2)*2)/2))/R,(R-(sqrt(pow(C,2)*2)/2))/R,1])
> layer_5();
> }
> module layer_5(){
>     scale([(R-(sqrt(pow(C,2)*2)/2))/R,(R-(sqrt(pow(C,2)*2)/2))/R,1])
> layer_4();
> }
>
> module layer_4(){
>     scale([(R-(sqrt(pow(C,2)*2)/2))/R,(R-(sqrt(pow(C,2)*2)/2))/R,1])
> layer_3();
> }
>
> module layer_3(){
>     scale([(R-(sqrt(pow(C,2)*2)/2))/R,(R-(sqrt(pow(C,2)*2)/2))/R,1])
> layer_2();
> }
>
> module layer_2(){
>     scale([(R-(sqrt(pow(C,2)*2)/2))/R,(R-(sqrt(pow(C,2)*2)/2))/R,1])
> layer_1();
> }
>
> module lattice(){
>     rotate([45,0,0]){
> intersection(){
> cube(C, center=true);
> sphere(S, center=true);
> }
> }
> }
> module cyl(){
> translate([0,0,10]){
> cylinder (h=40,r=R,center=true);
> }
> }module layer_1(){
> layer();
> translate([0,0,sqrt(pow(C,2)*2)/2]){
>     rotate ([0,0,180/n]){
>         layer();
>     translate([0,0,sqrt(pow(C,2)*2)/2]){
>     rotate ([0,0,180/n]){
>         layer();
>         translate([0,0,sqrt(pow(C,2)*2)/2]){
>     rotate ([0,0,180/n]){
>         layer();translate([0,0,sqrt(pow(C,2)*2)/2]){
>     rotate ([0,0,180/n]){
>         layer();translate([0,0,sqrt(pow(C,2)*2)/2]){
>     rotate ([0,0,180/n]){
>         layer();translate([0,0,sqrt(pow(C,2)*2)/2]){
>     rotate ([0,0,180/n]){
>         layer();translate([0,0,sqrt(pow(C,2)*2)/2]){
>     rotate ([0,0,180/n]){
>         layer();
>         translate([0,0,sqrt(pow(C,2)*2)/2]){
>     rotate ([0,0,180/n]){
>         layer();
>         translate([0,0,sqrt(pow(C,2)*2)/2]){
>     rotate ([0,0,180/n]){
>         layer();
>         translate([0,0,sqrt(pow(C,2)*2)/2]){
>     rotate ([0,0,180/n]){
>         layer();
>         translate([0,0,sqrt(pow(C,2)*2)/2]){
>     rotate ([0,0,180/n]){
>         layer();
>         translate([0,0,sqrt(pow(C,2)*2)/2]){
>     rotate ([0,0,180/n]){
>         layer();
>         translate([0,0,sqrt(pow(C,2)*2)/2]){
>     rotate ([0,0,180/n]){
>         layer();
>     }
>     }}}}}}}}}}}}}}}}}}}}}}}}}}
>
> module layer(){
> union(){
> translate([R,0,0.5*C]){lattice();
> translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate ([0,0,360/n]){lattice();
>         translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate ([0,0,360/n]){lattice();
>         translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate ([0,0,360/n]){lattice();
>         translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate
> ([0,0,360/n]){lattice();translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate ([0,0,360/n]){lattice();
>         translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate ([0,0,360/n]){lattice();
> translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate ([0,0,360/n]){lattice();
>         translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate ([0,0,360/n]){lattice();
>         translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate ([0,0,360/n]){lattice();
>         translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate
> ([0,0,360/n]){lattice();translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate ([0,0,360/n]){lattice();
>         translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate ([0,0,360/n]){lattice();
>         translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate ([0,0,360/n]){lattice();
>         translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate ([0,0,360/n]){lattice();
>         translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate ([0,0,360/n]){lattice();
>         translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate
> ([0,0,360/n]){lattice();translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate ([0,0,360/n]){lattice();
>         translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate ([0,0,360/n]){lattice();
> translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate ([0,0,360/n]){lattice();
>         translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate ([0,0,360/n]){lattice();
>         translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate ([0,0,360/n]){lattice();
>         translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate
> ([0,0,360/n]){lattice();translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate ([0,0,360/n]){lattice();
>         translate([R*cos(360/n)-R,R*sin(360/n),0]){
>     rotate ([0,0,360/n]){lattice();
> }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}};
>
>
>
> _______________________________________________
>
-------------- next part --------------
An HTML attachment was scrubbed...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2019-10-21 (7).png
Type: image/png
Size: 93893 bytes
Desc: not available
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2019-10-21 (8).png
Type: image/png
Size: 35987 bytes
Desc: not available
```