views:

166

answers:

4

I am working on a C# 2d soft body physics engine and I need to assign masses to an object's vertices given: a list of vertices (x,y positions), the total mass for the object, and the center of mass.

The center of mass is given as:

alt text

where,

R = center of mass
M = total mass
mj = mass of vertex j
rj = position of vertex j

I need an algorithm that can approximate each mj given R, M, and rj.

edit: I just want to clarify that I am aware that there are an infinite set of solutions. I am looking for a quick algorithm that finds a set of mj's (such that they are each sufficiently close to mj = M/[number of vertices] and where "sufficiently" is defined as some small floating point threshold).

Also, each object will consist of about 5 to 35 points.

+1  A: 

Count the degrees of freedom: for points in D dimensional space you have D+1 equations[+] and n unknowns for n separate particles. If n>D+1 you are sunk (unless you have more information than you have told us about: symmetry constraints, higher order moments, etc...).

edit: My earlier version assumed you had the m_is and were looking for the r_is. It is slightly better when you have the r_is and want the m_is.

[+] The one you list above (which is actual D separate equation) and M = \sum m_j


Arriu said:

Oh sorry I misunderstood your question. I thought you were asking if I was modeling objects such as a torus, doughnut, or ring (objects with cutouts...). I am modeling bodies with just outer shells (like balloons or bubbles). I don't require anything more complex than that.

Now we are getting somewhere. You do know something more.

You can approximate the surface area of the object by breaking it into triangles between adjacent points. This total area gives you mean mass density. Now find the DoF deficit, and assign that many r_is (drawn at random, I guess) an initial mass based on the mean density and 1/3 of the area of each triangle it is a party to. Then solve the remaining system analytically. If the problem is ill-conditioned you can either draw a new set of assigned points, or attempt a random walk on the masses that you have already guessed at.

dmckee
the key word is "approximate"
Arriu
If you "solve" your system using the usual methods for solving simultaneous equations, you'll end up with equations describing the set of solutions in terms of a couple of variables. Just pick arbitrary values for those variables if you want a particular solution.
Anon.
When you are 1 DoF short the result is an entire line of acceptable solution. Which on of the infinite points do you propose to take? If you're 2 DoF short it is a plane, etc... So, do you have something else? An understanding of what the typical mass range is? Anything at all?
dmckee
I don't have anything more to work with than what I have stated above (except that the vertices do form a closed shape which does not cross). I am currently looking at barycentric coordinates as a possible way to approximate mass values...
Arriu
If you know the exact position of each vertex in 2D space, then you have three equations. If you have more than three points, then you're basically guessing - just solve as normal, pick arbitrary values for any parameters, and you have a valid solution.
Anon.
A: 

I would flip the problem around. That is, given a density and the position of the object (which is of course naturally still the center of mass of the object and three vectors corresponding to the orientation of the object, see Euler's angles), at each vertex associate a volume with that element (which would change with resolution and could be fractional for positions at the edge of the object) and multiply the density (d_j) with the associated volume (v_j), m_j=v_j * d_j. This approach should naturally reproduce the center of the mass of the object again.

Perhaps I didn't understand your problem, but consider that this would ultimately yield the correct mass ( Mass = sum(m_j) = sum(v_j * d_j) ) and at worst this approach should yield a verification of your result.

Alex
+1  A: 

The center of mass R will constantly be changing as the vertices move. So, if you have 10 vertices, store the values from 10 consecutive "frames" - this will give you 10 equations for your 10 unknowns (assuming that the masses don't change over time).

mbeckish
He *may* be talking about finite elements in a rigid body, which would kill this. Or he may have to do it with a single sample. But it is a cute idea.
dmckee
I am referring to the base shape of a soft body. The base shape never changes. It defines what the soft body will look like when it is not deformed.
Arriu
Do you have uniform---or even close to uniform---density? If so you can leverage that...
dmckee
+1  A: 

You can compute the CM of a uniformly dense polygon as follows: number the N vertices from 0..N-1, and treat them cyclicly, so that vertex N wraps to vertex 0:

total_area = sum[i=0..N-1]( X(p[i],p[i+1])/2 )
CM = sum[i=0..N-1]( (p[i]+p[i+1])*X(p[i],p[i+1])/6 ) / total_area

   where X(p,q)= p.x*q.y - q.x*p.y  [basically, a 2D cross product]

If the polygon is convex, the CM will be inside the polygon, so you can reasonably start out by slicing up the area in triangles like a pie, with the CM at the hub. You should be able to weight each vertex of a triangle with a third of its mass, without changing the CM -- however, this would still leave a third of the total mass at the CM of the entire polygon. Nonetheless, scaling the mass transfer by 3/2 should let you split the mass of each triangle between the two "external" vertices. As a result,

area[i] = X( (p[i]-CM), (p[i+1]-CM) ) / 2
   (this is the area of the triangle between the CM and vertices i and i+1)

mass[i] = (total_mass/total_area) * (area[i-1] + area[i])/2

Note that this kind of mass transfer is profoundly "unphysical" -- if nothing else, if treated literally, it would screw up the moment of inertia something fierce. However, if you need to distribute the mass among the vertices (like for some kind of cheesy explosion), and you don't want to disrupt the CM in doing so, this should do the trick.

Finally, a couple of warnings:

  • if you don't use the actual CM for this, it won't work right
  • it is hazardous to use this on concave objects; you risk ending up with negative masses
comingstorm