discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Parts cut away with difference() still remains in some situations

T
Troberg
Thu, Nov 9, 2017 8:51 AM

Try this minimalistic code sample:

union(){
color([0.5,0.5,0.5])
cube([50,100,100]);
difference(){
cube([100,100,100]);
translate([-1,-1,-1])
cube([51,102,102]);
}
}

It looks like a mess, with typical "in the same plane hatching".

I've seen this in other situations as well, so I don't think it's a bug in
my code. You can try to comment out the first cube, just to see that the cut
done by difference() is correct.

Shouldn't the cut away parts be gone?

--
Sent from: http://forum.openscad.org/

Try this minimalistic code sample: union(){ color([0.5,0.5,0.5]) cube([50,100,100]); difference(){ cube([100,100,100]); translate([-1,-1,-1]) cube([51,102,102]); } } It looks like a mess, with typical "in the same plane hatching". I've seen this in other situations as well, so I don't think it's a bug in my code. You can try to comment out the first cube, just to see that the cut done by difference() is correct. Shouldn't the cut away parts be gone? -- Sent from: http://forum.openscad.org/
NH
nop head
Thu, Nov 9, 2017 9:27 AM

You need to avoid coincident faces (even removed ones) if you want the
OpenCSG preview to look OK, or use render() to calculate the geometry
before preview.

union(){
color([0.5,0.5,0.5])
cube([50,100,100]);

render() difference(){
    cube([100,100,100]);

    translate([-1,-1,-1])
        cube([52,102,102]);
}

}

On 9 November 2017 at 08:51, Troberg troberg.anders@gmail.com wrote:

Try this minimalistic code sample:

union(){
color([0.5,0.5,0.5])
cube([50,100,100]);
difference(){
cube([100,100,100]);
translate([-1,-1,-1])
cube([51,102,102]);
}
}

It looks like a mess, with typical "in the same plane hatching".

I've seen this in other situations as well, so I don't think it's a bug in
my code. You can try to comment out the first cube, just to see that the
cut
done by difference() is correct.

Shouldn't the cut away parts be gone?

--
Sent from: http://forum.openscad.org/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

You need to avoid coincident faces (even removed ones) if you want the OpenCSG preview to look OK, or use render() to calculate the geometry before preview. union(){ color([0.5,0.5,0.5]) cube([50,100,100]); render() difference(){ cube([100,100,100]); translate([-1,-1,-1]) cube([52,102,102]); } } On 9 November 2017 at 08:51, Troberg <troberg.anders@gmail.com> wrote: > Try this minimalistic code sample: > > union(){ > color([0.5,0.5,0.5]) > cube([50,100,100]); > difference(){ > cube([100,100,100]); > translate([-1,-1,-1]) > cube([51,102,102]); > } > } > > It looks like a mess, with typical "in the same plane hatching". > > I've seen this in other situations as well, so I don't think it's a bug in > my code. You can try to comment out the first cube, just to see that the > cut > done by difference() is correct. > > Shouldn't the cut away parts be gone? > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
T
Troberg
Thu, Nov 9, 2017 10:03 AM

Thanks! Fixed it by moving the surfaces a tiny fraction of a millimeter.

Here's the code I was trying to make, a protractor for on-screen measuring
within a model, a companion to the ruler I've posted earlier. Maybe someone
finds it useful.

module protractor(radius, innerradius){
w=radius-innerradius;
protractorscale(90, innerradius+w/2, innerradius);
protractorscale(45, innerradius+w/2+w/4, innerradius+w/2);
protractorscale(10, innerradius+w/2+w/4+w/8, innerradius+w/2+w/4);
protractorscale(5, innerradius+w/2+w/4+w/8+w/16,
innerradius+w/2+w/4+w/8);
protractorscale(1, radius, innerradius+w/2+w/4+w/8+w/16);

color([0,0,0])
translate([-innerradius,-1/2,0])
cube([innerradius*2,1,1]);
color([0,0,0])
translate([-1/2,-innerradius,0])
cube([1,innerradius*2,1]);

}

module protractorscale(step, radius, innerradius){
difference(){
for(n=[0:step:360]){
union(){
color([(n/step)%2,(n/step)%2,(n/step)%2])
translate([0,0,step/400])
linear_extrude(height=1+step/200)

polygon([[0,0],[sin(n)radius2,cos(n)radius2],[sin(n+step)radius2,cos(n+step)radius2]]);
}
}
difference(){
color([0,0,0])
translate([0,0,-1])
cylinder(r=radius*3,3,$fn=360);
difference(){
color([0,0,0])
translate([0,0,-2])
cylinder(r=radius,5,$fn=360);

            color([0,0,0])
            translate([0,0,-3])
            cylinder(r=innerradius,7,$fn=360);
        }
    }
}

}

//Test
protractor(200,150);

--
Sent from: http://forum.openscad.org/

Thanks! Fixed it by moving the surfaces a tiny fraction of a millimeter. Here's the code I was trying to make, a protractor for on-screen measuring within a model, a companion to the ruler I've posted earlier. Maybe someone finds it useful. module protractor(radius, innerradius){ w=radius-innerradius; protractorscale(90, innerradius+w/2, innerradius); protractorscale(45, innerradius+w/2+w/4, innerradius+w/2); protractorscale(10, innerradius+w/2+w/4+w/8, innerradius+w/2+w/4); protractorscale(5, innerradius+w/2+w/4+w/8+w/16, innerradius+w/2+w/4+w/8); protractorscale(1, radius, innerradius+w/2+w/4+w/8+w/16); color([0,0,0]) translate([-innerradius,-1/2,0]) cube([innerradius*2,1,1]); color([0,0,0]) translate([-1/2,-innerradius,0]) cube([1,innerradius*2,1]); } module protractorscale(step, radius, innerradius){ difference(){ for(n=[0:step:360]){ union(){ color([(n/step)%2,(n/step)%2,(n/step)%2]) translate([0,0,step/400]) linear_extrude(height=1+step/200) polygon([[0,0],[sin(n)*radius*2,cos(n)*radius*2],[sin(n+step)*radius*2,cos(n+step)*radius*2]]); } } difference(){ color([0,0,0]) translate([0,0,-1]) cylinder(r=radius*3,3,$fn=360); difference(){ color([0,0,0]) translate([0,0,-2]) cylinder(r=radius,5,$fn=360); color([0,0,0]) translate([0,0,-3]) cylinder(r=innerradius,7,$fn=360); } } } } //Test protractor(200,150); -- Sent from: http://forum.openscad.org/
NH
nop head
Thu, Nov 9, 2017 10:21 AM

Nice but very slow to pan and zoom on my system due to the number of
objects.

To make it smooth I would put all the put some renders() in at the top
level and then apply colour. That will be slow once to calculate but it is
then cached and drawn quickly. That is how I make big assemblies like 3D
printers with hundreds of parts.

On 9 November 2017 at 10:03, Troberg troberg.anders@gmail.com wrote:

Thanks! Fixed it by moving the surfaces a tiny fraction of a millimeter.

Here's the code I was trying to make, a protractor for on-screen measuring
within a model, a companion to the ruler I've posted earlier. Maybe someone
finds it useful.

module protractor(radius, innerradius){
w=radius-innerradius;
protractorscale(90, innerradius+w/2, innerradius);
protractorscale(45, innerradius+w/2+w/4, innerradius+w/2);
protractorscale(10, innerradius+w/2+w/4+w/8, innerradius+w/2+w/4);
protractorscale(5, innerradius+w/2+w/4+w/8+w/16,
innerradius+w/2+w/4+w/8);
protractorscale(1, radius, innerradius+w/2+w/4+w/8+w/16);

 color([0,0,0])
 translate([-innerradius,-1/2,0])
 cube([innerradius*2,1,1]);
 color([0,0,0])
 translate([-1/2,-innerradius,0])
 cube([1,innerradius*2,1]);

}

module protractorscale(step, radius, innerradius){
difference(){
for(n=[0:step:360]){
union(){
color([(n/step)%2,(n/step)%2,(n/step)%2])
translate([0,0,step/400])
linear_extrude(height=1+step/200)

polygon([[0,0],[sin(n)radius2,cos(n)radius2],[sin(n+
step)radius2,cos(n+step)radius2]]);
}
}
difference(){
color([0,0,0])
translate([0,0,-1])
cylinder(r=radius*3,3,$fn=360);
difference(){
color([0,0,0])
translate([0,0,-2])
cylinder(r=radius,5,$fn=360);

             color([0,0,0])
             translate([0,0,-3])
             cylinder(r=innerradius,7,$fn=360);
         }
     }
 }

}

//Test
protractor(200,150);

--
Sent from: http://forum.openscad.org/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Nice but very slow to pan and zoom on my system due to the number of objects. To make it smooth I would put all the put some renders() in at the top level and then apply colour. That will be slow once to calculate but it is then cached and drawn quickly. That is how I make big assemblies like 3D printers with hundreds of parts. On 9 November 2017 at 10:03, Troberg <troberg.anders@gmail.com> wrote: > Thanks! Fixed it by moving the surfaces a tiny fraction of a millimeter. > > Here's the code I was trying to make, a protractor for on-screen measuring > within a model, a companion to the ruler I've posted earlier. Maybe someone > finds it useful. > > module protractor(radius, innerradius){ > w=radius-innerradius; > protractorscale(90, innerradius+w/2, innerradius); > protractorscale(45, innerradius+w/2+w/4, innerradius+w/2); > protractorscale(10, innerradius+w/2+w/4+w/8, innerradius+w/2+w/4); > protractorscale(5, innerradius+w/2+w/4+w/8+w/16, > innerradius+w/2+w/4+w/8); > protractorscale(1, radius, innerradius+w/2+w/4+w/8+w/16); > > color([0,0,0]) > translate([-innerradius,-1/2,0]) > cube([innerradius*2,1,1]); > color([0,0,0]) > translate([-1/2,-innerradius,0]) > cube([1,innerradius*2,1]); > } > > module protractorscale(step, radius, innerradius){ > difference(){ > for(n=[0:step:360]){ > union(){ > color([(n/step)%2,(n/step)%2,(n/step)%2]) > translate([0,0,step/400]) > linear_extrude(height=1+step/200) > > polygon([[0,0],[sin(n)*radius*2,cos(n)*radius*2],[sin(n+ > step)*radius*2,cos(n+step)*radius*2]]); > } > } > difference(){ > color([0,0,0]) > translate([0,0,-1]) > cylinder(r=radius*3,3,$fn=360); > difference(){ > color([0,0,0]) > translate([0,0,-2]) > cylinder(r=radius,5,$fn=360); > > color([0,0,0]) > translate([0,0,-3]) > cylinder(r=innerradius,7,$fn=360); > } > } > } > } > > //Test > protractor(200,150); > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
RP
Ronaldo Persiano
Thu, Nov 9, 2017 10:44 AM

As another nice touch, avoid the proctator to be rendered by an
accidentally hit F6. Just insert a % between the color and render()
suggested by nophead. That is what I do in my ruler code.

Em 9 de nov de 2017 08:22, "nop head" nop.head@gmail.com escreveu:

Nice but very slow to pan and zoom on my system due to the number of
objects.

To make it smooth I would put all the put some renders() in at the top
level and then apply colour. That will be slow once to calculate but it is
then cached and drawn quickly. That is how I make big assemblies like 3D
printers with hundreds of parts.

On 9 November 2017 at 10:03, Troberg troberg.anders@gmail.com wrote:

Thanks! Fixed it by moving the surfaces a tiny fraction of a millimeter.

Here's the code I was trying to make, a protractor for on-screen measuring
within a model, a companion to the ruler I've posted earlier. Maybe
someone
finds it useful.

module protractor(radius, innerradius){
w=radius-innerradius;
protractorscale(90, innerradius+w/2, innerradius);
protractorscale(45, innerradius+w/2+w/4, innerradius+w/2);
protractorscale(10, innerradius+w/2+w/4+w/8, innerradius+w/2+w/4);
protractorscale(5, innerradius+w/2+w/4+w/8+w/16,
innerradius+w/2+w/4+w/8);
protractorscale(1, radius, innerradius+w/2+w/4+w/8+w/16);

 color([0,0,0])
 translate([-innerradius,-1/2,0])
 cube([innerradius*2,1,1]);
 color([0,0,0])
 translate([-1/2,-innerradius,0])
 cube([1,innerradius*2,1]);

}

module protractorscale(step, radius, innerradius){
difference(){
for(n=[0:step:360]){
union(){
color([(n/step)%2,(n/step)%2,(n/step)%2])
translate([0,0,step/400])
linear_extrude(height=1+step/200)

polygon([[0,0],[sin(n)radius2,cos(n)radius2],[sin(n+step
)radius2,cos(n+step)radius2]]);
}
}
difference(){
color([0,0,0])
translate([0,0,-1])
cylinder(r=radius*3,3,$fn=360);
difference(){
color([0,0,0])
translate([0,0,-2])
cylinder(r=radius,5,$fn=360);

             color([0,0,0])
             translate([0,0,-3])
             cylinder(r=innerradius,7,$fn=360);
         }
     }
 }

}

//Test
protractor(200,150);

--
Sent from: http://forum.openscad.org/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

As another nice touch, avoid the proctator to be rendered by an accidentally hit F6. Just insert a % between the color and render() suggested by nophead. That is what I do in my ruler code. Em 9 de nov de 2017 08:22, "nop head" <nop.head@gmail.com> escreveu: > Nice but very slow to pan and zoom on my system due to the number of > objects. > > To make it smooth I would put all the put some renders() in at the top > level and then apply colour. That will be slow once to calculate but it is > then cached and drawn quickly. That is how I make big assemblies like 3D > printers with hundreds of parts. > > On 9 November 2017 at 10:03, Troberg <troberg.anders@gmail.com> wrote: > >> Thanks! Fixed it by moving the surfaces a tiny fraction of a millimeter. >> >> Here's the code I was trying to make, a protractor for on-screen measuring >> within a model, a companion to the ruler I've posted earlier. Maybe >> someone >> finds it useful. >> >> module protractor(radius, innerradius){ >> w=radius-innerradius; >> protractorscale(90, innerradius+w/2, innerradius); >> protractorscale(45, innerradius+w/2+w/4, innerradius+w/2); >> protractorscale(10, innerradius+w/2+w/4+w/8, innerradius+w/2+w/4); >> protractorscale(5, innerradius+w/2+w/4+w/8+w/16, >> innerradius+w/2+w/4+w/8); >> protractorscale(1, radius, innerradius+w/2+w/4+w/8+w/16); >> >> color([0,0,0]) >> translate([-innerradius,-1/2,0]) >> cube([innerradius*2,1,1]); >> color([0,0,0]) >> translate([-1/2,-innerradius,0]) >> cube([1,innerradius*2,1]); >> } >> >> module protractorscale(step, radius, innerradius){ >> difference(){ >> for(n=[0:step:360]){ >> union(){ >> color([(n/step)%2,(n/step)%2,(n/step)%2]) >> translate([0,0,step/400]) >> linear_extrude(height=1+step/200) >> >> polygon([[0,0],[sin(n)*radius*2,cos(n)*radius*2],[sin(n+step >> )*radius*2,cos(n+step)*radius*2]]); >> } >> } >> difference(){ >> color([0,0,0]) >> translate([0,0,-1]) >> cylinder(r=radius*3,3,$fn=360); >> difference(){ >> color([0,0,0]) >> translate([0,0,-2]) >> cylinder(r=radius,5,$fn=360); >> >> color([0,0,0]) >> translate([0,0,-3]) >> cylinder(r=innerradius,7,$fn=360); >> } >> } >> } >> } >> >> //Test >> protractor(200,150); >> >> >> >> -- >> Sent from: http://forum.openscad.org/ >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
T
Troberg
Thu, Nov 9, 2017 10:58 AM

That would mean that I would first have to make all the white objects, then
all the black. Too much work for an occasional measurement...

--
Sent from: http://forum.openscad.org/

That would mean that I would first have to make all the white objects, then all the black. Too much work for an occasional measurement... -- Sent from: http://forum.openscad.org/