title: Bouncing ball between 4 walls destination algorithm
body: <p>I'm trying to implement an animation of a ball bouncing between 4 perpendicular walls, being the speed of the ball constant. The problem is, the framework I'm using requires me to tell the origin and the destination of the ball each time it collides with a wall.</p>
  
  <p>In the moment of the collision, I have access to both the ball's current and previous positions of contact with the walls. Given the coordinates x_min, x_max, y_min and y_max of the walls, and these two positions of the ball, what is the simplest way to calculate its next position?</p>
  
  <p>All the algorithms I thought about followed kind of a brute force approach, with many if-else statements... I wonder if there is some elegant way of handling this.</p>