This example builds on my original project, which has commented code: Bounce circle on line. Click and drag the polygon anchors. If you move the lines, you can make the circle bounce inside the polygon. Note: This example is not robust in the sense that you can trap the circle in a line, particularly if you move the lines. This could be fixed in a proper project, but would only mess up this example's code. All code by me (@kriblo).