I recently started playing with android and decided to try making a basic physical simulator, but I ran into a small problem.
I have a Ball object, each ball has a velocity vector, and the way I move it is to add the specified vector to the ball with each tick. It worked well enough until I noticed a problem with this approach.
When I tried to apply gravity to the balls, I noticed that when two balls are approaching each other, one of the balls starts at a great speed.
After some debugging, I found the reason for this. Here is an example of how I calculate gravity and acceleration:
for (Ball ball : Ball.balls)
if (ball != this) {
double m1 = this.getMass();
double m2 = ball.getMass();
double distance = this.getLocation().distance(ball.getLocation());
double Fg = 6.674*((m1*m2)/(distance * distance));
Vector direction = ball.getLocation().subtract(this.getLocation()).toVector();
Vector gravity = direction.normalize().multiply(Fg / mass);
this.setVeloctity(this.getVelocity().add(gravity));
}
- , ( ), , , , , .
, - , ? , ?
, , , .