c0nrad's c0rner

Learning and learning

Sep 22, 2022 - 2 minute read

Sim 11: Ray Tracing Telescope

Today’s project was building a little ray tracing telescope with a fake CCD. You can play with it here:

https://blog.c0nrad.io/sims/teleray/

/teleray.png

(code)

Background

I have a homework assignment involving the calculation of some quantity related to a Cassegrain telescope. So being the procrastinator I am, I decided to instead build a little ray tracer telescope model instead.

Really I just wanted to play with building different types of lenses and mirrors and have some fun. And I figured it’d look neat.

How it works

Mirrors

The model renders the primary and secondary mirror first. To generate these objects I use a “Lathe” geometry, where I define a line and ThreeJS will rotate the line around to build a surface. This allows me to generate lenses and mirrors of arbitrary shape.

Walls

Next I generate the struts that block the light. These items are used in the collision detection to block the rays of light.

CCD

At the bottom there is a fake CCD, when a ray hits the device it records which cell and saves to a counts matrix for displaying later.

Rays

Rays are generated by following the path and seeing what object they collide with.

It the ray collides with a Wall, it is stopped. If it collides with a mirror, it’ll calculate the normal vector and then the reflection angle.

If the ray hits a CCD the count is recorded.

Interface

The interface is build using Angular. You’re able to adjust a number of parameters of the mirror including radius, position, etc.

What went well?

  • Graphics on ThreeJS always look neat
  • The CCD capture code was super simple, and looks cool

What did not go well

  • Collision detection (ray caster)
    • Due to some ThreeJS internals, you’re supposed to update the world matrix to get ray casting to work after moving an object. The object will be in the correct spot on the screen, but not in some internal matrix. I spent a good few hours trying to figure out why my collisions were off.
    • Surfaces by default are not double sided, so collisions only happen one way, combined with the previous issue, it was very frustrating to debug

Future

Probably nothing. The following things could be cool, but I probably won’t do them. I should be studying.

  • Use wavefronts instead of light points to model diffraction.
  • Add point sources of light instead of collimated light