SGvolume

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Analytical Geometry
Introduced first in SolidGeometry 2.8, Creation date: 2016-01-10, Last change: 2025-09-14

returns the estimated volume of a solid

Description

In contrast to SGweight, this function slices the solid. It uses function CPLofSGslice2

See Also: SGweight , VMofSG , CPLofSGslice2 , SGseparate , CPLofSGslice

Example Illustration

 missing image of SGvolume(SG,sz)

Syntax

[VSUM,A]=SGvolume(SG,[sz])

Input Parameter

SG: Solid Geoemtry
sz: step size in z; default is 1

Output Parameter

VSUM: Volume in cm^3
A: Area of the individual slices




Copyright 2016-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This function estimates the volume of a solid geometry (SG) by slicing it and calculating the area of each slice. It uses the function CPLofSGslice2 to obtain the cross-sectional area of each slice.

Input Parameters

Output Results

Algorithm Steps

  1. Initialize the step size sz to pi/3. If a step size is provided as an argument, use that value instead.
  2. Set a small offset r to avoid integer numbers, which is 0.001234567890.
  3. Calculate the bounding box of the solid geometry using BBofVL(SG.VL) to determine the maximum height.
  4. Adjust the step size sz to ensure an integer number of steps between the minimum and maximum z-values of the bounding box.
  5. Create a vector h that contains the z-values at which the solid will be sliced.
  6. If no output is expected, initialize a 3D plot for visualization.
  7. Initialize a vector V to store the area of each slice.
  8. Loop over each z-value in h:
  9. Calculate the total volume VSUM by summing the areas of the slices, using the trapezoidal rule, and convert the result to cubic centimeters.
  10. Return the total volume VSUM and the vector of slice areas A.
Algorithm explaination created using ChatGPT on 2025-08-19 07:01. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21