Using beam tracing to calculate reflections in JavaScript

I have been researching beam tracing for a project of mine for a while now. Beam tracing is a method for calculating reflection paths. I won’t go into any details of how beam tracing works, as this is something you can find on google in case you’re not familiar with it.

My first attempt at beam tracing was made in Python, about a year ago. I made an algorithm that worked in 3D, but it became exceedingly complicated as I worked on it (mostly related to occlusion and clipping). As it turned out, I was overcomplicating things.ย The paper “Accelerated beam tracing algorithm” by Laine et al. served as an excellent introduction into how basic beam tracing should be done: as simply as possible. To get a better understanding of the paper, I decided to try to implement some of the very basics in 2D using JavaScript.

The result

Open simulation

Click to place the source, the specular reflections are updated automatically as you move the mouse around. Note that reflections are only calculated up to a certain limit (theoretically there are an infinite amount of reflections).

Firstly, it should be noted that I only utilised the very basic ideas presented in the paper in my implementation (beam trees and accelerated ray tracing). I only wanted to spend a few days on this, which means that there are probably a lot of things which could (and should) be optimised. I spent most of the time pruning out bugs, which at times were very hard to find. I also pushed the MIT-licensed source code to Bitbucket, in the hopes that someone might think of something useful to do with 2D beam tracing in JavaScript!

2 thoughts on “Using beam tracing to calculate reflections in JavaScript

  1. Andreas Melcher

    Hi Kai,

    I am working on some js acoustic tools and when I saw your fem and beam tracing tools I had to write you, because its very obvious that we have some overlapping interests ๐Ÿ™‚

    I tried to download the applied acoustics article that you have mentioned in your code. Unfortunately there seems to be a problem with the “full text” button on the download page. In fact I should be able to download it over my university acount. but it doesn’t matter. I’ve downloaded your js code from bitbucket. I think about using some of it for one of my planned tools.

    I also want to do some research on the feasibility to use a fem to calculate modes of non-rectangular rooms based on the UI of my room mode calculator . But thats in the far future.

    Thanks for your really interesting work. I would be happy to read from you.

    1. Kai Post author

      Hi Andreas!

      I checked out your homepage, overlapping interests indeed (mein Deutsch ist slecht, but google translate does wonders)! ๐Ÿ™‚

      I really like the tool you made for analyzing room modes in rectangular rooms. It’s clear and intuitive.

      Feel free to use the js beam tracer (it’s MIT licensed)! I’ve seen people do some cool stuff with it. Let me know if you stumble upon problems/bugs.

      FEM would definitely be feasible. I think the calculations need to be done on the server, which raises the questions related to server resources. But if we’re just examining low frequencies, it should be fine. And there are ways to do some linear algebra client side, using javascript, I think?

      I have to run now, but I’d love to talk more with you! Feel free to contact me by email.


Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.