Spherical Pendulum

Details

Platform
  • Web browser
Engine/Language
  • Unity and C#
Project
  • Individual project

About This Project

This is the next installment of something I call "programmer art" which I do quite frequently (previously I did a Spirograph, the Mandelbrot Set and Marching Squares) and this weekend the YouTube shorts algorithm sneaked some cool videos of people using buckets filled with paint attached to a pendulum and letting it swing freely across a canvas to create art.
See:

I wanted to recreate this in Unity. So.. Off to starting a new project! Trying to figure out how to paint onto a canvas (basically just texture painting) where I found this really helpful video that allowed me to create the desired effect in about a day.

Then I went fully down the rabit hole of pendulums.. and oh boy.. I knew that simulating physics is hard - but I was like - its only a pendulum. How hard could it be... Looking at the wikipedia entry already gave me a headache, so I started looking at YouTube, maybe someone already did this? Turns out - most people implemented 2D pendulums, so.. Couldnt be too hard to extrapolate from 2D to 3D.. Creating a 2D pendulum with the help of my favorite coding YouTuber The Coding Train turned out to be easy.

A week later on the next weekend I've manged to twist my brain around the algorithms described on Wikipedia and some research papers also helped and now I got the pendulum fully implemented!

Here is how it works

I am using the Lagrangian mechanics described on the Wikipedia article for spherical pendulums (link above) to calculate the x,y and z coordinates for the pendulum.

It is important to note that when Phi (ϕ) = 0, the pendulum behaves like a normal 2D pendulum, swinging side to side without any angular rotation.
The simulation is also displaying the trajectory for the initial swing with a white curve whenever you change the values of the simulation.
You can export and download the art you created via the "EXPORT CANVAS" button.

Some Gifs of what I created with the simulation

Contact me

Please reach me at marc.kletz@hotmail.com if you want to get in touch.