I'm working on a small Unity hobby project where I'm trying to program thrusters for a spaceship in 3D space. The thrusters are working, but I have some issue with matching the centre of thrust with the center of mass. I want the thrusters to automatically adjust their strength based on their position relative to a movement direction.
When looking at the problem a bit more simplistically, I'm left with this situation:
I have a random amount of weights placed on a 2D plane at random locations. The mass of each weight is unknown, and the center of mass of all weights must be at 0,0.
How do I calculate the mass of each weight?
So far, I'm visualising the problem as a 2D space where the center of mass must be 'pulled' to 0,0 by increasing the mass of the weights. But I can't figure out an algorithm to do this accurately, and with the least amount of mass delta between weights.
The problem as you've described is underconstrained. With m1, m2, etc as the masses and (x1, y1), (x2, y2), etc as the coordinates:
m1 * x1 + m2 * x2 + m3 * x3 + m4 * x4 = 0
m1 * y1 + m2 * y2 + m3 * y3 + m4 * y4 = 0
Set m3 and m4 to zero and it's pretty easy.
You have four free variables (4 masses) to make match two equations. The only complication is that mass probably has to be positive for all values.
A pretty optimal way to solve this in your case is to pick a default mass, then try for each pair of masses (m1, m2), (m1, m3), (m1, m4), (m2, m3), etc, solve the equation with the other masses set to the default mass.
So, if default mass is 5kg, set m3 = 5kg and m4 = 5kg, solve for m1 and m2, getting say, m1 = 3kg and m2 = 6kg. Repeat this for all pairs of masses. Pick the pair that deviates the least from the default mass and doesn't go negative.