Difference leaves faces

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Difference leaves faces

Bananapeel
It's me again :)

Why does this end with disaster? The F5 preview is full of "pink" patterns and in the F6 view there are extra faces.

ribs_h = 20;
ribs_area_w = 170;

module ribs() {
	cube([ribs_area_w,ribs_area_w,ribs_h]);
}

module trim(length=100) {
	translate([0,ribs_area_w/2, ribs_h/2])
	rotate([90,0,90])
	linear_extrude(length)
	scale([170,20]) {
		difference() {
			square(1, center=true);
			union() {
				circle(0.5, $fn=100);
				translate([0,-0.25])
				square([1,0.5], center=true);
			}
		}
	}
}

difference() {
	ribs();
	trim(170);
}

*ribs();
*trim();

Best wishes,
Bananapeel :)
Reply | Threaded
Open this post in threaded view
|

Re: Difference leaves faces

kintel
Administrator
On Oct 15, 2014, at 08:47 AM, Bananapeel <[hidden email]> wrote:

> Why does this end with disaster? The F5 preview is full of "pink" patterns
> and in the F6 view there are extra faces.
>
Please post an example.

 -Marius

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: Difference leaves faces

nophead
In reply to this post by Bananapeel
It ends in disaster because you make a shape with infinitely thin parts where a circle meets a square tangentially, scale it up and subtract it from a cube exactly the same size. In a a pure maths world that works but on a digital computer with floating point hardware it doesn't.

The shape you subtract needs to overlap the cube a little to get a clean result.

But since you are subtracting a circle from a square and then subtracting that from a cube it would be easier to make the positive shape than doing a double subtraction as that avoids infinitely thin bits.



Reply | Threaded
Open this post in threaded view
|

Re: Difference leaves faces

kintel
Administrator
Wops, sorry, didn’t see the code (it didn’t make it to the mailing list, only the forum..)
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: Difference leaves faces

Bananapeel
In reply to this post by nophead
Thanks,  so OpenSCAD uses floating point numbers. Does it use single (4-byte) or double precision?

Reply | Threaded
Open this post in threaded view
|

Re: Difference leaves faces

kintel
Administrator
On Oct 15, 2014, at 13:28 PM, Bananapeel <[hidden email]> wrote:

> Thanks,  so OpenSCAD uses floating point numbers. Does it use single (4-byte)
> or double precision?
>
What you see are OpenGL rendering artifacts due to the z buffer not managing to distinguish between two close surfaces.
OpenGL renders using 32-bit floats but the z buffer depth may vary from platform to platform and is usually not linear.

 -Marius

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
ink
Reply | Threaded
Open this post in threaded view
|

Re: Difference leaves faces

ink
So if I tried to print this it would end up looking like the monstrosity I see after taking the difference? 

On Wed, Oct 15, 2014 at 2:26 PM, Marius Kintel <[hidden email]> wrote:
On Oct 15, 2014, at 13:28 PM, Bananapeel <[hidden email]> wrote:

> Thanks,  so OpenSCAD uses floating point numbers. Does it use single (4-byte)
> or double precision?
>
What you see are OpenGL rendering artifacts due to the z buffer not managing to distinguish between two close surfaces.
OpenGL renders using 32-bit floats but the z buffer depth may vary from platform to platform and is usually not linear.

 -Marius

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: Difference leaves faces

Miro Hrončok

Generally you can always consider F6 as the result you will get and consider F5 as fast but dummy preview.

Dne 15.10.2014 20:44 "Ian Kirkpatrick" <[hidden email]> napsal(a):
So if I tried to print this it would end up looking like the monstrosity I see after taking the difference? 

On Wed, Oct 15, 2014 at 2:26 PM, Marius Kintel <[hidden email]> wrote:
On Oct 15, 2014, at 13:28 PM, Bananapeel <[hidden email]> wrote:

> Thanks,  so OpenSCAD uses floating point numbers. Does it use single (4-byte)
> or double precision?
>
What you see are OpenGL rendering artifacts due to the z buffer not managing to distinguish between two close surfaces.
OpenGL renders using 32-bit floats but the z buffer depth may vary from platform to platform and is usually not linear.

 -Marius

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: Difference leaves faces

MichaelAtOz
Administrator
In reply to this post by Bananapeel
See below. Usually you would position and size things accurately, not use scale().

ribs_h = 20;
ribs_area_w = 170;

module ribs() {
        cube([ribs_area_w,ribs_area_w,ribs_h]);
}

module trim(length=100) {
        translate([0,ribs_area_w/2, ribs_h/2])
        rotate([90,0,90])
        linear_extrude(length)
        scale([170,20]) {
                difference() {
                        square(1, center=true);
                        union() {
                                circle(0.5, $fn=100);
                                translate([0,-0.25])
                                square([1.01,0.501], center=true); // changed
                        }
                }
        }
}

difference() {
        ribs();
        translate([-0.02,-0.02,0]) // changed, quick and dirty way.
        scale(1.001) // Fiddle with these and see what you get if you remove them
        trim(170);
}

*ribs();
*trim();
Admin - email* me if you need anything, or if I've done something stupid...
* click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.