Click canvas to place mirror/glass. Drag to rotate. Scroll over object to rotate.
This simulation traces a single laser ray through a 2D playfield, bouncing it off flat mirrors and bending it through glass blocks until it reaches the orange target. The engine uses ray–segment intersection to find the nearest surface, then applies the vector reflection formula r = d − 2(d·n)n at mirrors and Snell's law n₁·sin θ₁ = n₂·sin θ₂ at glass faces, recursing once per surface up to the bounce limit.
Sliders set the launch angle (−90° to 90°), the maximum number of bounces (1–30) and the glass refractive index n₂ (1.05–2.50). You add mirrors and glass blocks by clicking the canvas, drag them to reposition and scroll to rotate them. Counters track reflections, refractions, total path length and whether the target is hit. The same ray-tracing maths underpins fibre optics, periscopes, lens design and computer graphics.
What is the Laser Labyrinth simulation?
It is an interactive optics puzzle where you steer a laser beam off mirrors and through glass blocks to hit a circular target. It demonstrates the two core rules of geometric optics: reflection and refraction, with live counters and on-screen angle labels.
How does the law of reflection work here?
At a mirror the angle of incidence equals the angle of reflection, both measured from the surface normal. The code computes this with the vector form r = d − 2(d·n)n, where d is the incoming direction and n is the unit normal of the mirror edge, so the beam mirrors symmetrically about the normal.
What does the glass IOR slider change?
It sets the refractive index n₂ of the glass blocks, from 1.05 up to 2.50. A higher index bends the transmitted ray more sharply toward the normal on entry and makes total internal reflection easier on exit, so raising it visibly changes the beam's path through any glass you place.
Snell's law states n₁·sin θ₁ = n₂·sin θ₂, relating the angles on either side of a boundary to the two refractive indices. When the ray strikes a glass face the simulation computes the transmitted direction from this relation, increments the refraction counter and labels the new angle on the canvas.
That is total internal reflection. When a ray inside the denser glass meets the surface beyond the critical angle θ_c = arcsin(n₂/n₁), Snell's law has no real solution (sin θ would exceed 1), so all the light reflects. The simulation detects this case and reflects the ray rather than transmitting it.
Reflections counts how many times the beam mirrored off a surface or wall, Refractions counts boundary crossings through glass, Path (px) is the total distance the beam travelled in pixels, and Hit Target shows a green tick once the beam reaches the orange circle and a red cross otherwise.
The four canvas borders act as perfect mirrors so the ray is never lost off-screen. This keeps every level solvable and lets you bank shots off the walls, much like a billiard or squash table, while still obeying the same equal-angle reflection rule used for the placed mirrors.
Normals draws the dashed perpendicular line at each surface where the beam strikes, which is the reference line for measuring angles. Angles overlays the numeric incidence or refraction angle in degrees at each contact point, making it easy to verify the equal-angle reflection and Snell's-law bending.
The reflection and refraction directions follow the exact geometric-optics equations, so angles obey the law of reflection and Snell's law faithfully. It is a ray (geometric) model, however, so it ignores wave effects such as diffraction, interference and partial reflection, and it treats glass as having a single fixed index with no dispersion.
Geometric ray tracing designs camera lenses, microscopes, telescopes and periscopes, predicts how light travels in optical fibres and prisms, and is the foundation of photorealistic rendering in films and games. Laser-maze security beams and laser-show choreography rely on the same reflect-and-redirect principles you experiment with here.