<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ayush</title>
    <description>The latest articles on DEV Community by ayush (@ayush_42a26f94890ecb20d44).</description>
    <link>https://dev.to/ayush_42a26f94890ecb20d44</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3660504%2F32a25738-05b2-4546-b07a-027556adabca.png</url>
      <title>DEV Community: ayush</title>
      <link>https://dev.to/ayush_42a26f94890ecb20d44</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ayush_42a26f94890ecb20d44"/>
    <language>en</language>
    <item>
      <title>Building SolitonPlay: A Physics Playground for Everyone</title>
      <dc:creator>ayush</dc:creator>
      <pubDate>Sat, 28 Nov 2026 11:01:17 +0000</pubDate>
      <link>https://dev.to/ayush_42a26f94890ecb20d44/building-solitonplay-a-physics-playground-for-everyone-1c9k</link>
      <guid>https://dev.to/ayush_42a26f94890ecb20d44/building-solitonplay-a-physics-playground-for-everyone-1c9k</guid>
      <description>&lt;h1&gt;
  
  
  I Built a Physics Simulation Engine Because My Sister's Students Couldn't Visualize Physics
&lt;/h1&gt;

&lt;p&gt;I'm a software engineer, and I love physics.&lt;/p&gt;

&lt;p&gt;A while ago, my sister, who teaches Class 8 and 9, told me that some of her students were struggling to understand physics concepts.&lt;/p&gt;

&lt;p&gt;They could read the textbook. They could look at equations. But understanding what was actually happening was a different story.&lt;/p&gt;

&lt;p&gt;That conversation stayed with me.&lt;/p&gt;

&lt;p&gt;I started thinking: what if students could experiment with physics instead of only reading about it?&lt;/p&gt;

&lt;p&gt;What if they could change a parameter, move an object, adjust a spring, or build a scenario themselves and immediately see what happens?&lt;/p&gt;

&lt;p&gt;That's how &lt;strong&gt;SolitonPlay&lt;/strong&gt; started.&lt;/p&gt;

&lt;h2&gt;
  
  
  It started as a small project
&lt;/h2&gt;

&lt;p&gt;Initially, I just wanted to build something my sister could use with her students.&lt;/p&gt;

&lt;p&gt;I simply wanted to make physics easier to explore.&lt;/p&gt;

&lt;p&gt;But I love physics, and once I started building, I kept finding more things I wanted to simulate. One idea led to another, and the project gradually grew beyond its original purpose.&lt;/p&gt;

&lt;p&gt;What began as a small educational experiment became a physics simulation playground and an engine that developers can use through Python and JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why simulations?
&lt;/h2&gt;

&lt;p&gt;I think there's a difference between knowing an equation and understanding the phenomenon behind it.&lt;/p&gt;

&lt;p&gt;You can teach a student the formula for a spring's restoring force. But what happens when you change the spring constant? What happens when two objects interact? What if you build a scenario that wasn't in the textbook?&lt;/p&gt;

&lt;p&gt;A simulation gives students a way to investigate those questions themselves.&lt;/p&gt;

&lt;p&gt;They can experiment, make predictions, get unexpected results, and try again.&lt;/p&gt;

&lt;p&gt;The goal is to give learners another way to develop intuition.&lt;/p&gt;

&lt;h2&gt;
  
  
  The interesting part: letting people experiment
&lt;/h2&gt;

&lt;p&gt;One of my favorite things is seeing students try things I never explicitly designed for them to try.&lt;/p&gt;

&lt;p&gt;They don't always follow predefined examples. Sometimes they build unusual scenarios and produce behavior that surprises them.&lt;/p&gt;

&lt;p&gt;That is part of what makes a physics playground interesting: the user isn't limited to following instructions. They can explore.&lt;/p&gt;

&lt;p&gt;It also creates an engineering challenge. When a result looks unexpected, I need to investigate whether it's physically correct, a limitation of the model, or a numerical issue.&lt;/p&gt;

&lt;p&gt;That distinction matters. A simulation should not merely look convincing; its behavior should be grounded in the physics it's trying to represent.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building it as an engineer
&lt;/h2&gt;

&lt;p&gt;The project has also become an opportunity to explore the engineering behind physics simulations.&lt;/p&gt;

&lt;p&gt;I wanted the underlying engine to be usable beyond the browser, so I made Python and JavaScript packages available as well.&lt;/p&gt;

&lt;p&gt;That opens up different possibilities: students can experiment visually, while developers and educators can integrate simulations into their own programs and workflows.&lt;/p&gt;

&lt;p&gt;It's been a learning experience in both physics and software engineering. Getting something to run is one challenge; making it reusable, understandable, and trustworthy is another.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I'm keeping it free
&lt;/h2&gt;

&lt;p&gt;I want students and teachers to be able to use the project without having to think about whether they can afford it.&lt;/p&gt;

&lt;p&gt;I'm building it alongside my regular engineering work, so progress won't always be fast. But I'd rather keep improving it sustainably than turn it into something I no longer enjoy building.&lt;/p&gt;

&lt;p&gt;For me, the project's value isn't measured only by downloads or stars.&lt;/p&gt;

&lt;p&gt;It's measured by whether someone can use it to understand something they previously found difficult.&lt;/p&gt;

&lt;h2&gt;
  
  
  I'd love your feedback
&lt;/h2&gt;

&lt;p&gt;SolitonPlay is available here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Project and documentation:&lt;/strong&gt; &lt;a href="https://solitonplay.com" rel="noopener noreferrer"&gt;https://solitonplay.com&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you're a physics teacher, student, developer, or someone who enjoys scientific computing, I'd love to hear from you.&lt;/p&gt;

&lt;p&gt;What physics concepts are difficult to understand through traditional explanations? What would you want to experiment with in a simulation playground? And what would make a tool like this genuinely useful in a classroom?&lt;/p&gt;

&lt;p&gt;I'm still building, learning, and figuring out what it can become.&lt;/p&gt;

&lt;p&gt;The original motivation remains the same: I love physics, and I want to help more people understand it.&lt;/p&gt;

&lt;p&gt;If even one student eventually tells me, "I finally understand it now," I'll consider that time well spent.&lt;/p&gt;

</description>
      <category>physics</category>
      <category>maths</category>
      <category>simulation</category>
      <category>rust</category>
    </item>
    <item>
      <title>Curved ramps in a 2D physics engine, and the ball that looked like it was being hit 500 times a second</title>
      <dc:creator>ayush</dc:creator>
      <pubDate>Fri, 27 Nov 2026 19:14:07 +0000</pubDate>
      <link>https://dev.to/ayush_42a26f94890ecb20d44/curved-ramps-in-a-2d-physics-engine-and-the-ball-that-looked-like-it-was-being-hit-500-times-a-25ji</link>
      <guid>https://dev.to/ayush_42a26f94890ecb20d44/curved-ramps-in-a-2d-physics-engine-and-the-ball-that-looked-like-it-was-being-hit-500-times-a-25ji</guid>
      <description>&lt;p&gt;I build &lt;strong&gt;&lt;a href="https://solitonplay.com" rel="noopener noreferrer"&gt;Soliton&lt;/a&gt;&lt;/strong&gt;, a physics engine in Rust that compiles to WebAssembly and runs in the browser. It powers 151 interactive simulations of school physics, and a sandbox where you build your own.&lt;/p&gt;

&lt;p&gt;Someone sent me a video: a block slides down a curved ramp and hits a second block sitting on a spring, with a pendulum hanging under it. Could Soliton do that?&lt;/p&gt;

&lt;p&gt;Almost. It had no curves.&lt;/p&gt;

&lt;p&gt;This post is about adding them properly. It covers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;why a chain of flat pieces is the wrong answer,&lt;/li&gt;
&lt;li&gt;representing a curve so the engine can be exact about it,&lt;/li&gt;
&lt;li&gt;contact between a curve and a ball, and between a curve and a box,&lt;/li&gt;
&lt;li&gt;testing it all against textbook physics,&lt;/li&gt;
&lt;li&gt;and the two bugs those tests caught, one of them in the solver itself.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Try it first:&lt;/strong&gt; open the &lt;a href="https://solitonplay.com/play?mode=mechanics&amp;amp;sandbox" rel="noopener noreferrer"&gt;sandbox&lt;/a&gt; and press &lt;strong&gt;U&lt;/strong&gt; to drop a curved ramp. Free, no sign-up.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Why not just chain flat pieces?
&lt;/h2&gt;

&lt;p&gt;The obvious way to fake a curve is a polyline: lots of short straight segments. It looks fine. It behaves badly.&lt;/p&gt;

&lt;p&gt;A box sliding over a polyline meets a tiny corner at every joint. Each one is a small collision. It loses a little speed, judders, and sometimes snags outright. Make the pieces smaller and you get more corners, not fewer.&lt;/p&gt;

&lt;p&gt;So curves had to become a real shape in the engine.&lt;/p&gt;

&lt;h2&gt;
  
  
  The representation: a turtle path
&lt;/h2&gt;

&lt;p&gt;A track is a list of pieces. Each one starts where the last ended, heading the same way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="nc"&gt;TrackPiece&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;/// Straight ahead for this many metres.&lt;/span&gt;
    &lt;span class="nc"&gt;Line&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;/// Turn through `angle` radians on a circle: positive left, negative right.&lt;/span&gt;
    &lt;span class="nc"&gt;Arc&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;angle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;f64&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;/// A sharp turn on the spot: a floor meeting a wall, a ledge dropping away.&lt;/span&gt;
    &lt;span class="nc"&gt;Corner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because each piece leaves in the direction the previous one was heading, &lt;strong&gt;the tangent is continuous at every join by construction&lt;/strong&gt;, unless you explicitly ask for a corner. You can't accidentally build a kink.&lt;/p&gt;

&lt;p&gt;In a scene file, a U-shaped valley looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"track"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"pieces"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"arc"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"radius"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"angle"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.5708&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"line"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"arc"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"radius"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"angle"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.5708&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why only lines and circular arcs, and not Bézier curves or splines? Because for a line or a circle, &lt;strong&gt;the closest point to anything has an exact, closed-form answer&lt;/strong&gt;: a projection for a line, a radial line for an arc. Collision detection becomes exact geometry instead of iterative root-finding. Lines and arcs can still approximate any curve you want.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thick and two-sided
&lt;/h2&gt;

&lt;p&gt;The track is a centre line thickened by half its thickness on each side. That has two nice consequences:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;It's solid from both faces.&lt;/strong&gt; The same curve holds a ball inside it as a bowl and carries one over it as a hump.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collision is "distance to a curve".&lt;/strong&gt; A ball touches the track when the distance from its centre to the centre line is less than its radius plus half the thickness.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Contact with a ball
&lt;/h2&gt;

&lt;p&gt;For each segment, find the closest point to the ball's centre. Then deal with one subtlety: &lt;strong&gt;a point near a joint is closest to &lt;em&gt;both&lt;/em&gt; neighbouring segments at the joint itself&lt;/strong&gt;, and you don't want two identical contacts.&lt;/p&gt;

&lt;p&gt;The rule: if a segment's closest point was clamped to its end, the next segment will find that same point or a nearer one, so drop it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;keep&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;match&lt;/span&gt; &lt;span class="n"&gt;along&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Along&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;Interior&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;// A joint is kept once, by the segment after it, and only when both sides end there.&lt;/span&gt;
    &lt;span class="nc"&gt;Along&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;End&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;last&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;Along&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;Start&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;found&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nc"&gt;Along&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;End&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A ball over a joint touches once. A ball wedged in a narrow valley touches both walls, because those are two distinct places.&lt;/p&gt;

&lt;h2&gt;
  
  
  Contact with a box
&lt;/h2&gt;

&lt;p&gt;A convex polygon meets a smooth curve in exactly two ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;A corner of the box touches the curve.&lt;/strong&gt; This is how a box sits in a bowl: two corners on the curve.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The curve touches the middle of a face.&lt;/strong&gt; This is how a box sits on a hump. It can only happen where the curve runs parallel to the face, which on an arc is the arc's extreme point across the face:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// The arc's point furthest across the face, if the arc reaches round to it.&lt;/span&gt;
&lt;span class="nc"&gt;TrackSegment&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;Arc&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;center&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sweeps_through&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;normal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;angle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kc"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;center&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;normal&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the track's two end caps and any sharp corners as points that can press into a face (that's how a box hangs over a ledge), and you have the complete contact set.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing against the textbook
&lt;/h2&gt;

&lt;p&gt;Every scene in Soliton ships with a test that holds it to an exact physical fact. Curves got the same treatment:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Test&lt;/th&gt;
&lt;th&gt;Expected&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Bead in a bowl swings like a pendulum&lt;/td&gt;
&lt;td&gt;Exact &lt;strong&gt;large-amplitude&lt;/strong&gt; pendulum period&lt;/td&gt;
&lt;td&gt;Within 0.1%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ball inside a ring, launched at 1.02 × √(5gr)&lt;/td&gt;
&lt;td&gt;Goes over the top&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Same ball at 0.9 × √(5gr)&lt;/td&gt;
&lt;td&gt;Leaves the ring at h = (u² − 2gr)/3g = &lt;strong&gt;0.9225 m&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0.9225 m&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Box sliding across a valley for 10 s&lt;/td&gt;
&lt;td&gt;Energy conserved&lt;/td&gt;
&lt;td&gt;To 1 part in 10⁵&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Box into a vertical wall (sharp corner)&lt;/td&gt;
&lt;td&gt;Elastic bounce, never passes the corner&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Box with a quarter of it over a ledge&lt;/td&gt;
&lt;td&gt;Rests perfectly still&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That leaving height is my favourite. It comes from two facts: energy conservation, and the normal force reaching zero where gravity's inward pull alone supplies the centripetal force. The engine computes neither. It just integrates forces and resolves contacts, and the ball still lets go exactly where the algebra says.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bug 1: a steady push that looked like a hammer
&lt;/h2&gt;

&lt;p&gt;The ring test failed at first, in a strange way. The motion was perfect: the ball stayed exactly on the circle and energy was conserved. But &lt;strong&gt;the recorded normal force flickered between its true value and zero, every other step.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here's why. The solver has to decide, for each contact, whether this is a &lt;strong&gt;resting contact&lt;/strong&gt; (a steady push) or an &lt;strong&gt;impact&lt;/strong&gt; (a collision, which gets restitution and bounces). It decides by how fast the surfaces are approaching. If they're closing faster than the applied forces could explain within a few steps, it's an impact:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;pushed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;4.0&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;accelerations&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;dt&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;1e-6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;pre&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;restitution_threshold&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pushed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ... treat as an impact, aim for a bounce&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On a flat floor, that works. On a curve it doesn't. A ball sliding along the inside of a ring closes the gap to the wall &lt;strong&gt;even with no force pressing it&lt;/strong&gt;, because going straight would carry it into the bend. The rate is κv², the curvature times the speed squared. At 8 m/s on a 1.35 m radius, that's about 50 m/s² of "approach" that the solver couldn't explain from the forces. So it decided: impact! It applied a tiny bounce. Next step the ball had separated, so there was no force. Then it came back.&lt;/p&gt;

&lt;p&gt;The fix: &lt;strong&gt;contacts now carry the curvature of the surface&lt;/strong&gt;, and the solver counts the turning motion as part of the steady push:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Riding along a curved surface closes the gap as surely as a force pressing in does.&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;pressed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;normal&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;explicit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nf"&gt;explicit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;curvature&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;pressed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;slide&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;normal&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;perp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;point_velocity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;point&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nf"&gt;point_velocity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;point&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;pressed&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;curvature&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;slide&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;slide&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every existing shape reports zero curvature, so nothing that worked before changes. After the fix, the normal force on the ball matches m(v²/r − g·h/r) to 1 part in 10,000 all the way round.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bug 2 (not a bug): the box that knocks
&lt;/h2&gt;

&lt;p&gt;A box sliding over a bump lost about 1.4% of its energy. My first instinct was to blame the joins between arcs. But a ball over the same bump lost nothing.&lt;/p&gt;

&lt;p&gt;The box is right. Where the curve switches from bending down (the crest) to bending up (the dip), a rigid flat-bottomed box has to switch from rotating one way to rotating the other. There's no smooth way to do that, so its leading corner strikes the surface. That's a real collision, and with no bounce it really does absorb energy. The test now checks that this loss is booked as dissipated energy, not that it's zero.&lt;/p&gt;

&lt;h2&gt;
  
  
  The loop you can't build
&lt;/h2&gt;

&lt;p&gt;One thing a flat world can't have: a loop-the-loop with a run-in and a run-out.&lt;/p&gt;

&lt;p&gt;The ball's path has to cross itself. At the crossing, the ball passes along branch A past branch B, and later along B past A. For a two-sided track, both crossings are blocked. For a one-sided track, work out which side of each branch the ball approaches from. If d_A × d_B is the cross product of the two directions, passing B needs it negative and passing A needs it positive. &lt;strong&gt;You can't have both.&lt;/strong&gt; Real roller-coaster loops escape by shifting sideways in the third dimension. A closed ring works fine, which is all the textbook problem needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus: simple harmonic motion as a shadow
&lt;/h2&gt;

&lt;p&gt;With springs getting heavier use, I added the textbook's &lt;strong&gt;reference circle&lt;/strong&gt;: beside any body on a spring, a point goes round a circle at a steady rate, its shadow tied to the mass, while a displacement–time graph draws itself out of the circle.&lt;/p&gt;

&lt;p&gt;It isn't an animation of a formula. Amplitude and phase are computed live from the mass, the stiffness and the actual motion, so if friction or a collision changes the swing, the circle changes with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Playground:&lt;/strong&gt; &lt;a href="https://solitonplay.com" rel="noopener noreferrer"&gt;solitonplay.com&lt;/a&gt;. Press &lt;strong&gt;U&lt;/strong&gt; in the sandbox for a curved ramp.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reference circle:&lt;/strong&gt; &lt;a href="https://solitonplay.com/play?mode=mechanics&amp;amp;scenario=vertical-spring" rel="noopener noreferrer"&gt;a mass on a vertical spring&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scene format:&lt;/strong&gt; &lt;a href="https://docs.solitonplay.com/mechanics/scenes/#curved-tracks" rel="noopener noreferrer"&gt;writing tracks in a scene file&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JavaScript:&lt;/strong&gt; &lt;code&gt;npm install @soliton-physics/engine&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Python:&lt;/strong&gt; &lt;code&gt;pip install soliton-physics&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you've fought collision detection on curves yourself, I'd love to hear how you solved it in the comments.&lt;/p&gt;

</description>
      <category>rust</category>
      <category>webassembly</category>
      <category>physics</category>
      <category>gamedev</category>
    </item>
  </channel>
</rss>
