From 71d97577aede9fb70ada9a0fc53f746dce075d93 Mon Sep 17 00:00:00 2001 From: AgustinVallejo Date: Wed, 25 Dec 2024 12:04:12 -0500 Subject: [PATCH] Moving coefficients to the model https://github.com/phetsims/quantum-measurement/issues/54 --- js/bloch-sphere/model/BlochSphereModel.ts | 30 +++++++++++++++++++ .../view/BlochSphereNumericalEquationNode.ts | 16 +++++----- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/js/bloch-sphere/model/BlochSphereModel.ts b/js/bloch-sphere/model/BlochSphereModel.ts index e2b9ccf..88dd7e1 100644 --- a/js/bloch-sphere/model/BlochSphereModel.ts +++ b/js/bloch-sphere/model/BlochSphereModel.ts @@ -7,6 +7,7 @@ * @author Agustín Vallejo (PhET Interactive Simulations) */ +import NumberProperty from '../../../../axon/js/NumberProperty.js'; import TModel from '../../../../joist/js/TModel.js'; import { EmptySelfOptions } from '../../../../phet-core/js/optionize.js'; import PickRequired from '../../../../phet-core/js/types/PickRequired.js'; @@ -22,11 +23,40 @@ export default class BlochSphereModel implements TModel { public readonly blochSphere: ComplexBlochSphere; + // Coefficients of the state equation |psi> = upCoefficient |up> + downCoefficient * exp( i * |down> + public readonly upCoefficientProperty: NumberProperty; + public readonly downCoefficientProperty: NumberProperty; + public readonly phaseFactorProperty: NumberProperty; + public constructor( providedOptions: QuantumMeasurementModelOptions ) { this.blochSphere = new ComplexBlochSphere( { tandem: providedOptions.tandem.createTandem( 'blochSphere' ) } ); + + this.upCoefficientProperty = new NumberProperty( 1, { + tandem: providedOptions.tandem.createTandem( 'upCoefficientProperty' ), + phetioReadOnly: true + } ); + + this.downCoefficientProperty = new NumberProperty( 0, { + tandem: providedOptions.tandem.createTandem( 'downCoefficientProperty' ), + phetioReadOnly: true + } ); + + this.phaseFactorProperty = new NumberProperty( 0, { + tandem: providedOptions.tandem.createTandem( 'phaseFactorProperty' ), + phetioReadOnly: true + } ); + + this.blochSphere.polarAngleProperty.link( theta => { + this.upCoefficientProperty.value = Math.cos( theta / 2 ); + this.downCoefficientProperty.value = Math.sin( theta / 2 ); + } ); + + this.blochSphere.azimutalAngleProperty.link( phi => { + this.phaseFactorProperty.value = phi / Math.PI; + } ); } /** diff --git a/js/bloch-sphere/view/BlochSphereNumericalEquationNode.ts b/js/bloch-sphere/view/BlochSphereNumericalEquationNode.ts index ad6715a..2b0c490 100644 --- a/js/bloch-sphere/view/BlochSphereNumericalEquationNode.ts +++ b/js/bloch-sphere/view/BlochSphereNumericalEquationNode.ts @@ -33,16 +33,16 @@ export default class BlochSphereNumericalEquationNode extends HBox { const equationNode = new RichText( new DerivedStringProperty( [ - model.blochSphere.polarAngleProperty, - model.blochSphere.azimutalAngleProperty + model.upCoefficientProperty, + model.downCoefficientProperty, + model.phaseFactorProperty ], - ( polarAngle: number, azimutalAngle: number ) => { - const upCoefficient = Utils.toFixed( Math.cos( polarAngle / 2 ), 2 ); - const downCoefficient = Utils.toFixed( Math.abs( Math.sin( polarAngle / 2 ) ), 2 ); - const downCoefficientSign = Math.sin( polarAngle / 2 ) < 0 ? '\u2212' : '+'; - const azimutalCoefficient = Utils.toFixed( azimutalAngle / Math.PI, 2 ); + ( upCoefficient: number, downCoefficient: number, phaseFactor: number ) => { + const upCoefficientString = Utils.toFixed( upCoefficient, 2 ); + const downCoefficientString = Utils.toFixed( downCoefficient, 2 ); + const azimutalCoefficientString = Utils.toFixed( phaseFactor, 2 ); - return `|${PSI}⟩ = ${upCoefficient}|${UP}${KET} ${downCoefficientSign} ${downCoefficient}ei${azimutalCoefficient}${PI}|${DOWN}${KET}`; + return `|${PSI}⟩ = ${upCoefficientString}|${UP}${KET} + ${downCoefficientString}ei${azimutalCoefficientString}${PI}|${DOWN}${KET}`; } ), { font: EQUATION_FONT } );