Skip to content

Commit

Permalink
Minor improvements to the aperture of PhotonDetector, see #65
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinVallejo committed Dec 13, 2024
1 parent 9928423 commit 030e967
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
8 changes: 5 additions & 3 deletions js/photons/model/PhotonDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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( {
Expand Down
16 changes: 9 additions & 7 deletions js/photons/view/PhotonDetectorNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
} );

Expand Down Expand Up @@ -143,8 +147,6 @@ export default class PhotonDetectorNode extends Node {
);

super( options );

this.centerY += model.detectionDirection === 'up' ? -apertureHeightInView / 2 : apertureHeightInView / 2;
}
}

Expand Down

0 comments on commit 030e967

Please sign in to comment.