Live Demo: https://shahaayush265.github.io/pendula
Pendula is a web-based, real-time physics visualization and motion tracking tool. It captures organic human input (like rolling a drawing tablet stylus or gently swinging a mouse) and evaluates it against the mathematical ideal of Damped Simple Harmonic Motion (SHM).
Pendula was born out of a happy accident. One day, I left my graphics tablet stylus lying horizontally on the tablet surface. I accidentally nudged it, and it began to roll to and fro. I noticed that the cursor on my screen was mimicking this periodic motion flawlessly. Watching it gradually slow down, it struck me: the physical rolling of the slightly asymmetrical pen was actually a perfect real-world example of Damped Simple Harmonic Motion. I built Pendula to track, graph, and mathematically prove that exact observation.
- Click Start Recording (Wait for the 3-second delay to position your pen).
- Physically place your stylus on its side and gently push it so it rolls back and forth.
- Watch the Blue Dot (your cursor) and the Orange Dot (the real-time math prediction) map your path.
- Let the pen settle completely. The app will Auto-Stop.
- Review the mathematical parameters of the physical friction acting on your specific pen and click Replay Motion to see how closely physical reality matches the theory.
Pendula projects your 2D cursor movement onto a 1D timeline to extract these physical parameters:
-
$A$ (Amplitude): Your initial displacement in pixels. -
$\gamma$ (Damping): The friction coefficient (how quickly the rolling pen slows down). -
$\omega$ (Angular Frequency): How fast the pen rocks back and forth. -
$\phi$ (Phase): The starting position offset.
As a JEE aspirant, you spend hundreds of hours studying the exact mechanics of Simple Harmonic Motion. A core concept in JEE physics is that SHM is simply the 1D projection of Uniform Circular Motion.
Knowing this, before I even tested the first version of the app, I suspected I could completely fool the curve-fitting algorithm. Since the app uses Principal Component Analysis (PCA) to find the primary axis and projects your 2D motion onto that 1D line, I realized I didn't actually have to draw a pendulum swing to get a 99% score.
Here are the three mathematical loopholes I used to break my own app:
If you draw concentric circles moving steadily inward, you are drawing a damped polar curve:
A Figure-8 is a Lissajous curve. If you draw it with a decreasing radius, its 1D projection across the primary axis generates a highly periodic, decaying wave. While slightly chaotic, it easily tricks the Simulated Annealing algorithm into finding a "good enough" local minimum that looks like Damped SHM.
The most powerful cheat of all. The standard SHM equation is 0 and sets the phase (0, reducing the equation to:
To fix these loopholes, Pendula now features a mathematical tripwire system:
- Orthogonal Variance Check: It calculates how much you move perpendicular to the main PCA axis. If your perpendicular spread is >15% of your main spread, it knows you are drawing 2D shapes (Spirals/Figure-8s) instead of staying on a 1D line.
- Path-Length Ratio Check: A true pendulum swings back and forth, meaning the total distance the cursor travels must be far greater than the maximum spread of the swing. If the path length is roughly equal to the spread, the app knows you just drew a straight line.
Try the pre-loaded .motion files in the "Cheats" menu to see the anti-cheat system in action!
- Omnidirectional 2D Tracking: Swing your cursor in any direction. Pendula dynamically tracks your primary axis.
- Live Predictive Fit: A background optimization engine calculates a live mathematical prediction of where your pen should be in real-time.
-
Deep Post-Analysis: Once the motion settles, a secondary deep-fit calculation generates the absolute optimal model equation and outputs a "Similarity Score" (
$R^2$ fit). - Overlay Replay: Watch your raw, human motion race against the perfectly calculated mathematical model.
-
The
.motionFile Standard: Save, export, and load your custom.motiontelemetry files to build a personal library of physics experiments. - Glassmorphic UI: Modern, responsive design featuring a seamless, auto-detecting Light/Dark mode.
The repository includes a dedicated /examples/ folder containing pristine tests and the cheat files mentioned above.
- Note for local development: If you want to load the
.motionfiles from the UI, you must run a local web server (like VSCode Live Server orpython -m http.server). Browsers block fetch requests to local directories for security reasons.
- Vanilla HTML5 / CSS3 / ES6 JavaScript
- HTML Canvas API
- Custom implementation of Monte Carlo + Simulated Annealing optimization algorithms.
- No external libraries or dependencies.
- JEE-level love :)