Greetings,
Currently working on Oribital Mechanics. The only problem I don’t know how to solve after investigating alot of time is the fact that the object in space is pulled straight down to the planet/sun… B
for (int i = 0; i < entities.size(); i++){ //go through all the planets
if(entities.get(i) != sun){
double distance = 0;
for (int j = 0; j < entities.size(); j++){ //add up the gravitational effects of all the other planets
if (i != j){
distance = Math.sqrt(Math.pow((entities.get(i).getX() - entities.get(j).getX()), 2) + Math.pow((entities.get(i).getY() - entities.get(j).getY()), 2));
double G = 60000;
double accMag = (G*entities.get(j).getMass())/(Math.pow(distance, 2));
double accX = (accMag*(entities.get(j).getX() - entities.get(i).getX()))/distance;
double accY = (accMag*(entities.get(j).getY() - entities.get(i).getY()))/distance;
entities.get(i).addVX(accX);
entities.get(i).addVY(accY);
}
}
entities.get(i).updatePosition();
}
}
This said, means that I only got the accMagnitude and I don’t know how I get the velocity. Also I know I probably should be using vectors to calculate it’s path. So my question is how I can calculate the velocity. I am probably overlooking some things right now…
As always, thank you very much
-Roseslayer