From a4584262823d91f70c302f90d10cc1c9fbd15c98 Mon Sep 17 00:00:00 2001 From: Karan Mhetar Date: Fri, 22 May 2026 16:28:33 +0530 Subject: [PATCH] fix: show height above lowest point in SimplePendulum info panel The Height field in the info panel was displaying -position.y, which is the negated Y-up physics coordinate. Since the anchor sits high up in physics space, this always showed a large negative number unrelated to the pendulum's actual swing height. Fix: compute height as position.y - (anchor.y - length), which gives the height above the bob's lowest point (equilibrium). This reads 0 m at rest and increases correctly as the bob swings up. --- app/(core)/data/configs/SimplePendulum.js | 2 +- simulations/SimplePendulum.jsx | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/(core)/data/configs/SimplePendulum.js b/app/(core)/data/configs/SimplePendulum.js index 3eef52f..e3f9e82 100644 --- a/app/(core)/data/configs/SimplePendulum.js +++ b/app/(core)/data/configs/SimplePendulum.js @@ -91,7 +91,7 @@ export const SimInfoMapper = (bodyState) => { return { Angle: `${angle.toFixed(1)}°`, "Angular Velocity": `${bodyState.angularVel.toFixed(2)} rad/s`, - Height: `${(-bodyState.position.y).toFixed(2)} m`, + Height: `${bodyState.height.toFixed(2)} m`, Speed: `${bodyState.velocity.mag().toFixed(2)} m/s`, KE: `${bodyState.kineticEnergy.toFixed(2)} J`, PE: `${bodyState.potentialEnergy.toFixed(2)} J`, diff --git a/simulations/SimplePendulum.jsx b/simulations/SimplePendulum.jsx index 8b1094d..10b0d16 100644 --- a/simulations/SimplePendulum.jsx +++ b/simulations/SimplePendulum.jsx @@ -292,6 +292,9 @@ export default function Pendulum() { velocity: bodyRef.current.state.velocity, angularVel: bodyRef.current.angularVel, angleRad: bodyRef.current.getAngle(), + height: + bodyRef.current.state.position.y - + (bodyRef.current.anchor.y - bodyRef.current.length), kineticEnergy: bodyRef.current.getKineticEnergy(), potentialEnergy: bodyRef.current.getPotentialEnergy( inputsRef.current.gravity