Is it possible to calculate the volume for a mesh?

Started by
15 comments, last by Dmytry 19 years ago
Hi, say I've got a mesh, which is my spaceship constructed out of a trianglelist of triangles. ie 3 vertices for each triangle. Is there someway I can calculate the volume inside my spaceship? I want to do this so I can use the volume as the mass of the ship. Thanks
Advertisement
To learn of what's involved in what you ask, see the following paper by Dave Eberly:

http://www.geometrictools.com/Documentation/PolyhedralMassProperties.pdf
Yes, but it is not worthwhile to do so unless you really must. Also can you explain why you are using you ship's volume for its mass? That doesnt make much sense. Why not just give the ship a mass?
Maybe something you already have thought of.
But you can calculate the bounding box of your mesh and
use the volume of bouding box to set your mass.
This won't be as accurate but is a lot more easy to do.
You can pick a plane (Most easily the XY Plane)
For each traingle you can project it onto that plane (easy)
This creates a prism-like solid. Add the volume of that solid to the total mesh volume.
For counter clock wise traingles the volume should be positive and for clockwise triangles it should be negative.

This method is credited to Dmytry and he can give more explanation on the subject.
[ my blog ]
Quote:Original post by meo
Maybe something you already have thought of.
But you can calculate the bounding box of your mesh and
use the volume of bouding box to set your mass.
This won't be as accurate but is a lot more easy to do.


seconded.
Quote:Original post by Daerax
Yes, but it is not worthwhile to do so unless you really must. Also can you explain why you are using you ship's volume for its mass? That doesnt make much sense. Why not just give the ship a mass?


I thought it would be nice to give a ship a unique mass, depending on how big it is. I would just calculate the mass once for each ship type.
Quote:Original post by johnnyBravo
Quote:Original post by Daerax
Yes, but it is not worthwhile to do so unless you really must. Also can you explain why you are using you ship's volume for its mass? That doesnt make much sense. Why not just give the ship a mass?


I thought it would be nice to give a ship a unique mass, depending on how big it is. I would just calculate the mass once for each ship type.


i second the bounding box solution. especially because volume probably wouldn't be proportional to volume anyways. Using the surface size (which is a LOT easier to compute) as a guideline for weight would probably be more realistic anyways because it is very likely that the hull is the heaviest component.
Quote:Original post by johnnyBravo
Quote:Original post by Daerax
Yes, but it is not worthwhile to do so unless you really must. Also can you explain why you are using you ship's volume for its mass? That doesnt make much sense. Why not just give the ship a mass?


I thought it would be nice to give a ship a unique mass, depending on how big it is. I would just calculate the mass once for each ship type.


Oh! Then that is actually a good idea, I think I might use it myself [smile]. Im going to assume you are going to replace the triangles with an actual complex mesh otherwise you can simply assign a height and calculate the volume using the equation for the volume of a pyramaid. Otherwise...

I would also second the idea of computing a bounding volume for your needs, since accuracy is not really imperative here. I would go a step further however and suggest you include the concept of density into your calculations since a large volume does not necessarily imply a large mass. Look at a bowling bowl versus a balloon or something as an example, both can be of equal volume but definately not equal weight [mass *g].

Using DirectX you can compute the bounding box using the D3DXComputeBoundingBox() function. This function returns two vectors pMin and pMax. The product of the vector components of the vector that is the difference between these two vectors will be the volume you need e.g.
D3DXVECTOR3  dimension_vector, pMin, pMax;D3DXComputeBoundingBox(.., &pMin, &pMax)dimension_vector = pMax - pMin;  float volume = dimension_vector.x*dimension_vector.y*dimension_vector.z;

Here is where it gets tricky though, in order for the equation you will use to calculate the mass for volume, m = ρV, where ρ is density and V is volume, to make sense we are going to replace he ship with a box of uniform density and mass distribution which bounds the ship as an approximation of the ship's volume. I make the emphasis on replacing with a box as an approximation because there is no gurantee that the object [ship] will have a uniform mass distribution. Actually, chances are that it will not. The significance of this is that certain areas of the ship will be more dense than others and you would actually need to differntiate across the entire surface (hard) to get proper results. So we just approximate with a simple box [grin]. You can multiply by .05 to .1+ to make up for the empty space that will be around the spaceship depending on your needs.

So you can give each ship a default density in the constructor of the ship class or something and you dont really need to change it unless you have to, say upgrading to a ship with a lighter material or something. Otherwise the density part of the equation remains transparent and you more or less use the volume to calculate the mass.

Here is a list of the density of different materials.
if it's for a game, you'd be better of to make it up. Then you can tweak the gameplay as you wish (add more mass since the ship is more powerful than expected, ect...).

Everything is better with Metal.

This topic is closed to new replies.

Advertisement