- Joined
- Mar 28, 2008
- Messages
- 671
- Reaction score
- 32
- Points
- 43
I just need an Idea how I can create an alogrithm to calculate "average position and speed" of a n-body system, to subtract this values from each body.
So the system should be the same, but without any "Offset" for position and speed to the "global frame".
I think I need to calculate the "Barycentric coordinates" and subtract the coordinates from each body right?
Background is, I want to "Normalize" a gravitational system where I have positions and speeds, that it will stay near the "zero - point"...
At wikipedia, I found how to calculate it for 2 boddies.
I need it for x/y/z coordinates and I don't realy know how to calculate it for 3 / 4 / n boddies.
Is it the same formular for speed and position?
Please give me any hints or ideas
---------- Post added at 22:03 ---------- Previous post was at 21:17 ----------
Ha got it myself...
So the system should be the same, but without any "Offset" for position and speed to the "global frame".
I think I need to calculate the "Barycentric coordinates" and subtract the coordinates from each body right?
Background is, I want to "Normalize" a gravitational system where I have positions and speeds, that it will stay near the "zero - point"...
At wikipedia, I found how to calculate it for 2 boddies.
I need it for x/y/z coordinates and I don't realy know how to calculate it for 3 / 4 / n boddies.
Is it the same formular for speed and position?
Please give me any hints or ideas

---------- Post added at 22:03 ---------- Previous post was at 21:17 ----------
Ha got it myself...
Code:
public class GBodySystemNormalizer
{
static public void normalizeVectors(List<GBody> gBoddies)
{
GBody gbAverage = new GBody();
List<GBody> validGBoddies = new ArrayList<GBody>();
double totalMass = 0;
for (GBody gb : gBoddies)
{
if (gb.mergedObject == null)
{
validGBoddies.add(gb);
totalMass += gb.m;
}
}
for (GBody gb1 : validGBoddies)
{
gbAverage.r[0].add(gb1.r[0].mul(gb1.m/totalMass));
gbAverage.v[0].add(gb1.v[0].mul(gb1.m/totalMass));
}
for (GBody gb : validGBoddies)
{
gb.r[0].det(gbAverage.r[0]);
gb.v[0].det(gbAverage.v[0]);
}
}
}
Last edited: