Volume calculator

 From:  Max Smirnov (SMIRNOV)
7421.7 
This script can approximately calculate a volume of selected solid object (I told about it in this thread: http://moi3d.com/forum/index.php?webtag=MOI&msg=3746.7 ).
It can't calculate volume exactly, because it doesn't use any mathematical method (as Michael said above, it's very difficult task).
This script just creates a grid of lines and cut them with surface of the solid object.

Anyway it works :)
I used this object to test the script.


I use it because we can calculate exact volume of this shape:
Box (20x20x5) - Box (12x12x3) + Half sphere (R=5) - Cylinder(R=3,h=5) =
20*20*5 - 12*12*3 + 4*Pi*5*5*5/6 - Pi*3*3*5 = 1688,4277183876

And now script results:
Grid density: 10, time: 0.1s, result: 1570,999037, accuracy: >92%
Grid density: 50, time: 0.6s, result: 1659,717703, accuracy: >98%
Grid density: 100, time: 1.7s, result: 1686,79025, accuracy: >99.9%
Grid density: 300, time: 14.8s, result: 1688,279379, accuracy: >99.99%

Good enough! :)

Default value of the grid density is 100. You can set other values as command line parameters. Example: _CalcVolume 150
To increase performance I put all code in htm file. Be careful, this script can really hang up MoI. Don't set density values more than 300-350.

EDITED: 7 Mar 2022 by SMIRNOV