From 5c47f1e7c4d9acb529b1e47ff8a30d607fbe4133 Mon Sep 17 00:00:00 2001 From: samreid Date: Mon, 7 Jan 2019 18:44:43 -0700 Subject: [PATCH] Increase damping coefficient and use gradual reduction for masking, see https://github.com/phetsims/wave-interference/issues/304 --- js/common/model/Lattice.js | 6 +++--- js/common/model/Scene.js | 2 +- js/common/model/TemporalMask.js | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/js/common/model/Lattice.js b/js/common/model/Lattice.js index ab1a9593..117b87fc 100644 --- a/js/common/model/Lattice.js +++ b/js/common/model/Lattice.js @@ -22,7 +22,7 @@ define( require => { const WAVE_SPEED = 0.5; const WAVE_SPEED_SQUARED = WAVE_SPEED * WAVE_SPEED; // precompute to avoid work in the inner loop const NUMBER_OF_MATRICES = 3; // The discretized wave equation algorithm requires current value + 2 history points - const DAMPING_COEFFICIENT = 0.999; // wave values scaled by this much at each frame to wash out numerical artifacts + const DAMPING_COEFFICIENT = 0.9999; // wave values scaled by this much at each frame to wash out numerical artifacts // This is the threshold for the wave value that determines if the light has visited. If the value is higher, // it will track the wavefront of the light more accurately (and hence could be used for more accurate computation of @@ -193,9 +193,9 @@ define( require => { * @param {number} j * @public */ - clearCell( i, j ) { + reduceCell( i, j ) { for ( let k = 0; k < NUMBER_OF_MATRICES; k++ ) { - this.matrices[ k ].set( i, j, 0.0 ); + this.matrices[ k ].set( i, j, this.matrices[ k ].get( i, j ) * 0.95 ); } this.visitedMatrix.set( i, j, 0 ); } diff --git a/js/common/model/Scene.js b/js/common/model/Scene.js index f32f52e3..abd58683 100644 --- a/js/common/model/Scene.js +++ b/js/common/model/Scene.js @@ -618,7 +618,7 @@ define( require => { const cameFrom2 = this.temporalMask2.matches( i, j, this.stepIndex ); if ( !cameFrom1 && !cameFrom2 ) { - this.lattice.clearCell( i, j ); + this.lattice.reduceCell( i, j ); } } } diff --git a/js/common/model/TemporalMask.js b/js/common/model/TemporalMask.js index e4049169..96b9bbba 100644 --- a/js/common/model/TemporalMask.js +++ b/js/common/model/TemporalMask.js @@ -70,8 +70,9 @@ define( require => { const theoreticalTime = time - distance / Lattice.WAVE_SPEED; // if theoreticalDistance matches any time in this range, then we have a winner - const tolerance = 4; - if ( theoreticalTime >= startTime - tolerance && theoreticalTime <= endTime + tolerance ) { + const headTolerance = 4; + const tailTolerance = 4; + if ( theoreticalTime >= startTime - headTolerance && theoreticalTime <= endTime + tailTolerance ) { // Return as early as possible to improve performance return true;