openscad icon indicating copy to clipboard operation
openscad copied to clipboard

Feature request: Compute area and volume

Open hydrodog opened this issue 12 years ago • 30 comments

Adding computation of area and volume of objects would make OpenSCAD quite useful in exploring geometry of solid shapes in a math class. I've had quite a few math teachers I showed OpenSCAD to request this feature, so I'm relaying it.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

hydrodog avatar Jul 09 '13 15:07 hydrodog

+1

adius avatar Jun 02 '14 05:06 adius

If you want to use the bounds analytically to create further geometry, we need a bridge/feedback from the geometry engine to the language evaluator. I'm thinking about ways of doing this, but it requires a fair bit of refactoring. Also, it's really only useful if we can optimize 3D CSG operations with at an order of magnitude or two.

In any case, use-cases for such a feature are welcome!

kintel avatar Jun 02 '14 06:06 kintel

As a short-term solution, could the sum of areas or volumes be calculated and reported in the Render (F6) run Console results?

clothbot avatar Dec 29 '14 20:12 clothbot

Actually, as it relates to 2D a "sum of contour perimeters" would also be useful for laser cutting time estimates.

clothbot avatar Dec 29 '14 20:12 clothbot

We've been discussing the possibility of including admesh. That could potentially give us the volume calculation for free.

kintel avatar Dec 30 '14 00:12 kintel

Potential Use-Case: I am currently trying to make an sliding measuring spoon (Example: http://www.bedbathandbeyond.com/store/product/adjust-a-spoon-reg-tablespoon-measuring-spoon-system/1012971893 ), but I'd like to make it parametric, so having a volume() or similar would be very useful and save me quite a lot of math.

devyntk avatar Jun 22 '15 22:06 devyntk

@bkeeneykid could you explain a little bit more how that would be integrated into the model? The way I'm currently thinking about that would create a feedback loop from the volume() result back into the dimension for the model part where volume() is applied to (a bit like circular references in Excel).

t-paul avatar Jun 23 '15 07:06 t-paul

The goal of this would be to measure things in teaspoons, and a mm squared to teaspoons is quite simple. The goal would be to make it quite round and approachable, but the math involved to make it quite hard to code. Having a volume() of the rounded area could make my life much easier?

devyntk avatar Jun 23 '15 16:06 devyntk

Math has all the answers. Dont wait for OpenSCAD to change, learning math is faster.

Just formulate your problem precisely and someone on this list will come up with the code to do it.

2015-06-23 18:11 GMT+02:00 bkeeneykid [email protected]:

The goal of this would be to measure things in teaspoons, and a mm squared to teaspoons is quite simple. The goal would be to make it quite round and approachable, but the math involved to make it quite hard to code. Having a volume() of the rounded area could make my life much easier?

— Reply to this email directly or view it on GitHub https://github.com/openscad/openscad/issues/433#issuecomment-114559618.

[email protected] [email protected]

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist: Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben. Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy: I am currently trying short replies instead of no replies at all. Please let me know, if you like to read more.

Enjoy!

TakeItAndRun avatar Jun 23 '15 17:06 TakeItAndRun

Yes, I would love to do it myself, and I’ve tried working it out on paper, but if I want to use, for example, a Minkowski statement to easily round everything, It would take quite a bit to work that out for complex shapes. I maybe don’t need it for this project, but I can see it being useful, especially for kitchen appliances.

On Jun 23, 2015, at 12:25 PM, TakeItAndRun [email protected] wrote:

Math has all the answers. Dont wait for OpenSCAD to change, learning math is faster.

Just formulate your problem precisely and someone on this list will come up with the code to do it.

2015-06-23 18:11 GMT+02:00 bkeeneykid [email protected]:

The goal of this would be to measure things in teaspoons, and a mm squared to teaspoons is quite simple. The goal would be to make it quite round and approachable, but the math involved to make it quite hard to code. Having a volume() of the rounded area could make my life much easier?

— Reply to this email directly or view it on GitHub https://github.com/openscad/openscad/issues/433#issuecomment-114559618.

[email protected] [email protected]

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist: Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben. Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy: I am currently trying short replies instead of no replies at all. Please let me know, if you like to read more.

Enjoy! — Reply to this email directly or view it on GitHub https://github.com/openscad/openscad/issues/433#issuecomment-114578481.

devyntk avatar Jun 23 '15 17:06 devyntk

Here is a simple shape for the inside of the spoon. And it volume is just the addition of some cubes, cylinders, and spheres.

r=5; h=15; w=30; l=60; $fn=16;

hull() for(i=[0,l-2_r]) translate([0,i,0]) for(m=[1,-1]) translate([m_(w/2-r),0,-h+r]){ sphere(r); cylinder(h-r,r,r); }

2015-06-23 19:27 GMT+02:00 bkeeneykid [email protected]:

Yes, I would love to do it myself, and I’ve tried working it out on paper, but if I want to use, for example, a Minkowski statement to easily round everything, It would take quite a bit to work that out for complex shapes. I maybe don’t need it for this project, but I can see it being useful, especially for kitchen appliances.

On Jun 23, 2015, at 12:25 PM, TakeItAndRun [email protected] wrote:

Math has all the answers. Dont wait for OpenSCAD to change, learning math is faster.

Just formulate your problem precisely and someone on this list will come up with the code to do it.

2015-06-23 18:11 GMT+02:00 bkeeneykid [email protected]:

The goal of this would be to measure things in teaspoons, and a mm squared to teaspoons is quite simple. The goal would be to make it quite round and approachable, but the math involved to make it quite hard to code. Having a volume() of the rounded area could make my life much easier?

— Reply to this email directly or view it on GitHub < https://github.com/openscad/openscad/issues/433#issuecomment-114559618>.

[email protected] [email protected]

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist: Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben. Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy: I am currently trying short replies instead of no replies at all. Please let me know, if you like to read more.

Enjoy! — Reply to this email directly or view it on GitHub < https://github.com/openscad/openscad/issues/433#issuecomment-114578481>.

— Reply to this email directly or view it on GitHub https://github.com/openscad/openscad/issues/433#issuecomment-114579602.

[email protected] [email protected]

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist: Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben. Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy: I am currently trying short replies instead of no replies at all. Please let me know, if you like to read more.

Enjoy!

TakeItAndRun avatar Jun 23 '15 17:06 TakeItAndRun

Use case: I would love to get a bounding box from a geometry. Imagine a "box" tool for a laser cutter: the user enters the size of a box, OpenSCAD calculates six sides and projects them onto the X/Y axis so that they can be laser-cut. Knowing the bounding box of the parts would make it easy to arrange them programmatically for the laser cutter.

I know, a bounding box for a rectangle is simple, but this should not be limited to boxes.

MatthiasWM avatar Aug 10 '15 16:08 MatthiasWM

Use Case: Calculating displacement volumes for a sailing vessel as it heels, intersecting hull with a cube representing the waterline. Centre of mass and moment of inertia would also be very useful. Work around might be doing a series of sections and integrating using an external script. I'm a newish user and I don't know how many other people are thinking of using OpenSCAD for stuff other than 3D printing - to me I'm very interested in using it for design optimisation using external code, and being able to extract these details would be key.

robinhilliard avatar Mar 18 '17 07:03 robinhilliard

I, too, would love to get a volume function in there, as a step towards density calculations for balancing parts. I've got a BB8 robot design, and it would be excellent if I could balance him in openscad before printing.

paenian avatar Mar 31 '17 16:03 paenian

I did add a volume$() operation to rapcad, its a very naive implementation so its slow but it works. It also optionally prints out the centre of mass https://github.com/GilesBathgate/RapCAD/blob/master/src/cgalexplorer.cpp#L311

GilesBathgate avatar Mar 31 '17 16:03 GilesBathgate

+1, now in Late September 2018. This is " just math" filling the interior of the volume with tetrahedra with one triangular face outside and a common point inside. http://mathworld.wolfram.com/Tetrahedron.html

Specifying the tetrahedron by the three polyhedron edge vectors a, b, and c from a given polyhedron vertex, the volume is

V=1/(3!)|a·(bxc)|.

MangoCats avatar Sep 22 '18 16:09 MangoCats

Use case: Creating moulds for silicon. I want to know how much filament I need to print the mould and how much silicon I need to fill it.

(Answers advocating doing maths are not helpful.)

celesteh avatar Mar 25 '19 19:03 celesteh

I used NetFabb Studio to calculate the volume of my mould when I had exactly that use case. I then printed tiny measuring cups to mix exactly the right amount +10%.

nophead avatar Mar 25 '19 22:03 nophead

I'd love to see this, plus center of mass if it's easy. my current "workaround" is to export my model or piece of a model as an STL and then either pull it into another software (most 3D printing software) or take advantage of python's numpy-stl to get the info I need. This gets clumsy for multi-part multi-material models though (export each component, find the volume individually, include density manually for each component). having this within openscad would be great.

tpchuckles avatar Jul 13 '19 21:07 tpchuckles

image

GilesBathgate avatar Jul 14 '19 08:07 GilesBathgate

I suspect that the geometry returned by the render() function in #4478 can be used to calculate the volume of the model.

jordanbrown0 avatar Nov 18 '23 17:11 jordanbrown0

Note that manifold does support area and volume, but I am not entirely sure how precise the volume calculation is. It would be great if we can check against the output from CGAL with exact calculation.

pca006132 avatar Nov 20 '23 11:11 pca006132

I think this is easier then calculating a determinant of a 4x4 matrix:

for each of the triangles given with p1,p2,p3 sum up:

+p1[0]*p2[1]*p3[2] +p1[1]*p2[2]*p3[0] +p1[2]*p2[0]*p3[1] -p1[2]*p2[1]*p3[0] -p1[0]*p2[2]*p3[1] -p1[1]*p2[0]*p3[2]

and divide the result by 18

In any case I believe that displaying the numbers nicely in openscad is most effort here.

On Mon, Nov 20, 2023 at 12:08 PM Chun Kit LAM @.***> wrote:

Note that manifold does support area and volume, but I am not entirely sure how precise the volume calculation is. It would be great if we can check against the output from CGAL with exact calculation.

— Reply to this email directly, view it on GitHub https://github.com/openscad/openscad/issues/433#issuecomment-1818842015, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACCO4MQB4XSD3QIB6U7KIFDYFM24DAVCNFSM4AGM7LL2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBRHA4DIMRQGE2Q . You are receiving this because you are subscribed to this thread.Message ID: @.***>

gsohler avatar Nov 20 '23 12:11 gsohler

As minimal version it could be just added to the already existing (configurable) render summary in the console window:

Top level object is a 3D object:
   Facets:       2188
Bounding box:
   Min:  -34.00, -9.95, -9.95
   Max:  31.50, 9.95, 9.95
   Size: 65.50, 19.89, 19.89
Camera:
   Translation: 0.00, 0.00, 0.00
   Rotation:    55.00, 0.00, 25.00
   Distance:    140.00
   FOV:         22.50
Rendering finished.
Top level object is a 2D object:
   Contours:        4
Bounding box:
   Min:  -34.00, -9.95
   Max:  31.50, 9.95
   Size: 65.50, 19.89
Measurements:
   Area: 626.14
Camera:
   Translation: 0.00, 0.00, 0.00
   Rotation:    55.00, 0.00, 25.00
   Distance:    140.00
   FOV:         22.50
Rendering finished.

t-paul avatar Nov 20 '23 12:11 t-paul

@t-paul You could also have it work as the `Echo' module does, (that's how I do it in RapCAD., see screenshot above)

GilesBathgate avatar Nov 20 '23 12:11 GilesBathgate

When looking at designs like this:

https://www.thingiverse.com/thing:2676324

it might be fortunate to have a function which can calculate arbitrary characteristics of the design/ or sub parts (not only surface and volume, also gravity center are possible)

Users could individually echo() volume of subparts of the design.

On Mon, Nov 20, 2023 at 1:24 PM Giles Bathgate @.***> wrote:

@t-paul https://github.com/t-paul You could also have it work as the `Echo' module does, (that's how I do it in RapCAD., see screenshot above)

— Reply to this email directly, view it on GitHub https://github.com/openscad/openscad/issues/433#issuecomment-1818968089, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACCO4MXVXRXCKF5YQGMOEV3YFNDWZAVCNFSM4AGM7LL2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBRHA4TMOBQHA4Q . You are receiving this because you commented.Message ID: @.***>

gsohler avatar Nov 20 '23 12:11 gsohler

@gsohler I have a number of these 'auxiliary modules' : bound$() radial$() volume$(), they all echo themselves (because making them return values is more complex) They also render onto the model non-exportable line art, and text in blue, which you can also make out in the screenshot.

GilesBathgate avatar Nov 20 '23 12:11 GilesBathgate

yes!!!

https://imgpile.com/i/Gfuwto

openscad has it integrated

On Mon, Nov 20, 2023 at 1:43 PM Giles Bathgate @.***> wrote:

@gsohler https://github.com/gsohler I have a number of these 'auxiliary modules' : bound$() radial$() volume$(), they all echo themselves (because making them return values is more complex) They also render onto the model non-exportable line art, and text in blue, which you can also make out in the screenshot.

— Reply to this email directly, view it on GitHub https://github.com/openscad/openscad/issues/433#issuecomment-1818995902, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACCO4MVGYILPLZABPV2SQ63YFNF6BAVCNFSM4AGM7LL2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBRHA4TSNJZGAZA . You are receiving this because you were mentioned.Message ID: @.***>

gsohler avatar Nov 20 '23 14:11 gsohler

https://imgpile.com/i/Gfuwto openscad has it integrated

Hmm, I don't see this feature, is there an official/recommended way to output metrics such as volume? Thank you :)

CarlosGS avatar Jun 20 '24 14:06 CarlosGS

Hi Carlos,

I have it in my openscad code, but i just realized that it just works if the Topmost Geomery node is a PolySet. it does not work with Manifold nodes. I feel I should improve there

On Thu, Jun 20, 2024 at 4:15 PM Carlos García-Saura < @.***> wrote:

https://imgpile.com/i/Gfuwto openscad has it integrated

Hmm, I don't see this feature, is there an official/recommended way to output metrics such as volume? Thank you :)

— Reply to this email directly, view it on GitHub https://github.com/openscad/openscad/issues/433#issuecomment-2180820437, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACCO4MQZOVUC24BGTEUEA3LZILPZPAVCNFSM6AAAAABJUCAPCWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBQHAZDANBTG4 . You are receiving this because you were mentioned.Message ID: @.***>

gsohler avatar Jun 20 '24 14:06 gsohler