Visualising relativistic length contraction in 2D

Showing unwarped shapes and relativistically warped shapes superpositioned can be confusing, but interesting!

I created a program so that students can visualise relativistic length contraction better. When we teach it in Year 13 to our students, we teach that the proper length is contracted by a factor gamma, which depends on the relative speed of the observer and the body being observed. The problem is, this is all a bit too one-dimensional.

This visualisation was inspired by the MIT game called A Slower Speed of Light (available here). In that game, players must collect magic watermelons or something to slow down the speed of light, making relativistic effects observable. There were a few issues with the game. Firstly, it’s a game, and collecting the magic watermelons is tedious when I just want to show something to students. Secondly, the game is in 3-D, making it a little too resource-intensive for my work laptop. I could bring my nice gaming laptop from home to run it, but I would prefer not to. Since my old pink laptop died, I’ve been looking for alternatives.

Here is a regular array of rectangles. The ‘ship’ is stationary relative to the rectangles.
Two-dimension length contraction visualised using QBASIC code. In the ‘ship’s’ reference frame, the rectangles are moving vertically, and so lengths are contracted. Only the radial component of velocity causes length contraction. The straight edges would actually be curved, but the position of the vertices are correct

I was able to get A Slower Speed of Light to run on my Chromebook, believe it or not, at about 0.5 frames per second. It’s unplayable, and the tedium of collecting magic watermelons is augmented my the poor frame rate and slow response time of the controls. Nevertheless, running it within BOX64, I was able to get it to run.

But, hey, I’m a programmer (of sorts), so surely I could whip something up myself?

The regular array of rectangles look very different when moving through them. The vertex angles are particularly interesting

A few hours later, and here we have it. A two-dimensional simulation that runs pretty well. It uses Dosbox to run QuickBASIC 4.5, but don’t hold that against me. I started coding in BASIC when I was eight years old and I never really grew out of it (a colleague once remarked that they stopped using BASIC when they ‘grew up’. Well, I haven’t).

The unwarped square is shown in white. The yellow shape is the same shape, but with length contraction visualised. Here, the curvature of the straight lines is visible.

I like BASIC. It’s clear, easy to understand, and fairly forgiving. Sure, I could code this in Java, but I’d have to learn Java first. Or C++, but I’d have to learn C++ first. Or Python with Pygame, but I’d… you get the point. I have coded in C before, and Python lots, but I don’t like them and I’d spend so long looking up syntax that it really isn’t worth it for what I wanted to do. BASIC did what I wanted. BASIC is fine.

Watch the video below!

If you want to play with it yourself, open Dosbox, install QBASIC or QuickBASIC, and save the code below in plain text as a .BAS file. Open and enjoy.

Addendum, 2025-05-23:

Soon after writing this blog post, and as a personal challenge to myself, I decided to translate the code into Python. It isn’t pretty, but it works fine. I forgot to update this post until a blogger eidm wrote a post about Special Relativity and included a link to this very post. So, below is the python code I wrote. Enjoy!

If you want to read about the process of translating the code from QBASIC to Python, I wrote a blog post about it here.


Reminder: Weekly Live Tuition Sessions!

SUNDAY 11th January

GCSE Physics9:30am – 10:20amInfrared radiation
A-Level Physics10:30am – 11:20amMeasurement of specific charge
GCSE Astronomy11:30am – 12:20pmExploring the moon

If you wish to enrol on the tuition sessions and haven’t yet, then click enrol below

One thought on “Visualising relativistic length contraction in 2D

Leave a comment

Discover more from Physics with Keith

Subscribe now to keep reading and get access to the full archive.

Continue reading