From 870b82a24f57172454be952a6ad3c44c5a7649b6 Mon Sep 17 00:00:00 2001 From: Karan Mhetar Date: Sat, 16 May 2026 14:25:45 +0530 Subject: [PATCH 1/2] fix: show correct unit for acceleration vector label in BallAcceleration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The drawLabel method in ForceRenderer hardcoded "N" (Newtons) as the unit suffix for all vectors. In BallAcceleration, the acceleration vector is drawn with F/m values (m/s²), so the label incorrectly displayed "Acceleration (X.XN)". Added a `unit` option to drawLabel so callers can override the default "N". BallAcceleration now passes `{ unit: "m/s²" }` to drawVector, fixing the label to correctly show "Acceleration (X.Xm/s²)". --- app/(core)/physics/ForceRenderer.js | 3 ++- simulations/BallAcceleration.jsx | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/(core)/physics/ForceRenderer.js b/app/(core)/physics/ForceRenderer.js index f603cad..75386dc 100644 --- a/app/(core)/physics/ForceRenderer.js +++ b/app/(core)/physics/ForceRenderer.js @@ -110,7 +110,8 @@ export class ForceRenderer { let labelText = text; if (showMag && magnitude !== undefined) { - labelText = `${text} (${magnitude.toFixed(1)}N)`; + const unit = options.unit ?? "N"; + labelText = `${text} (${magnitude.toFixed(1)}${unit})`; } p.push(); diff --git a/simulations/BallAcceleration.jsx b/simulations/BallAcceleration.jsx index 272cc0e..816848c 100644 --- a/simulations/BallAcceleration.jsx +++ b/simulations/BallAcceleration.jsx @@ -222,7 +222,8 @@ export default function BallAcceleration() { accelerationForce.x / bodyRef.current.params.mass, -(accelerationForce.y / bodyRef.current.params.mass), "#ef4444", - "Acceleration" + "Acceleration", + { unit: "m/s²" } ); } From dd3cf9751ca0330ae29f6a369d16d5d23a180784 Mon Sep 17 00:00:00 2001 From: Karan Mhetar Date: Sat, 16 May 2026 14:34:33 +0530 Subject: [PATCH 2/2] fix: use correct reference height for potential energy in BallGravity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getPotentialEnergy(gravity, referenceY) computes mass * g * (position.y - referenceY). The previous referenceY of toMeters(p.height) is the canvas top in Y-up coordinates, making PE almost always a large negative number. Changed referenceY to size/2 (ball center Y when resting on the floor), so PE correctly equals 0 at ground level — consistent with BouncingBall. --- simulations/BallGravity.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simulations/BallGravity.jsx b/simulations/BallGravity.jsx index d232d95..2e6f5bc 100644 --- a/simulations/BallGravity.jsx +++ b/simulations/BallGravity.jsx @@ -226,7 +226,7 @@ export default function BallGravity() { kineticEnergy: bodyRef.current.getKineticEnergy(), potentialEnergy: bodyRef.current.getPotentialEnergy( gravity, - toMeters(p.height) + size / 2 ), }, {