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
- SG: The solid geometry object to be analyzed.
- sz: The step size in the z-direction for slicing the solid. The default value is 1 if not provided.
Output Results
- VSUM: The estimated volume of the solid in cubic centimeters (cm³).
- A: The area of the individual slices.
Algorithm Steps
- Initialize the step size
sz
to pi/3
. If a step size is provided as an argument, use that value instead.
- Set a small offset
r
to avoid integer numbers, which is 0.001234567890
.
- Calculate the bounding box of the solid geometry using
BBofVL(SG.VL)
to determine the maximum height.
- Adjust the step size
sz
to ensure an integer number of steps between the minimum and maximum z-values of the bounding box.
- Create a vector
h
that contains the z-values at which the solid will be sliced.
- If no output is expected, initialize a 3D plot for visualization.
- Initialize a vector
V
to store the area of each slice.
- Loop over each z-value in
h
:
- For the last slice, adjust the offset
r
to -r
.
- Use
CPLofSGslice2
to get the cross-sectional area at the current z-value plus the offset r
.
- Store the area of the slice in the vector
V
.
- If no output is expected, plot the slice for visualization.
- Calculate the total volume
VSUM
by summing the areas of the slices, using the trapezoidal rule, and convert the result to cubic centimeters.
- 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