From c6c9959ca199ea8318a982fda19e64a7453a1aee Mon Sep 17 00:00:00 2001 From: samreid Date: Sun, 5 Nov 2017 17:14:14 -0700 Subject: [PATCH] Cleanup in Voltmeter, see https://github.com/phetsims/faradays-law/issues/86 --- js/faradays-law/model/Voltmeter.js | 16 ++++++++-------- js/faradays-law/view/FaradaysLawScreenView.js | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/js/faradays-law/model/Voltmeter.js b/js/faradays-law/model/Voltmeter.js index ad371773..e50bf810 100644 --- a/js/faradays-law/model/Voltmeter.js +++ b/js/faradays-law/model/Voltmeter.js @@ -36,7 +36,7 @@ define( function( require ) { this.needleAngularAcceleration = 0; // @public {NumberProperty} Needle angle in radians. This drives both the needle location and the light bulb brightness. - this.thetaProperty = new NumberProperty( 0 ); + this.needleAngleProperty = new NumberProperty( 0 ); // @private - input voltage to meter this.signalProperty = new NumberProperty( 0, { @@ -59,18 +59,18 @@ define( function( require ) { // empirically determined to make the needle move the correct amount and direction. this.signalProperty.set( -0.2 * (this.model.bottomCoil.emfProperty.get() + this.model.topCoil.emfProperty.get()) ); - this.needleAngularAcceleration = NEEDLE_RESPONSIVENESS * (this.signalProperty.get() - this.thetaProperty.get()) - NEEDLE_FRICTION * this.needleAngularVelocity; //angular acceleration of needle - this.thetaProperty.set( this.thetaProperty.get() + this.needleAngularVelocity * dt + 0.5 * this.needleAngularAcceleration * dt * dt ); //angle of needle + this.needleAngularAcceleration = NEEDLE_RESPONSIVENESS * (this.signalProperty.get() - this.needleAngleProperty.get()) - NEEDLE_FRICTION * this.needleAngularVelocity; //angular acceleration of needle + this.needleAngleProperty.set( this.needleAngleProperty.get() + this.needleAngularVelocity * dt + 0.5 * this.needleAngularAcceleration * dt * dt ); //angle of needle var omega = this.needleAngularVelocity + this.needleAngularAcceleration * dt; - var alpha = NEEDLE_RESPONSIVENESS * (this.signalProperty.get() - this.thetaProperty.get()) - NEEDLE_FRICTION * omega; + var alpha = NEEDLE_RESPONSIVENESS * (this.signalProperty.get() - this.needleAngleProperty.get()) - NEEDLE_FRICTION * omega; this.needleAngularVelocity = this.needleAngularVelocity + 0.5 * dt * (this.needleAngularAcceleration + alpha); // Clamp the needle angle when its position, velocity, and acceleration go below a threshold so that it doesn't // oscillate forever. - if ( Math.abs( this.needleAngularAcceleration ) !== 0 && Math.abs( this.needleAngularAcceleration ) < ACTIVITY_THRESHOLD && - Math.abs( this.needleAngularVelocity ) !== 0 && Math.abs( this.needleAngularVelocity ) < ACTIVITY_THRESHOLD && - Math.abs( this.thetaProperty.get() ) !== 0 && Math.abs( this.thetaProperty.get() ) < ACTIVITY_THRESHOLD ) { - this.thetaProperty.set( 0 ); + if ( this.needleAngularAcceleration !== 0 && Math.abs( this.needleAngularAcceleration ) < ACTIVITY_THRESHOLD && + this.needleAngularVelocity !== 0 && Math.abs( this.needleAngularVelocity ) < ACTIVITY_THRESHOLD && + this.needleAngleProperty.get() !== 0 && Math.abs( this.needleAngleProperty.get() ) < ACTIVITY_THRESHOLD ) { + this.needleAngleProperty.set( 0 ); this.needleAngularVelocity = 0; this.needleAngularAcceleration = 0; } diff --git a/js/faradays-law/view/FaradaysLawScreenView.js b/js/faradays-law/view/FaradaysLawScreenView.js index 97345764..8c188fcd 100644 --- a/js/faradays-law/view/FaradaysLawScreenView.js +++ b/js/faradays-law/view/FaradaysLawScreenView.js @@ -50,8 +50,8 @@ define( function( require ) { this.aligner = new Aligner( model, bottomCoilNode.endRelativePositions, topCoilNode.endRelativePositions ); // voltmeter and bulb created - var voltmeterNode = new VoltmeterNode( model.voltmeter.thetaProperty, tandem.createTandem( 'voltmeterNode' ) ); - var bulbNode = new BulbNode( model.voltmeter.thetaProperty, { + var voltmeterNode = new VoltmeterNode( model.voltmeter.needleAngleProperty, tandem.createTandem( 'voltmeterNode' ) ); + var bulbNode = new BulbNode( model.voltmeter.needleAngleProperty, { centerX: this.aligner.bulbPosition.x, centerY: this.aligner.bulbPosition.y } );