Skip to content

Commit

Permalink
Move G from instance variable to outer constant, see #88
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Mar 16, 2023
1 parent 424d590 commit d55f4e6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions js/common/model/NumericalEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Body> ) {
super( bodies );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
}
}
Expand Down

0 comments on commit d55f4e6

Please sign in to comment.