discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Weird results when intersection with a large cube

SL
Steve Lelievre
Sat, May 27, 2023 5:44 PM

I do a lot of modelling that involves discarding the section with a
negative z so I decided to have a little module to do that; see code below.

The module intersects the basic design with a cube occupying the upper
part of the coordinate space. Because I wanted a general purpose module
that didn't depend on my model dimensions, I thought I might as well use
a huge cube, so I read up on the maximum allowed value for a number in
OpenSCAD.  In line with an example in the online documentation I defined
a infinity variable and set it to 1e300 but it didn't work!

Nothing was generated in either preview or render, so I went through a
series of progressively smaller infinities until I got a value that
works in both preview and render.  I have a solution that works but just
for interest - why are there problems with the bigger infinity values?

Steve

module top() {
   // Using OpenSCAD versions 2021.01 or 2023.05.24

   //inf = 1e300;  // fails to display anything in both preview and render; with 2023.05.24, render reports no top level geometry
   //inf = 1e10;   // weird flickering as I change preview angle with mouse; seems okay in render
   //inf = 1e6;    // ok when previewed from above but disappears when I try to view underside; seems okay in render
   inf = 1e4;    // seems okay in both preview and render

   intersection() {
      translate([-inf / 2, -inf / 2, 0]) cube(inf);
      children(0);
   }
}

top() sphere(50);

I do a lot of modelling that involves discarding the section with a negative z so I decided to have a little module to do that; see code below. The module intersects the basic design with a cube occupying the upper part of the coordinate space. Because I wanted a general purpose module that didn't depend on my model dimensions, I thought I might as well use a huge cube, so I read up on the maximum allowed value for a number in OpenSCAD.  In line with an example in the online documentation I defined a infinity variable and set it to 1e300 but it didn't work! Nothing was generated in either preview or render, so I went through a series of progressively smaller infinities until I got a value that works in both preview and render.  I have a solution that works but just for interest - why are there problems with the bigger infinity values? Steve module top() {    // Using OpenSCAD versions 2021.01 or 2023.05.24    //inf = 1e300;  // fails to display anything in both preview and render; with 2023.05.24, render reports no top level geometry    //inf = 1e10;   // weird flickering as I change preview angle with mouse; seems okay in render    //inf = 1e6;    // ok when previewed from above but disappears when I try to view underside; seems okay in render    inf = 1e4;    // seems okay in both preview and render    intersection() {       translate([-inf / 2, -inf / 2, 0]) cube(inf);       children(0);    } } top() sphere(50);