From c2e1ec8b827e688491ab319f41fc6c7423e67006 Mon Sep 17 00:00:00 2001 From: samreid Date: Mon, 14 Jan 2019 22:01:03 -0700 Subject: [PATCH] Rewrite calibration in terms of CALIBRATION_SCALE, see https://github.com/phetsims/wave-interference/issues/315 --- js/common/WaveInterferenceConstants.js | 15 +++++++-------- js/common/model/SoundScene.js | 4 ++-- js/waves/model/WavesModel.js | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/js/common/WaveInterferenceConstants.js b/js/common/WaveInterferenceConstants.js index 2d031424..5f320ddb 100644 --- a/js/common/WaveInterferenceConstants.js +++ b/js/common/WaveInterferenceConstants.js @@ -24,6 +24,10 @@ define( require => { const MAJOR_TICK_LENGTH = 12; const LATTICE_PADDING = 20; + // the simulation was initially calibrated at a lattice size of 101-20x2. This scale factor maintains the same + // calibrated behavior for differing lattice sizes. + const CALIBRATION_SCALE = ( WaveInterferenceQueryParameters.latticeSize - LATTICE_PADDING * 2 ) / ( 101 - 20 * 2 ); + const WaveInterferenceConstants = { WAVE_AREA_WIDTH: 500, MAJOR_TICK_LENGTH: MAJOR_TICK_LENGTH, @@ -72,10 +76,7 @@ define( require => { FEMTO: 1E-15, // Cell that oscillates, specified as an offset from the origin of the lattice (includes damping region). - POINT_SOURCE_HORIZONTAL_COORDINATE: - Util.roundSymmetric( - 3 / 61 * ( WaveInterferenceQueryParameters.latticeSize - LATTICE_PADDING * 2 ) + LATTICE_PADDING - ) + 1, + POINT_SOURCE_HORIZONTAL_COORDINATE: Util.roundSymmetric( 3 * CALIBRATION_SCALE ) + LATTICE_PADDING, // The lattice must have an odd dimension, so that there can be a cell exactly in the middle (for a single-cell // oscillator), symmetry for the two oscillator screen, and so the 1-cell wide barrier can appear directly in the @@ -95,10 +96,8 @@ define( require => { // rest of the texts TIME_AND_LENGTH_SCALE_INDICATOR_FONT: new PhetFont( DEFAULT_FONT_SIZE - 1 ), - // tuned so that the time for the wave to pass across the lattice is the same as pre-1.0. If the lattice size is - // changed, this can be re-tuned by computing the time it takes a sound wave to cross the new lattice size and - // dividing by the prior time. - SCALE_FACTOR: 54.176 / 20 + // see above + CALIBRATION_SCALE: CALIBRATION_SCALE }; assert && assert( WaveInterferenceConstants.LATTICE_DIMENSION % 2 === 1, 'lattice dimension must be odd' ); diff --git a/js/common/model/SoundScene.js b/js/common/model/SoundScene.js index 3329cd49..344668d2 100644 --- a/js/common/model/SoundScene.js +++ b/js/common/model/SoundScene.js @@ -111,8 +111,8 @@ define( require => { const fy = gradientY * k; if ( !isNaN( fx ) && !isNaN( fy ) ) { soundParticle.applyForce( - fx * WaveInterferenceConstants.SCALE_FACTOR, - fy * WaveInterferenceConstants.SCALE_FACTOR, + fx * WaveInterferenceConstants.CALIBRATION_SCALE, + fy * WaveInterferenceConstants.CALIBRATION_SCALE, dt, this ); } diff --git a/js/waves/model/WavesModel.js b/js/waves/model/WavesModel.js index 8c7cae0b..def00425 100644 --- a/js/waves/model/WavesModel.js +++ b/js/waves/model/WavesModel.js @@ -54,7 +54,7 @@ define( require => { // This simulation uses EventTimer, which provides exactly the same model behavior on very slow and very fast // platforms. Here we define the frequency of events in Hz, which has been tuned so that iPad2 has enough time to run // model computations. - const EVENT_RATE = 20 * WaveInterferenceConstants.SCALE_FACTOR; + const EVENT_RATE = 20 * WaveInterferenceConstants.CALIBRATION_SCALE; const toFemto = WaveInterferenceUtils.toFemto; class WavesModel {