In this challenge the table is still four-sided, but the angles are not straight; furthermore, there are pockets in the four corners.

As I want to use graphics for the challenge, dimensions/positions are given in pixels.

The four corners are located:

p1 = (100, 730) p2 = (700, 700) p3 = (500, 400) p4 = (50, 190)

The ball is simply a single (decimal-)point, graphically represented as a single pixel.

The starting point for the ball is (172, 520)

The pockets are a single pixel wide; i.e. if the position of the ball is less than 0.5 pixels from a corner, the ball is considered to be in the pocket.

We think of a board with no friction and perfect elastic bounces. Angle of incidence equals angle of reflection.

Now, a billiard board with ‘random’ angles is known to behave chaotic. If two shots are made with even a minute difference in starting angle, they will end up following completely different trajectories after a few bounces. It is really amazing to see.

A starting task in this challenge is to make a program that can simulate a ball on such a table. If you start a ball in a random direction it will end up in a pocket – but it might require several hundreds of bounces, sometimes more than 1000 bounces.

A popular form of carambole is the three-cushion game. This requires the player to be able to calculate/predict the ball position after four bounces (one cue and three cushions); demanding, but still doable on a normal table.

But more difficult on the table in this challenge.

So, here is the challenge:

Make a program that can calculate the starting angle such that the ball ends up in a pocket after

**exactly**four bounces on the table sides.

The picture below shows one possible solution. There are many solutions; it will be great if you find (minimum) one for each corner.

You can report ‘Mission Accomplished’ by uploading a picture of one of your solutions.

I use a red dot to mark the starting point and all bounce points.

Closing remark:

I have made many games involving bounces. But they were all bounces on either horizontal or vertical surfaces for which the math is very simple. Reflection on skewed lines was a little more complicated than I expected; I was probably seduced by the simplicity of “Angle of incidence equals angle of reflection”. So, don’t despair if this part takes longer than you expect.

The tricky part of this challenge is about ending up in a pocket after 4 bounces.

Happy Coding.

A special Post Scriptum for snoopy11:

Turtle graphics will be great….