Skip to content

Commit

Permalink
Adding the base equation to the preparation area #54
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinVallejo committed Dec 24, 2024
1 parent 424625d commit 409d781
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
65 changes: 65 additions & 0 deletions js/bloch-sphere/view/BlochSphereEquationNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2024, University of Colorado Boulder

/**
* BlochSphereEquationNode displays the equation that is used to calculate the expected value of polarization.
*
* @author Agustín Vallejo (PhET Interactive Simulations)
* @author John Blanco (PhET Interactive Simulations)
*/

import Vector2 from '../../../../dot/js/Vector2.js';
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import WithRequired from '../../../../phet-core/js/types/WithRequired.js';
import MathSymbolFont from '../../../../scenery-phet/js/MathSymbolFont.js';
import { HBox, HBoxOptions, RichText, RichTextOptions } from '../../../../scenery/js/imports.js';
import QuantumMeasurementConstants from '../../common/QuantumMeasurementConstants.js';
import FractionNode from '../../common/view/FractionNode.js';
import quantumMeasurement from '../../quantumMeasurement.js';

type SelfOptions = EmptySelfOptions;
type BlochSphereEquationNodeOptions = SelfOptions & WithRequired<HBoxOptions, 'tandem'>;

const EQUATION_FONT = new MathSymbolFont( 17 );
const THETA = QuantumMeasurementConstants.THETA;
const PHI = QuantumMeasurementConstants.PHI;
const PSI = QuantumMeasurementConstants.PSI;
const UP = QuantumMeasurementConstants.SPIN_UP_ARROW_CHARACTER;
const DOWN = QuantumMeasurementConstants.SPIN_DOWN_ARROW_CHARACTER;
const KET = QuantumMeasurementConstants.KET;

export default class BlochSphereEquationNode extends HBox {

public constructor( providedOptions?: BlochSphereEquationNodeOptions ) {

const richTextEquationOptions = { font: EQUATION_FONT };
const newRichText = ( text: string ) => new RichText( text, richTextEquationOptions );
const psiEqualsCos = newRichText( `|${PSI}⟩ = cos` );
const upPlusSin = newRichText( `|${UP}${KET} + sin` );
const downKet = newRichText( `e<sup>i${PHI}</sup>|${DOWN}${KET}` );

const parenthesesOptions: RichTextOptions = {
font: new MathSymbolFont( 17 ),
scale: new Vector2( 1, 2 )
};

const options = optionize<BlochSphereEquationNodeOptions, SelfOptions, HBoxOptions>()( {
spacing: 3,
align: 'center',
children: [
psiEqualsCos,
new RichText( '(', parenthesesOptions ),
new FractionNode( newRichText( THETA ), newRichText( '2' ), { scale: 0.8 } ),
new RichText( ')', parenthesesOptions ),
upPlusSin,
new RichText( '(', parenthesesOptions ),
new FractionNode( newRichText( THETA ), newRichText( '2' ), { scale: 0.8 } ),
new RichText( ')', parenthesesOptions ),
downKet
]
}, providedOptions );

super( options );
}
}

quantumMeasurement.register( 'BlochSphereEquationNode', BlochSphereEquationNode );
3 changes: 2 additions & 1 deletion js/bloch-sphere/view/BlochSphereScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import QuantumMeasurementColors from '../../common/QuantumMeasurementColors.js';
import BlochSphereNode from '../../common/view/BlochSphereNode.js';
import QuantumMeasurementScreenView from '../../common/view/QuantumMeasurementScreenView.js';
import quantumMeasurement from '../../quantumMeasurement.js';
import BlochSphereEquationNode from './BlochSphereEquationNode.js';

export default class BlochSphereScreenView extends QuantumMeasurementScreenView {

Expand Down Expand Up @@ -72,7 +73,7 @@ export default class BlochSphereScreenView extends QuantumMeasurementScreenView
align: 'center',
children: [
new Text( 'State to Prepare', { font: new PhetFont( { size: 20, weight: 'bolder' } ) } ),
new RichText( 'Equation 1', { font: new MathSymbolFont( { size: 20 } ) } ),
new BlochSphereEquationNode(),
new Panel(
new RichText( 'Equation 2', { font: new MathSymbolFont( { size: 20 } ) } ), {
fill: '#aff',
Expand Down
3 changes: 3 additions & 0 deletions js/common/QuantumMeasurementConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const QuantumMeasurementConstants = {
SCREEN_VIEW_Y_MARGIN: 15,
ALPHA: '\u03b1',
BETA: '\u03b2',
THETA: '\u03b8',
PHI: '\u03c6',
PSI: '\u03c8',
SPIN_UP_ARROW_CHARACTER: '\u2b61',
SPIN_DOWN_ARROW_CHARACTER: '\u2b63',
CLASSICAL_UP_SYMBOL: '\uD83C\uDF1E\uFE0E\uFE0E', // 🌞 Sun symbol
Expand Down

0 comments on commit 409d781

Please sign in to comment.