From 030e96712bfdb1936a6ccd7d40b37b41fbe94c74 Mon Sep 17 00:00:00 2001 From: AgustinVallejo Date: Fri, 13 Dec 2024 12:10:21 -0500 Subject: [PATCH] Minor improvements to the aperture of PhotonDetector, see https://github.com/phetsims/quantum-measurement/issues/65 --- js/photons/model/PhotonDetector.ts | 8 +++++--- js/photons/view/PhotonDetectorNode.ts | 16 +++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/js/photons/model/PhotonDetector.ts b/js/photons/model/PhotonDetector.ts index 57dc76d..23fba48 100644 --- a/js/photons/model/PhotonDetector.ts +++ b/js/photons/model/PhotonDetector.ts @@ -48,6 +48,9 @@ export default class PhotonDetector implements TPhotonInteraction { // detection aperture width, in meters public readonly apertureDiameter = PHOTON_BEAM_WIDTH * 1.75; + // detection aperture height, in meters + public readonly apertureHeight = 0.05; + // A line in model space that represents the position of the detection aperture. If a photon crosses this line, it // will be detected but not absorbed. public readonly detectionLine: Line; @@ -74,14 +77,13 @@ export default class PhotonDetector implements TPhotonInteraction { this.position = position; this.detectionDirection = detectionDirection; this.displayMode = options.displayMode!; - const apertureHeight = 0.02; this.detectionLine = new Line( position.plus( new Vector2( -this.apertureDiameter / 2, 0 ) ), position.plus( new Vector2( this.apertureDiameter / 2, 0 ) ) ); this.absorptionLine = new Line( - position.plus( new Vector2( -this.apertureDiameter / 2, this.detectionDirection === 'up' ? apertureHeight : -apertureHeight ) ), - position.plus( new Vector2( this.apertureDiameter / 2, this.detectionDirection === 'up' ? apertureHeight : -apertureHeight ) ) + position.plus( new Vector2( -this.apertureDiameter / 2, this.detectionDirection === 'up' ? this.apertureHeight : -this.apertureHeight ) ), + position.plus( new Vector2( this.apertureDiameter / 2, this.detectionDirection === 'up' ? this.apertureHeight : -this.apertureHeight ) ) ); this.detectionRateProperty = new AveragingCounterNumberProperty( { diff --git a/js/photons/view/PhotonDetectorNode.ts b/js/photons/view/PhotonDetectorNode.ts index bda090b..4177621 100644 --- a/js/photons/view/PhotonDetectorNode.ts +++ b/js/photons/view/PhotonDetectorNode.ts @@ -43,15 +43,19 @@ export default class PhotonDetectorNode extends Node { // Create the detection aperture. This is essentially the anchor point for reset of the layout, meaning that the // other nodes are positioned relative to this. - const apertureHeightInView = modelViewTransform.modelToViewDeltaY( - -Math.abs( model.detectionLine.start.y - model.absorptionLine.end.y ) - ); - const apertureDiameterInView = -modelViewTransform.modelToViewDeltaY( model.apertureDiameter ); + const apertureHeightInView = -modelViewTransform.modelToViewDeltaY( model.apertureHeight ); + const apertureDiameterInView = modelViewTransform.modelToViewDeltaX( model.apertureDiameter ); + const apertureCenterY = model.detectionDirection === 'up' ? + model.position.y + model.apertureHeight / 2 : + model.position.y - model.apertureHeight / 2; const aperture = new Rectangle( 0, 0, apertureDiameterInView, apertureHeightInView, { fill: new LinearGradient( 0, 0, apertureDiameterInView, 0 ) .addColorStop( 0, new Color( '#FFDDEE' ) ) .addColorStop( 1, Color.DARK_GRAY ), - center: modelViewTransform.modelToViewPosition( model.position ), + stroke: Color.DARK_GRAY, + lineWidth: 1, + centerX: modelViewTransform.modelToViewX( model.position.x ), + centerY: modelViewTransform.modelToViewY( apertureCenterY ), opacity: 0.3 } ); @@ -143,8 +147,6 @@ export default class PhotonDetectorNode extends Node { ); super( options ); - - this.centerY += model.detectionDirection === 'up' ? -apertureHeightInView / 2 : apertureHeightInView / 2; } }