diff --git a/js/bloch-sphere/model/StateDirection.ts b/js/bloch-sphere/model/StateDirection.ts index bd641dd..9a48e85 100644 --- a/js/bloch-sphere/model/StateDirection.ts +++ b/js/bloch-sphere/model/StateDirection.ts @@ -13,12 +13,12 @@ import quantumMeasurement from '../../quantumMeasurement.js'; import { MeasurementAxis } from './MeasurementAxis.js'; export class StateDirection extends EnumerationValue { - public static readonly Z_PLUS = new StateDirection( '+Z', 0, 0, 'ZPlus' ); - public static readonly Z_MINUS = new StateDirection( '-Z', Math.PI, 0, 'ZMinus' ); public static readonly X_PLUS = new StateDirection( '+X', Math.PI / 2, 0, 'XPlus' ); public static readonly X_MINUS = new StateDirection( '-X', Math.PI / 2, Math.PI, 'XMinus' ); public static readonly Y_PLUS = new StateDirection( '+Y', Math.PI / 2, Math.PI / 2, 'YPlus' ); public static readonly Y_MINUS = new StateDirection( '-Y', Math.PI / 2, 3 * Math.PI / 2, 'YMinus' ); + public static readonly Z_PLUS = new StateDirection( '+Z', 0, 0, 'ZPlus' ); + public static readonly Z_MINUS = new StateDirection( '-Z', Math.PI, 0, 'ZMinus' ); public static readonly CUSTOM = new StateDirection( 'Custom', 0, 0, 'Custom' ); public static readonly enumeration = new Enumeration( StateDirection ); diff --git a/js/bloch-sphere/view/BlochSphereNumericalEquationNode.ts b/js/bloch-sphere/view/BlochSphereNumericalEquationNode.ts index 8acba4a..f721344 100644 --- a/js/bloch-sphere/view/BlochSphereNumericalEquationNode.ts +++ b/js/bloch-sphere/view/BlochSphereNumericalEquationNode.ts @@ -47,14 +47,40 @@ export default class BlochSphereNumericalEquationNode extends HBox { blochSphere.azimuthalAngleProperty, options.basisProperty ], - ( polarAngle, azimuthalAngle, basisProperty ) => { + ( polarAngle, azimuthalAngle, basis ) => { + + let upCoefficientValue; + let downCoefficientValue; + let azimuthalCoefficientValue; + + const projectionToCoefficient = ( value: number ) => { + return Math.sqrt( ( value + 1 ) / 2 ); + }; + + switch( basis ) { + case StateDirection.X_PLUS: + upCoefficientValue = projectionToCoefficient( Math.cos( azimuthalAngle ) * Math.sin( polarAngle ) ); + downCoefficientValue = projectionToCoefficient( -Math.cos( azimuthalAngle ) * Math.sin( polarAngle ) ); + azimuthalCoefficientValue = 0; + break; + case StateDirection.Y_PLUS: + upCoefficientValue = projectionToCoefficient( Math.sin( azimuthalAngle ) * Math.sin( polarAngle ) ); + downCoefficientValue = projectionToCoefficient( -Math.sin( azimuthalAngle ) * Math.sin( polarAngle ) ); + azimuthalCoefficientValue = 0; + break; + default: // StateDirection.Z_PLUS + upCoefficientValue = Math.abs( Math.cos( polarAngle / 2 ) ); + downCoefficientValue = Math.abs( Math.sin( polarAngle / 2 ) ); + azimuthalCoefficientValue = azimuthalAngle / Math.PI; + break; + } // Update the coefficients of the state equation. - const upCoefficientString = Utils.toFixed( Math.cos( polarAngle / 2 ), 2 ); - const downCoefficientString = Utils.toFixed( Math.sin( polarAngle / 2 ), 2 ); - const azimuthalCoefficientString = Utils.toFixed( azimuthalAngle / Math.PI, 2 ); + const upCoefficientString = Utils.toFixed( upCoefficientValue, 2 ); + const downCoefficientString = Utils.toFixed( downCoefficientValue, 2 ); + const azimuthalCoefficientString = Utils.toFixed( azimuthalCoefficientValue, 2 ); - const direction = basisProperty.description.split( '' )[ 1 ]; + const direction = basis.description.split( '' )[ 1 ]; return `|${PSI}⟩ = ${upCoefficientString} |${UP}${direction} ${KET} + ` + `${downCoefficientString}ei${azimuthalCoefficientString}${PI} |${DOWN}${direction} ${KET}`;