**0**

# Is it possible to calculate the volume for a mesh?

Started by johnnyBravo, Apr 07 2005 06:33 PM

16 replies to this topic

###
#1
Members - Reputation: **100**

Posted 07 April 2005 - 06:33 PM

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

###
#2
Members - Reputation: **824**

Posted 07 April 2005 - 08:48 PM

To learn of what's involved in what you ask, see the following paper by Dave Eberly:

http://www.geometrictools.com/Documentation/PolyhedralMassProperties.pdf

http://www.geometrictools.com/Documentation/PolyhedralMassProperties.pdf

Christer Ericson

http://realtimecollisiondetection.net/blog/

http://realtimecollisiondetection.net/blog/

###
#5
Members - Reputation: **226**

Posted 08 April 2005 - 12:06 AM

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.

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.

###
#7
Members - Reputation: **100**

Posted 08 April 2005 - 12:41 AM

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.

###
#8
Members - Reputation: **1461**

Posted 08 April 2005 - 04:57 AM

Quote:

Original post by johnnyBravoQuote:

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.

###
#9
Members - Reputation: **1207**

Posted 08 April 2005 - 10:31 AM

Quote:

Original post by johnnyBravoQuote:

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.

###
#11
Members - Reputation: **241**

Posted 10 April 2005 - 02:39 PM

Quote:

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...).

I second that.. and a ship's density isn't constant, you could have a very small ship that weights the same or more than a larger ship, how do you determine the average density?

the same for all ships? quite restrictive... :/

by hand? then you'd better just set their weight by hand in the first place, and then you won't need their density...

anyway.. that's just my opinion.. if you still want to compute their volume, you can use the method Dmytry described in the other thread. (link's somewhere up on this page)

I use that method too and it works fine.

just take the AABB height and lower Y bound, place the virtual projection plane at min.y - (height * 0.1) (the relative offset is here just to avoid some imprecisions if the meshes you want to measure vary widely in size, then just ignore the Y coordinate of the triangles, compute the 2D area (dot product), and do area * (v0->y + v1->y + v2->y) / 3.0f, and add these values for each triangle to an accumulator. in the end, you'll get the volume.

he gave some visual explanations in the other thread if I recall correctly... might be clearer :)

note that if your mesh isn't closed, you will have volume "leaking" in or out, depending if the "hole" is located on the top or bottom of the mesh... anyway, make sure the mesh is completely closed.

###
#12
Anonymous Poster_Anonymous Poster_*
Guests - Reputation:

Posted 11 April 2005 - 10:41 AM

Simple geometric solution:

http://amp.ece.cmu.edu/Publication/Cha/icip01_Cha.pdf

http://amp.ece.cmu.edu/Publication/Cha/icip01_Cha.pdf

###
#13
Members - Reputation: **410**

Posted 12 April 2005 - 09:20 AM

I like the surface area approximation, after all the inside tends to be mostly air as far as science fiction spaceships go... Get the area and multiply with the thickness of your armor plating. Add some known/constant values for things like thrusters or nuclear reactors or cargo. That way you can display how many kilotons of neutronium you have onboard and have it actually mean something (Total mass = hull mass + systems + payload).

But then you'll need to know the volume anyway to tell how many standard crates you can fit in the hold :)

But then you'll need to know the volume anyway to tell how many standard crates you can fit in the hold :)

###
#14
Members - Reputation: **100**

Posted 12 April 2005 - 01:42 PM

yes I was thinking of just getting the area of a triangle and multiply that by the armour thickness.

But this isn't really a game that I'm making, its more of just a testing ground for ai ideas, eg flocking, fighting etc. So I don't really have imaginary cockpits etc. And I just want my world to have realistic physics, but simple representations of stuff, eg spaceships as a solid object.

Right now weapons and engines don't really add to the mass, as they are just represented as invisible objects placed on the spaceship, eg thrusters are placed around the ship so it can manuevour properly, and when a thruster fires, it just applies a force the ship. And weapons which are all projectiles, just create objects eg bullet or missile which apply that force to the ship when fired.

So what I'm trying to say is, every is to be simple, no cargo etc. Maybe the number of projectiles mass might be added to the ship's mass, and removed as they are shot. Hmmm now that also involves space within the spaceship.

And using Daerax's density link, I will just apply density to my ships from looking at the different metals I could use.

But this isn't really a game that I'm making, its more of just a testing ground for ai ideas, eg flocking, fighting etc. So I don't really have imaginary cockpits etc. And I just want my world to have realistic physics, but simple representations of stuff, eg spaceships as a solid object.

Right now weapons and engines don't really add to the mass, as they are just represented as invisible objects placed on the spaceship, eg thrusters are placed around the ship so it can manuevour properly, and when a thruster fires, it just applies a force the ship. And weapons which are all projectiles, just create objects eg bullet or missile which apply that force to the ship when fired.

So what I'm trying to say is, every is to be simple, no cargo etc. Maybe the number of projectiles mass might be added to the ship's mass, and removed as they are shot. Hmmm now that also involves space within the spaceship.

And using Daerax's density link, I will just apply density to my ships from looking at the different metals I could use.

###
#15
Members - Reputation: **1165**

Posted 12 April 2005 - 03:53 PM

Quote:

Original post by johnnyBravo

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

Suppose you have a vertex array V[] of N vertices. The triangle list is an array I[] of 3*T indices into the vertex array and represents T triangles. Suppose the mesh is closed, each edge is shared by two triangles, and the mesh is not self-intersecting ("water tight" in the vernacular). Also assume that the triangles are counterclockwise oriented as viewed by an observer outside the mesh. Finally, assume that the mass density is constant (1). If nonconstant, the problem is much more difficult.

float volume = 0;

int* index = I;

for (i = 0; i < T; i++)

{

Vector3 v0 = V[*index++];

Vector3 v1 = V[*index++];

Vector3 v2 = V[*index++];

volume += Dot(v0,Cross(v1,v2));

}

volume /= 6;

###
#17
Members - Reputation: **1150**

Posted 12 April 2005 - 06:10 PM

For example, with real planes, mass is not proportional to volume. (large plane have lower average density than small plane). Area * armor thickness seems as reasonable idea, except that inside ship you also must have structural elements for strength. As about using densities of metals, spacecrafts made out of solid metal is too cool, heck.

Let we have field F(P)=P . It have constant divergence Ñ·F = 3 . Flow of F(P) through triangle ABC is 1/2 * A.BXC . Method above uses exactly that. (it indeed could be said that it just adds volume of pyramids. [grin] but you can derive it from divergence theorem (aka Gauss's Theorem) , and will not have problems proving that negative volume trick will work)

(2everyone who suggested my method explained in other tread, that only differs in "volume+=(v0.x+v1.x+v2.x)*Cross(v1-v0,v2-v0).x" (uses field F(P)=[P.x,0,0] with divergence 1) : it was made to simplify computation of volume of submerged object. In other cases, "pyramids method" is nicer)

Quote:

Original post by Dave EberlyQuote:

Original post by johnnyBravo

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

Suppose you have a vertex array V[] of N vertices. The triangle list is an array I[] of 3*T indices into the vertex array and represents T triangles. Suppose the mesh is closed, each edge is shared by two triangles, and the mesh is not self-intersecting ("water tight" in the vernacular). Also assume that the triangles are counterclockwise oriented as viewed by an observer outside the mesh. Finally, assume that the mass density is constant (1). If nonconstant, the problem is much more difficult.

float volume = 0;

int* index = I;

for (i = 0; i < T; i++)

{

Vector3 v0 = V[*index++];

Vector3 v1 = V[*index++];

Vector3 v2 = V[*index++];

volume += Dot(v0,Cross(v1,v2));

}

volume /= 6;

Quote:

Have you considered using Gauss' Theorem?

Let we have field F(P)=P . It have constant divergence Ñ·F = 3 . Flow of F(P) through triangle ABC is 1/2 * A.BXC . Method above uses exactly that. (it indeed could be said that it just adds volume of pyramids. [grin] but you can derive it from divergence theorem (aka Gauss's Theorem) , and will not have problems proving that negative volume trick will work)

(2everyone who suggested my method explained in other tread, that only differs in "volume+=(v0.x+v1.x+v2.x)*Cross(v1-v0,v2-v0).x" (uses field F(P)=[P.x,0,0] with divergence 1) : it was made to simplify computation of volume of submerged object. In other cases, "pyramids method" is nicer)