discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

getting the boundaries of a stl

A
ahmad
Sat, Aug 12, 2017 4:36 AM

Hi guys

I am trying to find out the minx,miny,minz,  maxx,maxy,maxz of a stl file(
i.e. the boundaries of it). in there any function to do so? I found this:
https://github.com/openscad/openscad/issues/301

but I could not run them.

Thanks

Hi guys I am trying to find out the minx,miny,minz, maxx,maxy,maxz of a stl file( i.e. the boundaries of it). in there any function to do so? I found this: https://github.com/openscad/openscad/issues/301 but I could not run them. Thanks
MM
Michael Marx
Sat, Aug 12, 2017 4:44 AM

If you mean inside your .scad code, currently no.

There is a lot of historical discussion re this, and related concepts. I would not hold your breath
ATM.

The issue is that OpenSCAD mojo is around fast preview, and separate slow render.

The F5 preview does not calculate the actual 3D geometry coordinates, so that info is not available
at run time.

Such coordinates come from a slow render calculated the exact 3D geometry.

You can get that static info from the STL with programs such as Netfabb basic.


From: Discuss [mailto:discuss-bounces@lists.openscad.org] On Behalf Of ahmad
Sent: Sat, 12 Aug 2017 14:36
To: OpenSCAD general discussion
Subject: [OpenSCAD] getting the boundaries of a stl

Hi guys

I am trying to find out the minx,miny,minz,  maxx,maxy,maxz of a stl file( i.e. the boundaries of
it). in there any function to do so? I found this:
https://github.com/openscad/openscad/issues/301

but I could not run them.

Thanks

If you mean inside your .scad code, currently no. There is a lot of historical discussion re this, and related concepts. I would not hold your breath ATM. The issue is that OpenSCAD mojo is around fast preview, and separate slow render. The F5 preview does not calculate the actual 3D geometry coordinates, so that info is not available at run time. Such coordinates come from a slow render calculated the exact 3D geometry. You can get that static info from the STL with programs such as Netfabb basic. _____ From: Discuss [mailto:discuss-bounces@lists.openscad.org] On Behalf Of ahmad Sent: Sat, 12 Aug 2017 14:36 To: OpenSCAD general discussion Subject: [OpenSCAD] getting the boundaries of a stl Hi guys I am trying to find out the minx,miny,minz, maxx,maxy,maxz of a stl file( i.e. the boundaries of it). in there any function to do so? I found this: https://github.com/openscad/openscad/issues/301 but I could not run them. Thanks
A
ahmad
Sat, Aug 12, 2017 6:01 AM

What about outside scad script, i.e. in commnad line?

On Aug 11, 2017 9:45 PM, "Michael Marx" michael.marx@tpg.com.au wrote:

If you mean inside your .scad code, currently no.

There is a lot of historical discussion re this, and related concepts. I
would not hold your breath ATM.

The issue is that OpenSCAD mojo is around fast preview, and separate slow
render.

The F5 preview does not calculate the actual 3D geometry coordinates, so
that info is not available at run time.

Such coordinates come from a slow render calculated the exact 3D geometry.

You can get that static info from the STL with programs such as Netfabb
basic.


From: Discuss [mailto:discuss-bounces@lists.openscad.org] *On Behalf Of
*ahmad
Sent: Sat, 12 Aug 2017 14:36
To: OpenSCAD general discussion
Subject: [OpenSCAD] getting the boundaries of a stl

Hi guys

I am trying to find out the minx,miny,minz,  maxx,maxy,maxz of a stl
file( i.e. the boundaries of it). in there any function to do so? I found
this:
https://github.com/openscad/openscad/issues/301

but I could not run them.

Thanks


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

What about outside scad script, i.e. in commnad line? On Aug 11, 2017 9:45 PM, "Michael Marx" <michael.marx@tpg.com.au> wrote: > If you mean inside your .scad code, currently no. > > There is a lot of historical discussion re this, and related concepts. I > would not hold your breath ATM. > > > > The issue is that OpenSCAD mojo is around fast preview, and separate slow > render. > > The F5 preview does not calculate the actual 3D geometry coordinates, so > that info is not available at run time. > > Such coordinates come from a slow render calculated the exact 3D geometry. > > > > You can get that static info from the STL with programs such as Netfabb > basic. > > > ------------------------------ > > *From:* Discuss [mailto:discuss-bounces@lists.openscad.org] *On Behalf Of > *ahmad > *Sent:* Sat, 12 Aug 2017 14:36 > *To:* OpenSCAD general discussion > *Subject:* [OpenSCAD] getting the boundaries of a stl > > > > Hi guys > > I am trying to find out the minx,miny,minz, maxx,maxy,maxz of a stl > file( i.e. the boundaries of it). in there any function to do so? I found > this: > https://github.com/openscad/openscad/issues/301 > > > but I could not run them. > > Thanks > > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
MM
Michael Marx
Sat, Aug 12, 2017 6:22 AM

Not ATM, some in the discussion may be more amenable to something driven that way.

Or even something in the console after a render/F6, just spit out the bounding box & other readily
available info.

I agree, not having the size of a STL for import is annoying.

As I said, I use Netfabb Basic, as basic info it gives:

(I imagine there are other tools too)

It also has a measuring system where you can do stuff like:


From: Discuss [mailto:discuss-bounces@lists.openscad.org] On Behalf Of ahmad
Sent: Sat, 12 Aug 2017 16:01
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] getting the boundaries of a stl

What about outside scad script, i.e. in commnad line?

On Aug 11, 2017 9:45 PM, "Michael Marx" michael.marx@tpg.com.au wrote:

If you mean inside your .scad code, currently no.

There is a lot of historical discussion re this, and related concepts. I would not hold your breath
ATM.

The issue is that OpenSCAD mojo is around fast preview, and separate slow render.

The F5 preview does not calculate the actual 3D geometry coordinates, so that info is not available
at run time.

Such coordinates come from a slow render calculated the exact 3D geometry.

You can get that static info from the STL with programs such as Netfabb basic.


From: Discuss [mailto:discuss-bounces@lists. mailto:discuss-bounces@lists.openscad.org
openscad.org] On Behalf Of ahmad
Sent: Sat, 12 Aug 2017 14:36
To: OpenSCAD general discussion
Subject: [OpenSCAD] getting the boundaries of a stl

Hi guys

I am trying to find out the minx,miny,minz,  maxx,maxy,maxz of a stl file( i.e. the boundaries of
it). in there any function to do so? I found this:
https://github.com/openscad/ https://github.com/openscad/openscad/issues/301 openscad/issues/301

but I could not run them.

Thanks


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

Not ATM, some in the discussion may be more amenable to something driven that way. Or even something in the console after a render/F6, just spit out the bounding box & other readily available info. I agree, not having the size of a STL for import is annoying. As I said, I use Netfabb Basic, as basic info it gives: (I imagine there are other tools too) It also has a measuring system where you can do stuff like: _____ From: Discuss [mailto:discuss-bounces@lists.openscad.org] On Behalf Of ahmad Sent: Sat, 12 Aug 2017 16:01 To: OpenSCAD general discussion Subject: Re: [OpenSCAD] getting the boundaries of a stl What about outside scad script, i.e. in commnad line? On Aug 11, 2017 9:45 PM, "Michael Marx" <michael.marx@tpg.com.au> wrote: If you mean inside your .scad code, currently no. There is a lot of historical discussion re this, and related concepts. I would not hold your breath ATM. The issue is that OpenSCAD mojo is around fast preview, and separate slow render. The F5 preview does not calculate the actual 3D geometry coordinates, so that info is not available at run time. Such coordinates come from a slow render calculated the exact 3D geometry. You can get that static info from the STL with programs such as Netfabb basic. _____ From: Discuss [mailto:discuss-bounces@lists. <mailto:discuss-bounces@lists.openscad.org> openscad.org] On Behalf Of ahmad Sent: Sat, 12 Aug 2017 14:36 To: OpenSCAD general discussion Subject: [OpenSCAD] getting the boundaries of a stl Hi guys I am trying to find out the minx,miny,minz, maxx,maxy,maxz of a stl file( i.e. the boundaries of it). in there any function to do so? I found this: https://github.com/openscad/ <https://github.com/openscad/openscad/issues/301> openscad/issues/301 but I could not run them. Thanks _______________________________________________ OpenSCAD mailing list Discuss@lists.openscad.org http://lists.openscad.org/ <http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org> mailman/listinfo/discuss_lists.openscad.org
SR
Sebastien Roy (DIRO)
Sat, Aug 12, 2017 1:28 PM

Hi,

Le samedi 12 août 2017 à 14:44 +1000, Michael Marx a écrit :

If you mean inside your .scad code, currently no.
There is a lot of historical discussion re this, and related
concepts. I would not hold your breath ATM.
 
The issue is that OpenSCAD mojo is around fast preview, and separate
slow render.
The F5 preview does not calculate the actual 3D geometry coordinates,
so that info is not available at run time.
Such coordinates come from a slow render calculated the exact 3D
geometry.
 
You can get that static info from the STL with programs such as
Netfabb basic.

I coded an extension("probe()" wich provides bounding box information,
as well as volume and center of mass.

As Michael says, this feature requires a "render" of the geometry, even
when previewing the geometry, which should be as fast as possible. In
fact, every time your ask for a bounding box, it is exactly equivalent
to calling render().

My opinion is that some features, like knowing the bounding box of some
geometry (especially imported stl) is sometimes essential. This means
that the wait for rendering is fully justified by the usefulness of the
feature. Note that I do not suggest to automatically compute this
information, but only on request, so whoever use it realize that he is
going to slow down his rendering. I dont see anyone putting "render()"
all over their code just to slow it down for for no reason... why
should it be different with a probe() function to get geometric
information?

I consider that the lack of such simple geometric computation as the
bounding box is a weakness of openscad, which makes a whole category of
models impossible to code.

As for using an outside program, this is ok when you need the
information once, but openscad strength is parametrization, which is
not compatible with running helper programs by hand.

If there is interest, my "probe" branch is still available. Sorry for
bringing back this discussion, but I did not start it :-)

Sincerely,

Sebastien

 
From: Discuss [mailto:discuss-bounces@lists.openscad.org] On Behalf
Of ahmad
Sent: Sat, 12 Aug 2017 14:36
To: OpenSCAD general discussion
Subject: [OpenSCAD] getting the boundaries of a stl
 
Hi guys

I am trying to find out the minx,miny,minz,   maxx,maxy,maxz of a stl
file( i.e. the boundaries of it). in there any function to do so? I
found this:
https://github.com/openscad/openscad/issues/301

but I could not run them.

Thanks
 


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

Hi, Le samedi 12 août 2017 à 14:44 +1000, Michael Marx a écrit : > If you mean inside your .scad code, currently no. > There is a lot of historical discussion re this, and related > concepts. I would not hold your breath ATM. >   > The issue is that OpenSCAD mojo is around fast preview, and separate > slow render. > The F5 preview does not calculate the actual 3D geometry coordinates, > so that info is not available at run time. > Such coordinates come from a slow render calculated the exact 3D > geometry. >   > You can get that static info from the STL with programs such as > Netfabb basic. I coded an extension("probe()" wich provides bounding box information, as well as volume and center of mass. As Michael says, this feature requires a "render" of the geometry, even when previewing the geometry, which should be as fast as possible. In fact, every time your ask for a bounding box, it is exactly equivalent to calling render(). My opinion is that some features, like knowing the bounding box of some geometry (especially imported stl) is sometimes essential. This means that the wait for rendering is fully justified by the usefulness of the feature. Note that I do not suggest to automatically compute this information, but only on request, so whoever use it realize that he is going to slow down his rendering. I dont see anyone putting "render()" all over their code just to slow it down for for no reason... why should it be different with a probe() function to get geometric information? I consider that the lack of such simple geometric computation as the bounding box is a weakness of openscad, which makes a whole category of models impossible to code. As for using an outside program, this is ok when you need the information once, but openscad strength is parametrization, which is not compatible with running helper programs by hand. If there is interest, my "probe" branch is still available. Sorry for bringing back this discussion, but I did not start it :-) Sincerely, Sebastien >   > From: Discuss [mailto:discuss-bounces@lists.openscad.org] On Behalf > Of ahmad > Sent: Sat, 12 Aug 2017 14:36 > To: OpenSCAD general discussion > Subject: [OpenSCAD] getting the boundaries of a stl >   > Hi guys > > I am trying to find out the minx,miny,minz,   maxx,maxy,maxz of a stl > file( i.e. the boundaries of it). in there any function to do so? I > found this: > https://github.com/openscad/openscad/issues/301 > > but I could not run them. > > Thanks >   > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
JB
Jordan Brown
Sat, Aug 12, 2017 4:09 PM

On 8/11/2017 9:44 PM, Michael Marx wrote:

If you mean inside your .scad code, currently no.

There is a lot of historical discussion re this, and related concepts.
I would not hold your breath ATM.

The issue is that OpenSCAD mojo is around fast preview, and separate
slow render.

The F5 preview does not calculate the actual 3D geometry coordinates,
so that info is not available at run time.

Such coordinates come from a slow render calculated the exact 3D geometry.

It's not really relevant to the discussion, but if somebody could check
my mental model I'd appreciate it: my impression is that the issue is
that OpenSCAD generates a full list of the primitive objects and their
positions in space and the boolean operations to be applied to them, and
then does the boolean operations.  Because the bounding box is
dependent on the results of the boolean operations, it's not available
during the first phase when everything is placed in space.

You can get that static info from the STL with programs such as
Netfabb basic.

If all you want is to analyze an STL file, and if your STL files are
text form (as the ones coming from OpenSCAD are), you can write a
relatively simple program in almost any language to read them and
calculate the min/max values.

Here's one in awk:

BEGIN {
m = 1000000; // Make larger if your model is really large
maxx = -m;
minx = m;
maxy = -m;
miny = m;
maxz = -m;
minz = m;
}

$1 == "vertex" {
maxx = ($2>maxx ? $2 : maxx);
minx = ($2<minx ? $2 : minx);
maxy = ($3>maxy ? $3 : maxy);
miny = ($3<miny ? $3 : miny);
maxz = ($4>maxz ? $4 : maxz);
minz = ($4<minz ? $4 : minz);
}

END {
print minx,miny,minz;
print maxx,maxy,maxz;
}

On 8/11/2017 9:44 PM, Michael Marx wrote: > > If you mean inside your .scad code, currently no. > > There is a lot of historical discussion re this, and related concepts. > I would not hold your breath ATM. > > > > The issue is that OpenSCAD mojo is around fast preview, and separate > slow render. > > The F5 preview does not calculate the actual 3D geometry coordinates, > so that info is not available at run time. > > Such coordinates come from a slow render calculated the exact 3D geometry. > It's not really relevant to the discussion, but if somebody could check my mental model I'd appreciate it: my impression is that the issue is that OpenSCAD generates a full list of the primitive objects and their positions in space and the boolean operations to be applied to them, and *then* does the boolean operations. Because the bounding box is dependent on the results of the boolean operations, it's not available during the first phase when everything is placed in space. > You can get that static info from the STL with programs such as > Netfabb basic. > If all you want is to analyze an STL file, and if your STL files are text form (as the ones coming from OpenSCAD are), you can write a relatively simple program in almost any language to read them and calculate the min/max values. Here's one in awk: BEGIN { m = 1000000; // Make larger if your model is really large maxx = -m; minx = m; maxy = -m; miny = m; maxz = -m; minz = m; } $1 == "vertex" { maxx = ($2>maxx ? $2 : maxx); minx = ($2<minx ? $2 : minx); maxy = ($3>maxy ? $3 : maxy); miny = ($3<miny ? $3 : miny); maxz = ($4>maxz ? $4 : maxz); minz = ($4<minz ? $4 : minz); } END { print minx,miny,minz; print maxx,maxy,maxz; }
JD
Jerry Davis
Sat, Aug 12, 2017 9:59 PM

this works great. thanks for another tool in my arsenal!

--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Openscad developer

The most exciting phrase to hear in science - the one that heralds new
discoveries - is not "Eureka!" but "That's funny...".
- Isaac. Asimov

On Sat, Aug 12, 2017 at 9:09 AM, Jordan Brown <openscad@jordan.maileater.net

wrote:

On 8/11/2017 9:44 PM, Michael Marx wrote:

If you mean inside your .scad code, currently no.

There is a lot of historical discussion re this, and related concepts. I
would not hold your breath ATM.

The issue is that OpenSCAD mojo is around fast preview, and separate slow
render.

The F5 preview does not calculate the actual 3D geometry coordinates, so
that info is not available at run time.

Such coordinates come from a slow render calculated the exact 3D geometry.

It's not really relevant to the discussion, but if somebody could check my
mental model I'd appreciate it: my impression is that the issue is that
OpenSCAD generates a full list of the primitive objects and their positions
in space and the boolean operations to be applied to them, and then does
the boolean operations.  Because the bounding box is dependent on the
results of the boolean operations, it's not available during the first
phase when everything is placed in space.

You can get that static info from the STL with programs such as Netfabb
basic.

If all you want is to analyze an STL file, and if your STL files are text
form (as the ones coming from OpenSCAD are), you can write a relatively
simple program in almost any language to read them and calculate the
min/max values.

Here's one in awk:

BEGIN {
m = 1000000; // Make larger if your model is really large
maxx = -m;
minx = m;
maxy = -m;
miny = m;
maxz = -m;
minz = m;
}

$1 == "vertex" {
maxx = ($2>maxx ? $2 : maxx);
minx = ($2<minx ? $2 : minx);
maxy = ($3>maxy ? $3 : maxy);
miny = ($3<miny ? $3 : miny);
maxz = ($4>maxz ? $4 : maxz);
minz = ($4<minz ? $4 : minz);
}

END {
print minx,miny,minz;
print maxx,maxy,maxz;
}


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

this works great. thanks for another tool in my arsenal! -- Extra Ham Operator: K7AZJ Registered Linux User: 275424 Raspberry Pi and Openscad developer *The most exciting phrase to hear in science - the one that heralds new discoveries - is not "Eureka!" but "That's funny...".*- Isaac. Asimov On Sat, Aug 12, 2017 at 9:09 AM, Jordan Brown <openscad@jordan.maileater.net > wrote: > On 8/11/2017 9:44 PM, Michael Marx wrote: > > If you mean inside your .scad code, currently no. > > There is a lot of historical discussion re this, and related concepts. I > would not hold your breath ATM. > > > > The issue is that OpenSCAD mojo is around fast preview, and separate slow > render. > > The F5 preview does not calculate the actual 3D geometry coordinates, so > that info is not available at run time. > > Such coordinates come from a slow render calculated the exact 3D geometry. > > > It's not really relevant to the discussion, but if somebody could check my > mental model I'd appreciate it: my impression is that the issue is that > OpenSCAD generates a full list of the primitive objects and their positions > in space and the boolean operations to be applied to them, and *then* does > the boolean operations. Because the bounding box is dependent on the > results of the boolean operations, it's not available during the first > phase when everything is placed in space. > > You can get that static info from the STL with programs such as Netfabb > basic. > > > If all you want is to analyze an STL file, and if your STL files are text > form (as the ones coming from OpenSCAD are), you can write a relatively > simple program in almost any language to read them and calculate the > min/max values. > > Here's one in awk: > > BEGIN { > m = 1000000; // Make larger if your model is really large > maxx = -m; > minx = m; > maxy = -m; > miny = m; > maxz = -m; > minz = m; > } > > $1 == "vertex" { > maxx = ($2>maxx ? $2 : maxx); > minx = ($2<minx ? $2 : minx); > maxy = ($3>maxy ? $3 : maxy); > miny = ($3<miny ? $3 : miny); > maxz = ($4>maxz ? $4 : maxz); > minz = ($4<minz ? $4 : minz); > } > > END { > print minx,miny,minz; > print maxx,maxy,maxz; > } > > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
CA
Carsten Arnholm
Sun, Aug 13, 2017 10:42 AM

On 12. aug. 2017 18:09, Jordan Brown wrote:

It's not really relevant to the discussion, but if somebody could check
my mental model I'd appreciate it: my impression is that the issue is
that OpenSCAD generates a full list of the primitive objects and their
positions in space and the boolean operations to be applied to them, and
then does the boolean operations.  Because the bounding box is
dependent on the results of the boolean operations, it's not available
during the first phase when everything is placed in space.

I think your mental model is correct. Your last sentence describes how
OpenSCAD works, but it is more a reflection of the design choices than
what is theoretically possible (ref. below).

a) it is possible to compute the final bounding box without performing
mesh boolean operations, but that is not how OpenSCAD does it.
b) you also need a way to query/use such computed information, and that
is not possible in a functional language.

Therefore, your best option is to export to STL (or other format) and
use other software to compute the bounding box from the file coordinates.

However, to illustrate that these things are not fundamental, but result
from software design choices, consider a trivial OpenSCAD example:

module main_shape()
{
cylinder(h=100,r=10);
translate([0,0,100])cube(50,center=true);
}
rotate([0,30,0])  main_shape();

To obtain the bounding box for the resulting solid object, one must
export to file as discussed.

I had similar needs to obtain bounding box information and therefore
implemented it in my own application (based on the AngelScript language)
where the a) and b) restrictions do not apply. The bounding boxes are
directly available for any solid, primitive or compound, and they can be
queried. The trivial example restated in AngelCAD:

shape@ main_shape()
{
solid@ cyl  = cylinder(h:100,r:10);
solid@ cub  = translate(0,0,100)cube(50,center:true);
solid@ thing = rotate_y(deg:30)
(cyl + cub);
return print_box(thing);
}

solid@ print_box(solid@ body)
{
boundingbox@ box = body.box();
pos3d@ p1 = box.p1();
pos3d@ p2 = box.p2();
cout << "boundingbox: ";
cout << "x=[" << p1.x() << "," << p2.x() << "]  ";
cout << "y=[" << p1.y() << "," << p2.y() << "]  ";
cout << "z=[" << p1.z() << "," << p2.z() << "]  " << endl();
return body;
}

The script output is

boundingbox: x=[-21.6506,84.1506]  y=[-25,25]  z=[-12.5,120.753]

Note the bounding boxes are computed without performing any boolean
operations on mesh level (mesh booleans are done in a separate
application later, https://github.com/arnholm/xcsg ).

In summary, your mental model is correct given the OpenSCAD design choices.

Carsten Arnholm

On 12. aug. 2017 18:09, Jordan Brown wrote: > It's not really relevant to the discussion, but if somebody could check > my mental model I'd appreciate it: my impression is that the issue is > that OpenSCAD generates a full list of the primitive objects and their > positions in space and the boolean operations to be applied to them, and > *then* does the boolean operations. Because the bounding box is > dependent on the results of the boolean operations, it's not available > during the first phase when everything is placed in space. I think your mental model is correct. Your last sentence describes how OpenSCAD works, but it is more a reflection of the design choices than what is theoretically possible (ref. below). a) it is possible to compute the final bounding box without performing mesh boolean operations, but that is not how OpenSCAD does it. b) you also need a way to query/use such computed information, and that is not possible in a functional language. Therefore, your best option is to export to STL (or other format) and use other software to compute the bounding box from the file coordinates. However, to illustrate that these things are not fundamental, but result from software design choices, consider a trivial OpenSCAD example: module main_shape() { cylinder(h=100,r=10); translate([0,0,100])cube(50,center=true); } rotate([0,30,0]) main_shape(); To obtain the bounding box for the resulting solid object, one must export to file as discussed. I had similar needs to obtain bounding box information and therefore implemented it in my own application (based on the AngelScript language) where the a) and b) restrictions do not apply. The bounding boxes are directly available for any solid, primitive or compound, and they can be queried. The trivial example restated in AngelCAD: shape@ main_shape() { solid@ cyl = cylinder(h:100,r:10); solid@ cub = translate(0,0,100)*cube(50,center:true); solid@ thing = rotate_y(deg:30)*(cyl + cub); return print_box(thing); } solid@ print_box(solid@ body) { boundingbox@ box = body.box(); pos3d@ p1 = box.p1(); pos3d@ p2 = box.p2(); cout << "boundingbox: "; cout << "x=[" << p1.x() << "," << p2.x() << "] "; cout << "y=[" << p1.y() << "," << p2.y() << "] "; cout << "z=[" << p1.z() << "," << p2.z() << "] " << endl(); return body; } The script output is boundingbox: x=[-21.6506,84.1506] y=[-25,25] z=[-12.5,120.753] Note the bounding boxes are computed without performing any boolean operations on mesh level (mesh booleans are done in a separate application later, https://github.com/arnholm/xcsg ). In summary, your mental model is correct given the OpenSCAD design choices. Carsten Arnholm
NH
nop head
Sun, Aug 13, 2017 10:50 AM

How do you calculate the bounding box of a difference without calculating
the mesh?

On 13 August 2017 at 11:42, Carsten Arnholm arnholm@arnholm.org wrote:

On 12. aug. 2017 18:09, Jordan Brown wrote:

It's not really relevant to the discussion, but if somebody could check
my mental model I'd appreciate it: my impression is that the issue is that
OpenSCAD generates a full list of the primitive objects and their positions
in space and the boolean operations to be applied to them, and then does
the boolean operations.  Because the bounding box is dependent on the
results of the boolean operations, it's not available during the first
phase when everything is placed in space.

I think your mental model is correct. Your last sentence describes how
OpenSCAD works, but it is more a reflection of the design choices than what
is theoretically possible (ref. below).

a) it is possible to compute the final bounding box without performing
mesh boolean operations, but that is not how OpenSCAD does it.
b) you also need a way to query/use such computed information, and that is
not possible in a functional language.

Therefore, your best option is to export to STL (or other format) and use
other software to compute the bounding box from the file coordinates.

However, to illustrate that these things are not fundamental, but result
from software design choices, consider a trivial OpenSCAD example:

module main_shape()
{
cylinder(h=100,r=10);
translate([0,0,100])cube(50,center=true);
}
rotate([0,30,0])  main_shape();

To obtain the bounding box for the resulting solid object, one must export
to file as discussed.

I had similar needs to obtain bounding box information and therefore
implemented it in my own application (based on the AngelScript language)
where the a) and b) restrictions do not apply. The bounding boxes are
directly available for any solid, primitive or compound, and they can be
queried. The trivial example restated in AngelCAD:

shape@ main_shape()
{
solid@ cyl  = cylinder(h:100,r:10);
solid@ cub  = translate(0,0,100)cube(50,center:true);
solid@ thing = rotate_y(deg:30)
(cyl + cub);
return print_box(thing);
}

solid@ print_box(solid@ body)
{
boundingbox@ box = body.box();
pos3d@ p1 = box.p1();
pos3d@ p2 = box.p2();
cout << "boundingbox: ";
cout << "x=[" << p1.x() << "," << p2.x() << "]  ";
cout << "y=[" << p1.y() << "," << p2.y() << "]  ";
cout << "z=[" << p1.z() << "," << p2.z() << "]  " << endl();
return body;
}

The script output is

boundingbox: x=[-21.6506,84.1506]  y=[-25,25]  z=[-12.5,120.753]

Note the bounding boxes are computed without performing any boolean
operations on mesh level (mesh booleans are done in a separate application
later, https://github.com/arnholm/xcsg ).

In summary, your mental model is correct given the OpenSCAD design choices.

Carsten Arnholm


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

How do you calculate the bounding box of a difference without calculating the mesh? On 13 August 2017 at 11:42, Carsten Arnholm <arnholm@arnholm.org> wrote: > On 12. aug. 2017 18:09, Jordan Brown wrote: > >> It's not really relevant to the discussion, but if somebody could check >> my mental model I'd appreciate it: my impression is that the issue is that >> OpenSCAD generates a full list of the primitive objects and their positions >> in space and the boolean operations to be applied to them, and *then* does >> the boolean operations. Because the bounding box is dependent on the >> results of the boolean operations, it's not available during the first >> phase when everything is placed in space. >> > > I think your mental model is correct. Your last sentence describes how > OpenSCAD works, but it is more a reflection of the design choices than what > is theoretically possible (ref. below). > > a) it is possible to compute the final bounding box without performing > mesh boolean operations, but that is not how OpenSCAD does it. > b) you also need a way to query/use such computed information, and that is > not possible in a functional language. > > Therefore, your best option is to export to STL (or other format) and use > other software to compute the bounding box from the file coordinates. > > However, to illustrate that these things are not fundamental, but result > from software design choices, consider a trivial OpenSCAD example: > > module main_shape() > { > cylinder(h=100,r=10); > translate([0,0,100])cube(50,center=true); > } > rotate([0,30,0]) main_shape(); > > To obtain the bounding box for the resulting solid object, one must export > to file as discussed. > > I had similar needs to obtain bounding box information and therefore > implemented it in my own application (based on the AngelScript language) > where the a) and b) restrictions do not apply. The bounding boxes are > directly available for any solid, primitive or compound, and they can be > queried. The trivial example restated in AngelCAD: > > shape@ main_shape() > { > solid@ cyl = cylinder(h:100,r:10); > solid@ cub = translate(0,0,100)*cube(50,center:true); > solid@ thing = rotate_y(deg:30)*(cyl + cub); > return print_box(thing); > } > > solid@ print_box(solid@ body) > { > boundingbox@ box = body.box(); > pos3d@ p1 = box.p1(); > pos3d@ p2 = box.p2(); > cout << "boundingbox: "; > cout << "x=[" << p1.x() << "," << p2.x() << "] "; > cout << "y=[" << p1.y() << "," << p2.y() << "] "; > cout << "z=[" << p1.z() << "," << p2.z() << "] " << endl(); > return body; > } > > The script output is > > boundingbox: x=[-21.6506,84.1506] y=[-25,25] z=[-12.5,120.753] > > Note the bounding boxes are computed without performing any boolean > operations on mesh level (mesh booleans are done in a separate application > later, https://github.com/arnholm/xcsg ). > > In summary, your mental model is correct given the OpenSCAD design choices. > > Carsten Arnholm > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
CA
Carsten Arnholm
Sun, Aug 13, 2017 12:26 PM

On 13. aug. 2017 12:50, nop head wrote:

How do you calculate the bounding box of a difference without
calculating the mesh?

By computing the difference between the bounding boxes of the input objects.

It means you need a way to compute union, intersection and difference
for bounding boxes, i.e. a mini boolean engine for bounding boxes only.

It should be said that in some cases, this approach can overestimate the
volume of the resulting bounding box, compared to computing it from the
mesh, but it is guaranteed to be large enough.

Carsten Arnholm

On 13. aug. 2017 12:50, nop head wrote: > How do you calculate the bounding box of a difference without > calculating the mesh? By computing the difference between the bounding boxes of the input objects. It means you need a way to compute union, intersection and difference for bounding boxes, i.e. a mini boolean engine for bounding boxes only. It should be said that in some cases, this approach can overestimate the volume of the resulting bounding box, compared to computing it from the mesh, but it is guaranteed to be large enough. Carsten Arnholm