Share via


Lasers reflecting off an ellipse

Various conic sections (hyperbolas, parabolas, ellipses) have interesting reflective properties. Parabolas are used for antennae and even car headlight and flashlight reflectors to focus a beam of light.

image

In the last post https://blogs.msdn.microsoft.com/calvin_hsia/2018/02/28/reflect-laser-beams-off-multiple-mirrors I showed some code to bounce a laser off various mirrors that the user can draw on the screen. I also mentioned that an elliptically shaped water tank will reflect waves and that Lithotripter uses ellipses to remove kidney stones
Let’s enhance that code:
•    Add an ellipse
•    Allow multiple lasers, initially emanating from a single point, thus simulating a point source of light
•    Added a context menu that allows the user to set the initial laser point. E.g. what happens if you put the lasers initially at a focus of the ellipse?
•    Added an options dialog that allows the user to control the number of lasers

The code involves multiple files, one of which has 1300 lines and thus is hard to publish as a single blog entry, so I’ve put it at https://github.com/calvinhsia/ReflectCpp
Just clone the repo locally, open the solution ReflectCPP.sln and run it.

Note how the code has multiple kinds of mirrors (currently 2), all of which implement an interface IMirror, which has methods like Draw, IntersectingPoint and Reflect

Things to try:
•    Slow it down, use 1 laser, watch how it reflects off the ellipse walls
•    Use your mouse and draw a mirror or several and watch how it affects the pattern.
•    Try to isolate the light into patterns stuck in just a portion of the ellipse without a mirror touching the ellipse (try setting the laser count to 1 first)

The name “ReflectCPP” implies it is the C++ version of the code, and that there’s another version. Next time!
The patterns generated from the code are pretty remarkable. You can see the symmetry around the focal points (the little dots)