Advanced maths

Polygon billiard trajectory calculator with reflection steps

Polygon billiards trace a point ray that reflects specularly from straight walls.

Your numbers

No holes; x,y rows.
Integer 1–100.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Polygon billiards trace a point ray that reflects specularly from straight walls. This calculator repeatedly finds the nearest forward boundary intersection and reflects the direction across that wall’s tangent. A corner hit stops the trajectory before reflection because two meeting walls do not supply one unambiguous normal.

THE FORMULAv_out=2(v_in·t)t−v_in, with unit wall tangent t.

A worked example

In a 4×3 rectangle, start at (1,1) with direction (1,0.3). The first collision is at (4,1.9); reflection reverses the horizontal component and preserves the vertical component. Unfolding reflected copies of the rectangle turns the same path into a straight line.

Good to know

Simple polygon without holes, strictly interior start, nonzero direction and one to 100 reflections. Numerical corner/near-corner hits stop with an explicit status. No finite-radius particle, curved wall or long-term chaotic-orbit prediction. Distance includes completed reflections only.

The next wall is the nearest forward hit

The starting point must lie strictly inside the simple polygon, and the direction must be nonzero. It is normalized before tracing, so its magnitude does not set a physical speed. Only its orientation determines the geometric path, while traveled distance is accumulated separately from the positive ray parameters between completed collisions.

Every wall intersection is tested in the forward ray direction and within the finite edge segment. The nearest admissible hit is selected. Choosing an intersection with an infinite supporting line or a farther wall would allow the particle to pass through the actual boundary and would not represent polygon billiards.

A rectangular billiard reflection reverses the normal velocity componentstartFirst hit: (4,1.9)vx reverses; vy staysThree wall reflections
In a 4×3 rectangle, start at (1,1) with direction (1,0.3). The first collision is at (4,1.9); reflection reverses the horizontal component and preserves the vertical component. Unfolding reflected copies of the rectangle turns the same path into a straight line.

The Reflect a point across a line calculator covers the nearby task. One reflected point does not evolve a ray through repeated nearest-boundary collisions.

Specular reflection preserves speed

Reflection across a unit wall tangent preserves the tangential component and reverses the normal component. The resulting direction should retain unit length up to roundoff and satisfy equal incidence and reflection angles. The implementation updates the direction at the hit point rather than reflecting the point coordinates as if they were a new starting position elsewhere.

A rectangular table provides an independent unfolding construction: reflect copies of the rectangle instead of reflecting the ray, then follow a straight line. Folding those crossings back into the original rectangle checks collision order and positions. This validation uses geometry different from the step-by-step nearest-edge code.

Corner encounters stop without an invented normal

At a vertex, two edge normals are available and the ideal specular continuation is generally undefined. Near-corner numerical ties are also sensitive. The page stops before applying a reflection and reports that status, rather than choosing whichever edge happened to appear first in the input list and extending an arbitrary trajectory.

The displayed length includes completed unambiguous reflection segments. No claim is made about long-time periodicity, ergodicity or chaos from a finite path. Curved walls, holes, finite-radius particles and rough collisions require different models. Independent checks examine wall membership, reflection invariants, rectangular unfolding and explicit corner-stop behavior within the supported finite horizon.

Construct one reflection from geometry

A ray is intersected with every polygon side, and the nearest positive intersection selects the next collision. For a unit tangent s along that side and incoming unit direction v, the reflected direction is vnew=2(v·s)s−v. The tangential component is preserved and the normal component reverses, implementing equal angles of incidence and reflection.

The direction is normalized before tracing, so multiplying the entered direction by a positive constant does not change the path. This form tracks geometry rather than elapsed physical time or a speed parameter. Distance is accumulated along completed collision segments, and every new reflected ray is traced from the previous wall hit.

Follow the rectangular default through three walls

In the rectangle (0,0),(4,0),(4,3),(0,3), start at (1,1) with direction proportional to (1,0.3). The first hit is the right wall at (4,1.9), after which the horizontal component reverses. The second is the top wall at (1/3,3), where the vertical component reverses.

The third hit is the left wall at (0,2.9). In unnormalized horizontal-step units, traveled segments are 3,11/3,1/3, totaling 7; Euclidean length is therefore 7√(1+0.3²)≈7.308215. The displayed outgoing directions are unit vectors, so compare their signs and component ratios rather than expecting the raw input magnitudes.

Treat a corner as an undefined reflection rule

At a polygon vertex, two sides meet and there is no single wall normal. This model therefore stops before an ambiguous corner or near-corner reflection. It does not choose one side arbitrarily or claim that a physical point particle must follow one particular continuation.

For the same rectangle, direction (3,2) from (1,1) reaches corner (4,3) directly. No ordinary wall reflection has completed, so the completed-reflection count is zero. The distance metric includes completed reflections only and does not add the unfinished corner segment. Read the status together with the count rather than assuming every requested reflection was achieved.

Understand finite precision and the point-particle model

Vertices must form a simple polygon in boundary order, and the start must be strictly inside rather than on an edge. The polygon may be concave, making nearest-forward intersection important; intersecting the supporting infinite lines without checking segment bounds would select nonexistent walls.

A finite-radius ball would collide before its center reaches the wall and needs offset geometry. Curved walls need local normals, and long trajectories can amplify small numeric differences near vertices. None is included here. Use the trace to examine a bounded sequence of ideal specular reflections, not to certify long-term periodicity, chaos, conservation in a real mechanical system or collision behavior with rounded physical corners.

A few questions, answered

What happens at a corner hit?

The trace stops before reflection because no unique wall normal is available.

Does direction magnitude set speed?

No. Direction is normalized; this is a geometric path calculation without a physical time scale.

Why does scaling the direction leave the path unchanged?

Only its orientation is used; the vector is normalized before tracing. The calculator does not interpret its magnitude as a physical speed.

Why is a direct corner hit not counted as a reflection?

Two walls provide no unique normal at the vertex. The form stops before assigning an arbitrary continuation and reports only completed unambiguous reflections.

Find your calculator

Start typing to explore the library.