Inspiration

I've stared at a mechanics question, plugged numbers into a formula, got the answer in the back of the book, and still had no idea what the ball was actually doing. My classmates do the same. The questions are about things moving, yet I only ever studied them as text, a diagram that doesn't move, and a final number.

Simulators like PhET are great, but each one is a fixed scene and it isn't your question. Solver apps hand you the answer, which helps for checking homework and doesn't help you learn it. I wanted something in between, where you type the exact problem you're stuck on and see that problem move.

What it does

You paste a word problem, the kind you'd find in NCERT/CBSE book, and NewtonLab does five things.

  1. It shows what it read. A "Here's what I understood" card lists every value it pulled out (speed, angle, masses, friction), and those numbers get colour-coded in your question so you can see where each one came from. If it misread something, you fix it before anything runs.
  2. It asks you to guess first. You type your prediction, and after the reveal it tells you how far off you were. I added this on purpose, because guessing makes you think about the physics instead of waiting for a number.
  3. It runs the simulation. The ball flies, the block slides, the pulley masses move, the trolleys crash or the spring bounces. You can scrub through time, slow it down to a quarter speed, and turn on force or velocity arrows. Strobe dots mark equal time steps, so you can see where things speed up and slow down.
  4. It shows the worked solution with your numbers plugged in, step by step, and compares it with the textbook answer.
  5. It lets you change things. Drag a slider and the path and answer update straight away, with the original path left as a dashed line. From a 10 m balcony, for example, it tells you the best throwing angle is about 36° instead of the 45° everyone memorises, and there's a button to try it.

It handles five kinds of problems so far:

Topic Example question it can do
Projectile motion a ball thrown from a balcony, a stone off a cliff, a car driving off a ledge at 54 km/h
Inclined plane a block sliding down a ramp, with or without friction
Pulleys two hanging masses (Atwood machine), or a block on a rough table pulled by a hanging mass
1D collisions elastic, perfectly inelastic, or anything in between (a bullet hitting a block, trolleys that stick together)
Spring-mass SHM period, frequency, max speed, energy

For anything else, like a pendulum or a circuit, it says "not supported yet" instead of showing a wrong simulation.

How I built it

The front end is React, TypeScript and Vite. I draw the simulations myself on an HTML canvas, and KaTeX renders the equations.

To read the question, a small serverless function sends the text to Google's Gemini API and asks for strict JSON back with the problem type and values. The API key stays on the server. The 12 example problems are pre-parsed, so they still work if the AI is down.

The answers come from exact textbook equations, written and tested in code. The AI only reads the question; it never calculates anything, and there's no game engine. That's why the numbers match the book: the football example gives 38.35 m and the textbook says 38.4 m. There are 75 automated tests, and every example problem is checked against its expected answer.

For example, a ball launched at speed \( v \) and angle \( \theta \) from height \( h \) lands after

$$t = \frac{v\sin\theta + \sqrt{(v\sin\theta)^2 + 2gh}}{g}$$

and two masses on a pulley accelerate at \( a = \frac{(m_2 - m_1)\,g}{m_1 + m_2} \). The app shows these steps with the student's own numbers plugged in.

It's hosted on Cloudflare Workers. For the look, I went for a lab notebook instead of another dashboard, with graph-paper backgrounds, ink-coloured text, a terracotta "pen" colour and a light/dark toggle.

I used an AI coding assistant to help write and debug the code. The idea, what to build and what to cut, the problem types, the design direction and all the testing (including running real textbook-style questions through the live site) were my calls.

Challenges I ran into

Early on, the AI kept dropping numbers. "A ball thrown at 15 m/s at 40° from a 10 m balcony" came back with the speed and nothing else. I fixed it by making every field required in a nested format, and went from losing values on about half my test questions to getting all of them right.

After I deployed, half the requests failed with "User location is not supported". Cloudflare runs the code at whichever data centre is closest to the visitor, and Gemini refuses requests from some of those regions. Pinning the server near Google's US region fixed it, and 17 out of 17 test questions passed afterwards.

One model took two minutes to answer. It was accurate, but it spent ages "thinking". I switched to a lighter model that answers in about a second and kept the bigger one as a backup for when the free rate limit runs out.

Real textbook questions turned out messier than mine. "Find the acceleration and the tension" got rejected because it asks for two things, and a bullet at 400 m/s broke my speed limit. I fixed both after running actual CBSE-style questions through the app.

The physics had edge cases too: a block that friction holds in place, a pushed block that stops halfway down, two equal masses on a pulley that just balance, and trolleys moving apart that never collide. Each one needed its own explanation so the app wouldn't show a strange animation.

Accomplishments that I'm proud of

Every example matches its textbook answer, and the tests keep it that way.

I'm also proud of the "not 45°" moment. Watching the best angle change as you raise the launch height made something click that I never got from the formula.

It works on a phone, in dark mode, and with reduced-motion settings. You can always see and correct what it read, and it tells you when a problem is outside what it can do.

What I learned

The AI is good at reading messy English, so that's the only job I gave it. The physics has to be right every time, so it lives in plain code with tests.

I should have tested with real inputs sooner. Most of the bugs only showed up when I pasted in questions phrased the way textbooks phrase them.

I also learned to test the deployed site and not just my laptop, because the region bug never happened locally.

Related work

I looked for similar projects. PhET has excellent simulations, but they're fixed scenes. Photo-solver apps give answers without showing any motion. The closest project I found on GitHub, AI-Physics-Visualizer, turns text into an animation for projectiles only and steps the motion numerically. NewtonLab covers five topics with exact equations and checks itself against the textbook.

What's next

I want to add pendulums, circular motion, motion up a slope and two-dimensional collisions. A photo upload would let you snap the textbook page instead of typing. I'd like to support questions in Tamil and Hindi, since a lot of students learn physics in a language other than English. And a teacher mode could project one problem for the whole class and collect everyone's predictions before the reveal.

Built With

Share this project:

Updates

Submission history