Skip to content

Commit

Permalink
partial solution for 'Object blocks reflected rays', #125
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Jan 21, 2022
1 parent 4feef7c commit 75cf430
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
36 changes: 33 additions & 3 deletions js/common/model/LightRay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import GOQueryParameters from '../GOQueryParameters.js';
import LightRaySegment from './LightRaySegment.js';
import Optic from './Optic.js';
import Ray from './Ray.js';
import Shape from '../../../../kite/js/Shape.js';
import IReadOnlyProperty from '../../../../axon/js/IReadOnlyProperty.js';

class LightRay {

Expand Down Expand Up @@ -51,9 +53,11 @@ class LightRay {
* @param isVirtual - is the image virtual?
* @param isPrincipalRaysType - is the light ray mode set to Principal rays
* @param projectionScreen - optional projection screen that can block the rays
* @param sourceOjectPositionProperty
*/
constructor( initialRay: Ray, time: number, optic: Optic, targetPoint: Vector2, isVirtual: boolean,
isPrincipalRaysType: boolean, projectionScreen: ProjectionScreen | null ) {
isPrincipalRaysType: boolean, projectionScreen: ProjectionScreen | null,
sourceOjectPositionProperty: IReadOnlyProperty<Vector2> ) {

assert && AssertUtils.assertNonNegativeNumber( time );

Expand All @@ -68,11 +72,14 @@ class LightRay {

this.realRays = getRealRays( initialRay, firstPoint, optic, isPrincipalRaysType, targetPoint );

// If we have a projection screen, check whether the last ray terminates on the projection screen.
// Check whether the last ray terminates on the projection screen or source object.
const lastRay = this.realRays[ this.realRays.length - 1 ];
if ( projectionScreen ) {
const lastRay = this.realRays[ this.realRays.length - 1 ];
terminateOnProjectionScreen( lastRay, projectionScreen );
}
else if ( optic instanceof Mirror ) {
terminateOnFramedObject( lastRay, sourceOjectPositionProperty.value );
}

this.hasVirtualRay = hasVirtualComponent( isVirtual, this.realRays );

Expand Down Expand Up @@ -279,6 +286,29 @@ function getIntermediatePoint( initialRay: Ray, firstPoint: Vector2, optic: Opti
return initialRay.position.blend( firstPoint, opticSourceVector.x / firstSourceVector.x );
}

/**
* If ray intersects the framed object, terminate the ray on the framed object by setting
* the ray's final point.
* @param realRay
* @param sourceObjectPosition
*/
function terminateOnFramedObject( realRay: Ray, sourceObjectPosition: Vector2 ): void {

//TODO This line was created empirically because it does not currently exist in the SourceObject model.
//TODO Factor out duplication with terminateOnProjectionScreen.
const bisectorLine = new Shape().moveToPoint( sourceObjectPosition.plusXY( 0, 18 ) ).lineToPoint( sourceObjectPosition.minusXY( 0, 72 ) );

const intersection = bisectorLine.intersection( realRay );

// {Vector2|null}
const pointOnScreen = getPoint( intersection );

// If intersection is found, set the transmittedRay final point
if ( pointOnScreen ) {
realRay.setFinalPoint( pointOnScreen );
}
}

/**
* If ray intersects the projection screen, terminate the ray on the projection screen by setting
* the ray's final point.
Expand Down
2 changes: 1 addition & 1 deletion js/common/model/LightRays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class LightRays {

// determine the lightRay
const lightRay = new LightRay( initialRay, time, optic, targetPoint, isVirtual, isPrincipalRaysType,
representation.isObject ? null : projectionScreen
representation.isObject ? null : projectionScreen, sourceObjectPositionProperty
);

// set target's visibility to true after the first ray reaches its target
Expand Down

0 comments on commit 75cf430

Please sign in to comment.