Is it possible to calculate the volume for a mesh?

Started by
15 comments, last by Dmytry 19 years ago
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.
Advertisement
Simple geometric solution:
http://amp.ece.cmu.edu/Publication/Cha/icip01_Cha.pdf
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 :)
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.
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;

Have you considered using Gauss' Theorem? (for the volume calculation)

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

Quote:Original post by Dave Eberly
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;


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)

This topic is closed to new replies.

Advertisement