Calculating a volume of a custom mesh using mesh.volume() doesn't work properly
See original GitHub issueHi, I’m currently trying to build tubes and tubelike meshes, that might branch, etc. (I’m aware that there is a Tube shape in the Vedo library).
I want to cut them and cap them at the places where they have opened up after cutting.
Additionally, I would like to calculate the total volume enclosed by the mesh before and after the procedure.
Here’s an example below:
from vedo import *
import math
r = 1
coord_start_z = 0
coord_end_z = 1
angle = 0
number_of_vertices = 520
start_x = 0
start_y = 0
coordinates_all = []
for i in range(0,number_of_vertices):
angle = (i/number_of_vertices)*2*3.141592653589793
coord_x = start_x + r * math.cos(angle)
coord_y = start_y + r * math.sin(angle)
coordinates_all.append((coord_x,coord_y,coord_start_z))
coordinates_all.append((coord_x,coord_y,coord_end_z))
faces = []
faces_base_start = [i for i in range(0,number_of_vertices*2) if i%2 == 0]
faces_base_end = [i for i in range(0,number_of_vertices*2) if i%2 != 0]
for i in range(0,number_of_vertices):
faces_start = []
if i + 1 == number_of_vertices:
faces.append((i*2,i*2+1,1,0))
else:
faces.append((i*2,i*2+1,i*2+3,i*2+2))
faces.append(tuple(faces_base_start))
faces.append(tuple(faces_base_end))
tube = Mesh([coordinates_all,faces])
cut_tube = tube.clone().cutWithPlane(origin=(0, 0, 0), normal=(1, 0, 0))
capped_cut_tube = cut_tube.clone().cap()
capped_cut_tube.c('r',alpha=0.5)
print('Volume of the original tube is: ' + str(tube.volume()))
print('Volume of the cut and capped tube is: ' + str(capped_cut_tube.volume()))
show(tube,axes=1,at=0,shape=(2,1))
show(capped_cut_tube,axes=1,at=1,shape=(2,1))
Unfortunately, the volume of the first tube is computed as 0 (it should be around 3.141592) and the second one is incorrectly calculated as well (0.8742, even though the volume is roughly halved by the split).
What could be the issue here?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Calculating the volume of a closed custom mesh?
Iterate over all triangles. Take the face consisting of these 3 vertices and connect it with the apex to form a pyramid. Calculate...
Read more >Calculating the volume of a mesh – Nervous System blog
The idea behind calculating the volume of a mesh is to calculate a volume for each triangle of the mesh and add them...
Read more >How would one calculate a 3d Mesh volume in Unity?
I am not quite sure what you are looking to do, this seems to calculate the volume of a mesh (cubic units), was...
Read more >How calculate a volume of this mesh 3D? - Stack Overflow
In Meshlab: Try the poisson option under point set; Or use i.e. Blender to close the volume manually. Once this is done, it...
Read more >Calculating volume of clipped 3D mesh · Issue #71 - GitHub
The volume calculation of the clipped mesh is incorrect because it is not a closed surface while the input cylinder is a completely...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks!
I actually did not think of the possibility to
sweep
a line to create tubes:But probably the second solution is what you are after (but this one can become very memory-consuming for large networks: