# java – Ball-Ball Collision physically correct

hello guys im not a native english speaker so sorry for my bad english.
my problem ist that im working on a ball simulator with correct physics.
my code looks like this

´´´

public void kollisionsVelocity(Ball ball, Ball nebenball){

``````    ball.setCenterX(ball.getxPos());
nebenball.setCenterX(nebenball.getxPos());
ball.setCenterY(ball.getyPos());
nebenball.setCenterY(nebenball.getyPos());

double normaleX = ball.getCenterX() - nebenball.getCenterX();
double normaleY = ball.getCenterY() - nebenball.getCenterY();
double normaleXn = normaleX / abstandKugeln(ball, nebenball);
double normaleYn = normaleY / abstandKugeln(ball, nebenball);

double tangenteX = -normaleYn; //Senkrecht zum normalenvektor
double tangenteY = normaleXn;

double tGeschwindigkeit1 = ball.getxVel() * tangenteX + ball.getyVel() * tangenteY;
double tGeschwindigkeit2 = nebenball.getxVel() * tangenteX + nebenball.getyVel() * tangenteY;

double nGeschwindigkeit1 = ball.getxVel() * normaleXn + ball.getyVel()*normaleYn;
double nGeschwindigkeit2 = nebenball.getxVel() * normaleXn + nebenball.getyVel()*normaleYn;

double n1 = 2* ball.getMass()*nGeschwindigkeit1 + nebenball.getMass()*nGeschwindigkeit2 / ball.getMass() + nebenball.getMass() - nGeschwindigkeit1;
double n2 = 2* ball.getMass()*nGeschwindigkeit1 + nebenball.getMass()*nGeschwindigkeit2 / ball.getMass() + nebenball.getMass() - nGeschwindigkeit2;

ball.setxVel(tangenteX * tGeschwindigkeit1 + normaleXn * n1);
ball.setyVel(tangenteY * tGeschwindigkeit1 + normaleYn * n1);
nebenball.setxVel(tangenteX * tGeschwindigkeit2 + normaleXn * n2);
nebenball.setyVel(tangenteY * tGeschwindigkeit2 + normaleYn * n2);
``````

´´´

i thought that is correct but i spoke to my professor right now and he said that is fine but there are missing some cases where it is not physically correct. he said in some cases the velocity has to be negative for one ball (?) can someone maybe explain what cases are missing.