From d55f4e68c494be3d6f31d64e7085e5ad2ca9c6f6 Mon Sep 17 00:00:00 2001 From: Sam Reid Date: Wed, 15 Mar 2023 23:54:06 -0600 Subject: [PATCH] Move G from instance variable to outer constant, see https://github.com/phetsims/my-solar-system/issues/88 --- js/common/model/NumericalEngine.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/js/common/model/NumericalEngine.ts b/js/common/model/NumericalEngine.ts index 091a1dc5..28b4e0b8 100644 --- a/js/common/model/NumericalEngine.ts +++ b/js/common/model/NumericalEngine.ts @@ -23,10 +23,10 @@ const XI = 0.1786178958448091; const LAMBDA = -0.2123418310626054; const CHI = -0.06626458266981849; -export default class NumericalEngine extends Engine { +// Gravitational constant +const G = 10000; - // Gravitational constant - private readonly G = 10000; +export default class NumericalEngine extends Engine { public constructor( bodies: ObservableArray ) { super( bodies ); @@ -100,7 +100,7 @@ export default class NumericalEngine extends Engine { const direction = scratchVector.set( positions[ j ] ).subtract( positions[ i ] ); const distance = direction.magnitude; assert && assert( distance >= 0, 'Negative distances not allowed!!' ); - const forceMagnitude = this.G * mass1 * mass2 * ( Math.pow( distance, -3 ) ); + const forceMagnitude = G * mass1 * mass2 * ( Math.pow( distance, -3 ) ); const force = direction.multiplyScalar( forceMagnitude ); forces[ i ].add( force ); @@ -212,7 +212,7 @@ export default class NumericalEngine extends Engine { const direction: Vector2 = body2.positionProperty.value.minus( body1.positionProperty.value ); const distance = direction.magnitude; assert && assert( distance > 0, 'Negative distances not allowed!!' ); - const forceMagnitude = this.G * body1.massProperty.value * body2.massProperty.value * ( Math.pow( distance, -3 ) ); + const forceMagnitude = G * body1.massProperty.value * body2.massProperty.value * ( Math.pow( distance, -3 ) ); return direction.times( forceMagnitude ); } }