1

I'm obviously referencing to this question as I already calculate the volume of a 3D mesh and works flawlessly: How to calculate the volume of a 3D mesh object the surface of which is made up triangles

Just to recap, I have a mesh made of triangles, all in the proper order, and above zero.

Since this is for sending to 3d printing, I want to calculate how much support volume is going to be needed for the printing. For example, the red volume:

Illustration

Additionally, some printers with some materials can actually print some surfaces minimally slanted, meaning that the volume under that surface need not to be included.

I feel I could do this generating volumes under the surfaces and merging them, but when a model exceeds the millions of polygons I expect any JavaScript engine will implode under the effort.

EDIT:

For reference, I want to calculate the volume in red in the above image.

Remember that meshes can have any shape and have no restrictions (other than being sealed and having no overlapping parts)

Community
  • 1
  • 1
Blue Ion
  • 53
  • 3
  • 8
  • 1
    I'm not quite sure what you're asking. Do you have a surface and need to calculate the volume above the base? Why not just make the base a part of the surface and use the linked solution? – Teepeemm Feb 15 '14 at 01:06
  • Because it is not just a simple surface, like a terrain or the ceiling of a cave, check the image of my edit for an example. It can be any type of mesh. – Blue Ion Feb 15 '14 at 10:27
  • You're still not quite clear. You have a triangular mesh that defines the grey volume, and you want to figure out the red volume? Is that what you're looking for? – Teepeemm Feb 15 '14 at 18:48
  • Yes, that is correct. I'm going to put another picture to help explain things better. But I guess there is no simple mathematical method out there that I might have missed. – Blue Ion Feb 17 '14 at 19:05
  • @BlueIon: Did you ever find an efficient solution to this? e.g. one based on the signed volume technique? – Adi Shavit Nov 05 '15 at 11:54
  • @Adi Shavit: Sadly I didn't try MvG proposal. Looks sound, though Javascript may choke with it. However, since I had to stop the project for which I had to use that functionality, I never got around to implement it, which is why I hadn't accepted the solution, I don't know if it really works. – Blue Ion Dec 23 '15 at 13:17

1 Answers1

0

Rewritten answer, didn't understand the question correctly the first time around.

Your goal should be to divide the plane into polygons in such a way that above each polygon, there is a constant number of surfaces, i.e. at every point within a polygon, a vertical ray will intersect the same number of triangles. Then you can simply alternate between “hole” and “solid”, and in that way sum up the holes. In order to obtain this division of the plane, look at “vertical” parts of the mesh. On the one hand, this includes triangles which are actually vertical. On the other hand, this also includes edges between triangles if the normal of one triangle is below horizontal and the other above.

So I'd suggest the following approach:

  1. Identify all “vertical” components of the mesh, and project them into the ground plane.
  2. Combine these line segments to obtain a partition of the plane into polygons.
  3. Iterate over all triangles and assign each to one of these polygons. Polygons at the boundary between polygons will be divided into several triangles.
  4. For the triangles of each polygon of the partition, identify the different layers. This can be done by simply following adjacency between triangles, with the exception of vertical components.
  5. Order the layers for each polygon, e.g. by intersecting a single ray with them. Then compute volumnes between layers and the ground layer using the shoelace formula you already referenced.
  6. Compute the correct sums and differences: the first layer is positive, the second negative, and so on, up to the last layer which does not count at all. Do so for all polygons, and sum the results. Edit: Thinking about it, triangle orientations will already take care of the alternating signs, so disregarding the top layer is the crucial point here.

I don't have any ready ideas for dealing with the slightly slanted scenarios you mention. Looking at the holes found by the above might help. You can combine them accross boundaries of the partition, then investigate them one at a time to see whether they can be made any smaller.


Edit: After some more thought, I realized that since you only have to disregard the topmost layer, you could also tackle this aspect from a different angle: Iterate over all triangles in order of decreasing height (of any vertex, or sume of three vertices, or whatever; details don't matter if the mesh doesn't intersect itself). While iterating, maintain a 2d idea of what areas above ground are already below some triangle. You might represent this as a set of polygons, perhaps even as a set of convex polygons.

For every triangle, if it is completely inside one region, you have to count it. So add the voume it spans with the origin (o.e. its determinant) to the accumulated volume. If it is completely outside all regions, don't count its volume but add its projection as a new polygon. If it is partially inside a region and partially outside, only compute and add the volume for the part which is outside, and add the projection to the region it did intersect. If it intersects more than one region, only count the part which is outside all of them, and consider joining the regions into a bigger one to simplify your data structures.

MvG
  • 57,380
  • 22
  • 148
  • 276
  • The question I linked explains exactly what you said, and I do that already. I want to calculate the volume of the void, or the space between the mesh and the floor. Check the image in my original question for something a little bit clearer. – Blue Ion Feb 15 '14 at 11:14
  • @BlueIon: I guess I initially missed the point of your question. Rewrite my answer, it should be better now. – MvG Feb 15 '14 at 15:17