Billiards simulator
Follow exact ray reflections in six tables and inspect signed collision phase coordinates.
About this tool
The table preview is available before the first collision. Its arrow shows the launch direction, without advancing the model. Start and Pause share one button. Clear trail keeps the inputs and returns to this preview. Trajectory readings show the hit position and reflection angles; phase-space readings show s and p. Both views retain collision count and distance. Numeric fields or a table tap choose a new start.
An ideal point particle moves in straight lines and reflects elastically from the boundary. There are no forces, friction, finite ball radius or obstacles. Coordinate units are arbitrary; the model uses unit speed. Playback is measured in collisions per display second, not physical flight time. The geometries can behave differently; this is not a claim that every orbit or table is chaotic.
Start and controls. The start must lie strictly inside the selected table. A boundary or outside start is rejected, never silently moved. Starts within 128 machine epsilons (about 2.84×10⁻¹⁴ coordinate units) of the boundary are also rejected as numerically ambiguous. The initial angle is measured counterclockwise from +x in turns: 0 is right, 0.25 up, 0.5 left, and 1 equals 0. Start begins or resumes; One collision pauses and advances to exactly one new boundary hit. Clear trail keeps the inputs and restores the preview. A tap in the trajectory sets new input coordinates and stops the old run; it does not simulate. Numeric fields are the keyboard alternative.
Domain, start or direction changes clear the trajectory. View, grid, palette and a valid playback-rate change retain the model and history. Hidden tools and browser tabs pause. Long display stalls contribute at most 0.25 seconds to one playback update. The run stops after 10,000 collisions; at most 10,000 trajectory vertices and 10,000 regular phase points are retained. PNG saves the labeled active canvas view.
Fixed tables. Rectangle: half-width 0.48, half-height 0.34. Circle: radius 0.44. Ellipse: semi-axes 0.5 and 0.32. Stadium: straight half-length 0.28 and cap radius 0.22. Triangle and regular 3–12-gons: circumradius 0.42, first vertex at angle π/2. Both trajectory axes have the same scale; y points upward.
Reflection. For unit outward normal n, vout = vin − 2(vin·n)n. The incoming angle to the outward normal equals the outgoing angle to the inward normal; both are reported as nonnegative angles. Arrow i ends at the collision, arrow o starts there, and dashed n points outward. Arrow lengths are illustrative. The model passes the computed boundary point to the next ray without an artificial inward displacement.
A polygon corner, including a rectangle corner, has no unique normal and no defined continuation in this model. Such hits stop with no outgoing velocity or p. The stadium joins are tangent-continuous and are not polygon corners. Tangencies and collisions too close to distinguish in floating-point arithmetic also stop explicitly. Ray intersections use stable quadratic roots; corner and near-zero-distance decisions have finite precision.
Signed phase space. s is counterclockwise arc length divided by perimeter, in [0,1). With CCW unit tangent t = (−ny,nx), p = vout·t / |vout| lies in [−1,1]. Its sign distinguishes the two tangential directions; p = 0 is normal incidence. The origin is the rightmost point for circle and ellipse, the first vertex for polygons, the bottom-left corner for the rectangle, and (−a,−r) for the stadium. The stadium order is bottom edge, right cap, top edge, left cap. Ellipse arc lengths use a cached 2048-panel Simpson quadrature with a partial-panel evaluation and are numerical approximations. Other perimeters and arc pieces use their analytic lengths.
Sources: MIT, Paul Seidel: 18.900 Lecture 6 (reflection law and undefined corner continuation); DynamicalBilliards.jl: phase spaces (boundary arc length and signed outgoing angle).