From bad4cd47d124f36138cdce6d2612fbb8ba015811 Mon Sep 17 00:00:00 2001 From: AgustinVallejo Date: Thu, 16 Jan 2025 10:50:41 -0500 Subject: [PATCH] Changing Basis for Axis, see https://github.com/phetsims/quantum-measurement/issues/80 --- js/bloch-sphere/model/BlochSphereModel.ts | 18 +++++++++--------- js/bloch-sphere/model/ComplexBlochSphere.ts | 14 +++++++------- ...{MeasurementBasis.ts => MeasurementAxis.ts} | 12 ++++++------ js/bloch-sphere/model/StateDirection.ts | 4 ++-- .../view/BlochSphereMeasurementArea.ts | 16 ++++++++-------- 5 files changed, 32 insertions(+), 32 deletions(-) rename js/bloch-sphere/model/{MeasurementBasis.ts => MeasurementAxis.ts} (80%) diff --git a/js/bloch-sphere/model/BlochSphereModel.ts b/js/bloch-sphere/model/BlochSphereModel.ts index 44e0004..18f5dfd 100644 --- a/js/bloch-sphere/model/BlochSphereModel.ts +++ b/js/bloch-sphere/model/BlochSphereModel.ts @@ -22,7 +22,7 @@ import StringUnionIO from '../../../../tandem/js/types/StringUnionIO.js'; import QuantumMeasurementConstants from '../../common/QuantumMeasurementConstants.js'; import quantumMeasurement from '../../quantumMeasurement.js'; import ComplexBlochSphere from './ComplexBlochSphere.js'; -import { MeasurementBasis } from './MeasurementBasis.js'; +import { MeasurementAxis } from './MeasurementAxis.js'; import { SpinMeasurementState, SpinMeasurementStateValues } from './SpinMeasurementState.js'; import { StateDirection } from './StateDirection.js'; @@ -54,7 +54,7 @@ class BlochSphereModel implements TModel { public measurementTimeProperty: NumberProperty; // Measurement basis - public measurementBasisProperty: Property; + public measurementAxisProperty: Property; // If is single or multiple measurement mode public isSingleMeasurementModeProperty: BooleanProperty; @@ -109,9 +109,9 @@ class BlochSphereModel implements TModel { tandem: providedOptions.tandem.createTandem( 'measurementTimeProperty' ) } ); - this.measurementBasisProperty = new Property( MeasurementBasis.S_SUB_Z, { - tandem: providedOptions.tandem.createTandem( 'measurementBasisProperty' ), - phetioValueType: EnumerationIO( MeasurementBasis ), + this.measurementAxisProperty = new Property( MeasurementAxis.Z_PLUS, { + tandem: providedOptions.tandem.createTandem( 'measurementAxisProperty' ), + phetioValueType: EnumerationIO( MeasurementAxis ), phetioFeatured: true } ); @@ -203,7 +203,7 @@ class BlochSphereModel implements TModel { } ); } ); - this.measurementBasisProperty.link( () => { + this.measurementAxisProperty.link( () => { this.resetCounts(); } ); } @@ -220,7 +220,7 @@ class BlochSphereModel implements TModel { if ( this.isSingleMeasurementModeProperty.value ) { this.singleMeasurementBlochSphere.measure( - this.measurementBasisProperty.value, + this.measurementAxisProperty.value, this.upMeasurementCountProperty, this.downMeasurementCountProperty ); @@ -228,7 +228,7 @@ class BlochSphereModel implements TModel { else { this.multiMeasurementBlochSpheres.forEach( blochSphere => { blochSphere.measure( - this.measurementBasisProperty.value, + this.measurementAxisProperty.value, this.upMeasurementCountProperty, this.downMeasurementCountProperty ); @@ -303,7 +303,7 @@ class BlochSphereModel implements TModel { this.magneticFieldEnabledProperty.reset(); this.measurementStateProperty.reset(); this.magneticFieldStrengthProperty.reset(); - this.measurementBasisProperty.reset(); + this.measurementAxisProperty.reset(); this.isSingleMeasurementModeProperty.reset(); this.timeToMeasurementProperty.reset(); this.measurementTimeProperty.reset(); diff --git a/js/bloch-sphere/model/ComplexBlochSphere.ts b/js/bloch-sphere/model/ComplexBlochSphere.ts index 62a59c0..cbe9ced 100644 --- a/js/bloch-sphere/model/ComplexBlochSphere.ts +++ b/js/bloch-sphere/model/ComplexBlochSphere.ts @@ -16,7 +16,7 @@ import { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js'; import AbstractBlochSphere, { AbstractBlochSphereOptions } from '../../common/model/AbstractBlochSphere.js'; import QuantumMeasurementConstants from '../../common/QuantumMeasurementConstants.js'; import quantumMeasurement from '../../quantumMeasurement.js'; -import { MeasurementBasis } from './MeasurementBasis.js'; +import { MeasurementAxis } from './MeasurementAxis.js'; import { StateDirection } from './StateDirection.js'; type SelfOptions = { @@ -63,12 +63,12 @@ export default class ComplexBlochSphere extends AbstractBlochSphere { /** * Given a measurement basis, measures along that axis and updates the counters accordingly. - * @param measurementBasis + * @param measurementAxis * @param upCounterProperty * @param downCounterProperty */ - public measure( measurementBasis: MeasurementBasis, upCounterProperty: NumberProperty, downCounterProperty: NumberProperty ): void { - const measurementVector = StateDirection.directionToVector( measurementBasis ); + public measure( measurementAxis: MeasurementAxis, upCounterProperty: NumberProperty, downCounterProperty: NumberProperty ): void { + const measurementVector = StateDirection.directionToVector( measurementAxis ); const stateVector = StateDirection.anglesToVector( this.polarAngleProperty.value, this.azimuthalAngleProperty.value @@ -80,13 +80,13 @@ export default class ComplexBlochSphere extends AbstractBlochSphere { if ( isUp ) { upCounterProperty.value++; this.setDirection( - measurementBasis.polarAngle, - measurementBasis.azimuthalAngle + measurementAxis.polarAngle, + measurementAxis.azimuthalAngle ); } else { downCounterProperty.value++; - const oppositeDirection = measurementBasis.oppositeDirection; + const oppositeDirection = measurementAxis.oppositeDirection; this.setDirection( oppositeDirection.polarAngle, oppositeDirection.azimuthalAngle diff --git a/js/bloch-sphere/model/MeasurementBasis.ts b/js/bloch-sphere/model/MeasurementAxis.ts similarity index 80% rename from js/bloch-sphere/model/MeasurementBasis.ts rename to js/bloch-sphere/model/MeasurementAxis.ts index 79c55f1..adc6584 100644 --- a/js/bloch-sphere/model/MeasurementBasis.ts +++ b/js/bloch-sphere/model/MeasurementAxis.ts @@ -13,18 +13,18 @@ import quantumMeasurement from '../../quantumMeasurement.js'; import QuantumMeasurementStrings from '../../QuantumMeasurementStrings.js'; import { StateDirection } from './StateDirection.js'; -export class MeasurementBasis extends EnumerationValue { - public static readonly S_SUB_X = new MeasurementBasis( +export class MeasurementAxis extends EnumerationValue { + public static readonly X_PLUS = new MeasurementAxis( QuantumMeasurementStrings.SSubXStringProperty, Math.PI / 2, 0, StateDirection.X_MINUS, 'SSubX' ); - public static readonly S_SUB_Y = new MeasurementBasis( + public static readonly Y_PLUS = new MeasurementAxis( QuantumMeasurementStrings.SSubYStringProperty, Math.PI / 2, Math.PI / 2, StateDirection.Y_MINUS, 'SSubY' ); - public static readonly S_SUB_Z = new MeasurementBasis( + public static readonly Z_PLUS = new MeasurementAxis( QuantumMeasurementStrings.SSubZStringProperty, 0, 0, StateDirection.Z_MINUS, 'SSubZ' ); - public static readonly enumeration = new Enumeration( MeasurementBasis ); + public static readonly enumeration = new Enumeration( MeasurementAxis ); public constructor( public readonly label: TReadOnlyProperty, public readonly polarAngle: number, @@ -35,4 +35,4 @@ export class MeasurementBasis extends EnumerationValue { } } -quantumMeasurement.register( 'MeasurementBasis', MeasurementBasis ); \ No newline at end of file +quantumMeasurement.register( 'MeasurementAxis', MeasurementAxis ); \ No newline at end of file diff --git a/js/bloch-sphere/model/StateDirection.ts b/js/bloch-sphere/model/StateDirection.ts index 053203b..3244966 100644 --- a/js/bloch-sphere/model/StateDirection.ts +++ b/js/bloch-sphere/model/StateDirection.ts @@ -10,7 +10,7 @@ import Vector3 from '../../../../dot/js/Vector3.js'; import Enumeration from '../../../../phet-core/js/Enumeration.js'; import EnumerationValue from '../../../../phet-core/js/EnumerationValue.js'; import quantumMeasurement from '../../quantumMeasurement.js'; -import { MeasurementBasis } from './MeasurementBasis.js'; +import { MeasurementAxis } from './MeasurementAxis.js'; export class StateDirection extends EnumerationValue { public static readonly Z_PLUS = new StateDirection( '+Z', 0, 0, 'ZPlus' ); @@ -30,7 +30,7 @@ export class StateDirection extends EnumerationValue { super(); } - public static directionToVector( direction: StateDirection | MeasurementBasis ): Vector3 { + public static directionToVector( direction: StateDirection | MeasurementAxis ): Vector3 { return new Vector3( Math.sin( direction.polarAngle ) * Math.cos( direction.azimuthalAngle ), Math.sin( direction.polarAngle ) * Math.sin( direction.azimuthalAngle ), Math.cos( direction.polarAngle ) ); diff --git a/js/bloch-sphere/view/BlochSphereMeasurementArea.ts b/js/bloch-sphere/view/BlochSphereMeasurementArea.ts index 8dcafde..35d9f8c 100644 --- a/js/bloch-sphere/view/BlochSphereMeasurementArea.ts +++ b/js/bloch-sphere/view/BlochSphereMeasurementArea.ts @@ -27,7 +27,7 @@ import QuantumMeasurementHistogram from '../../common/view/QuantumMeasurementHis import quantumMeasurement from '../../quantumMeasurement.js'; import QuantumMeasurementStrings from '../../QuantumMeasurementStrings.js'; import BlochSphereModel from '../model/BlochSphereModel.js'; -import { MeasurementBasis } from '../model/MeasurementBasis.js'; +import { MeasurementAxis } from '../model/MeasurementAxis.js'; import BlochSphereNumericalEquationNode from './BlochSphereNumericalEquationNode.js'; import MagneticFieldControl from './MagneticFieldControl.js'; import MeasurementTimerControl from './MeasurementTimerControl.js'; @@ -86,12 +86,12 @@ export default class BlochSphereMeasurementArea extends Node { multipleMeasurementBlochSpheresNode.top = 70; const spinUpLabelStringProperty = new DerivedStringProperty( - [ model.measurementBasisProperty ], - measurementBasis => measurementBasis.label.value + QuantumMeasurementConstants.SPIN_UP_ARROW_CHARACTER + [ model.measurementAxisProperty ], + measurementAxis => measurementAxis.label.value + QuantumMeasurementConstants.SPIN_UP_ARROW_CHARACTER ); const spinDownLabelStringProperty = new DerivedStringProperty( - [ model.measurementBasisProperty ], - measurementBasis => measurementBasis.label.value + QuantumMeasurementConstants.SPIN_DOWN_ARROW_CHARACTER + [ model.measurementAxisProperty ], + measurementAxis => measurementAxis.label.value + QuantumMeasurementConstants.SPIN_DOWN_ARROW_CHARACTER ); const measurementResultHistogram = new QuantumMeasurementHistogram( @@ -126,7 +126,7 @@ export default class BlochSphereMeasurementArea extends Node { // Create and add the radio buttons that select the chart type view in the nuclideChartAccordionBox. const basisRadioButtonGroupTandem = providedOptions.tandem.createTandem( 'basisRadioButtonGroup' ); - const basisRadioGroupItems = MeasurementBasis.enumeration.values.map( basis => { + const basisRadioGroupItems = MeasurementAxis.enumeration.values.map( basis => { return { value: basis, createNode: () => new RichText( @@ -136,8 +136,8 @@ export default class BlochSphereMeasurementArea extends Node { }; } ); - const basisRadioButtonGroup = new RectangularRadioButtonGroup( - model.measurementBasisProperty, + const basisRadioButtonGroup = new RectangularRadioButtonGroup( + model.measurementAxisProperty, basisRadioGroupItems, { orientation: 'horizontal',