[OpenSCAD] Problems making a negative space

matt meek elephant100 at hotmail.co.uk
Mon Oct 21 15:55:08 EDT 2019


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
[cid:c4aabeea-e83d-49a1-92cb-656151fa520a][cid:5e4ebe26-737b-44a1-8627-cb01603d9392]



$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...
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20191021/67904f72/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2019-10-21 (7).png
Type: image/png
Size: 93893 bytes
Desc: 2019-10-21 (7).png
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20191021/67904f72/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2019-10-21 (8).png
Type: image/png
Size: 35987 bytes
Desc: 2019-10-21 (8).png
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20191021/67904f72/attachment-0001.png>


More information about the Discuss mailing list