Simulate billiard physics - HTML5
For a new project I am currently developing a billiard game. This article deals with physics. First of all, the balls don't rotate, there is no spin. This makes the physics part a lot easier.
We come directly to the first special case of the inelastic impact: the impact. Before the impact, all the balls, except the white one, are close to each other and form a triangle, a unit, a whole. The impact triggers a chain reaction of shocks and gives each ball the initial force for a short moment. Due to the low friction, the balls lose little energy on impact.
The first ball transfers its full energy to the last ball and back again.
An interesting video on the subject can be found here: planet-schule.de - Angestißen. In this experiment it is tested whether it is possible to transfer the force of an impact up to the last ball in a row. The row consists of 600 balls.
ball against ballVielleicht auch interessant
Grundlegende Server/Client Logik mit SFML für Gether.
The whole thing looks a bit different when two single balls collide with each other. Let's assume here that one of the balls is resting.
The white ball experiences an impulse, flies against the other ball and exchanges forces with it. We can talk about an exchange here, because the balls all have the same mass and size. At this meeting the minimal friction and possible rotation of the ball influence the result, but we ignore that here.
If the balls hit each other at two different speeds, the inelastic impact happens the same as before. The forces are exchanged.
Programming is probably the most interesting way to move the balls in the right direction after they have been hit by another ball. How do we do that?
This is much easier than you might think, all we need is atan2 and the centers of both spheres.
var a = Math.atan2(ball1.getY() - ball2.getY(), ball1.getX() - ball2.getX()); var dx= Math.cos(a); var dy= Math.sin(a);
With dx and dy we can now move the ball in the right direction.
More about atan2 can be found in the following article: Shoot in mouse direction.