From c43b5f144eef86bd07fbb447b7c8a7087f4d0cac Mon Sep 17 00:00:00 2001 From: bobzel Date: Mon, 22 May 2023 15:32:15 -0400 Subject: start of physics cleanup --- .../nodes/PhysicsBox/PhysicsSimulationBox.tsx | 1131 ++++++++++---------- 1 file changed, 546 insertions(+), 585 deletions(-) (limited to 'src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx') diff --git a/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx b/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx index ab93583df..db15c9a5c 100644 --- a/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx +++ b/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx @@ -1,29 +1,24 @@ -import './PhysicsSimulationBox.scss'; -import { FieldView, FieldViewProps } from './../FieldView'; -import React = require('react'); -import { ViewBoxAnnotatableComponent } from '../../DocComponent'; -import { observer } from 'mobx-react'; -import './PhysicsSimulationBox.scss'; -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { CheckBox } from '../../search/CheckBox'; +import ArrowLeftIcon from '@mui/icons-material/ArrowLeft'; +import ArrowRightIcon from '@mui/icons-material/ArrowRight'; import PauseIcon from '@mui/icons-material/Pause'; import PlayArrowIcon from '@mui/icons-material/PlayArrow'; -import ReplayIcon from '@mui/icons-material/Replay'; import QuestionMarkIcon from '@mui/icons-material/QuestionMark'; -import ArrowLeftIcon from '@mui/icons-material/ArrowLeft'; -import ArrowRightIcon from '@mui/icons-material/ArrowRight'; -import EditIcon from '@mui/icons-material/Edit'; -import EditOffIcon from '@mui/icons-material/EditOff'; -import { Box, Button, Checkbox, Dialog, DialogTitle, DialogContent, DialogContentText, DialogActions, FormControl, FormControlLabel, FormGroup, IconButton, LinearProgress, Stack } from '@mui/material'; +import ReplayIcon from '@mui/icons-material/Replay'; +import { Box, Button, Checkbox, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, FormControl, FormControlLabel, FormGroup, IconButton, LinearProgress, Stack } from '@mui/material'; import Typography from '@mui/material/Typography'; +import { observer } from 'mobx-react'; +import { HeightSym, NumListCast, WidthSym } from '../../../../fields/Doc'; +import { ViewBoxAnnotatableComponent } from '../../DocComponent'; +import { FieldView, FieldViewProps } from './../FieldView'; import './PhysicsSimulationBox.scss'; import InputField from './PhysicsSimulationInputField'; import * as questions from './PhysicsSimulationQuestions.json'; import * as tutorials from './PhysicsSimulationTutorial.json'; import Wall from './PhysicsSimulationWall'; import Weight from './PhysicsSimulationWeight'; -import { NumCast } from '../../../../fields/Types'; -import { HeightSym, WidthSym } from '../../../../fields/Doc'; +import React = require('react'); +import { BoolCast, NumCast, StrCast } from '../../../../fields/Types'; +import { List } from '../../../../fields/List'; interface IWallProps { length: number; @@ -70,7 +65,7 @@ interface TutorialTemplate { directionInDegrees: number; component: boolean; }[]; - showMagnitude: boolean; + show_Magnitude: boolean; }[]; } @@ -99,54 +94,36 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent(); + this.dataDoc.show_Icon = false; this.dataDoc.hintDialogueOpen = false; this.dataDoc.noMovement = false; this.dataDoc.questionNumber = 0; this.dataDoc.questionPartOne = ''; this.dataDoc.questionPartTwo = ''; - this.dataDoc.reviewGravityAngle = 0; - this.dataDoc.reviewGravityMagnitude = 0; - this.dataDoc.reviewNormalAngle = 0; - this.dataDoc.reviewNormalMagnitude = 0; - this.dataDoc.reviewStaticAngle = 0; - this.dataDoc.reviewStaticMagnitude = 0; + this.dataDoc.review_GravityAngle = 0; + this.dataDoc.review_GravityMagnitude = 0; + this.dataDoc.review_NormalAngle = 0; + this.dataDoc.review_NormalMagnitude = 0; + this.dataDoc.review_StaticAngle = 0; + this.dataDoc.review_StaticMagnitude = 0; this.dataDoc.selectedSolutions = []; this.dataDoc.selectedQuestion = this.dataDoc.selectedQuestion ?? questions.inclinePlane[0]; // this.dataDoc.sketching = this.dataDoc.sketching ?? false; @@ -158,39 +135,25 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent { - this.dataDoc.simulationPaused = true; + this.dataDoc.simulation_Paused = true; if (simulationType != 'Circular Motion') { - this.dataDoc.startVelX = 0; + this.dataDoc.start_VelX = 0; this.dataDoc.setStartVelY = 0; - this.dataDoc.velocityXDisplay = 0; - this.dataDoc.velocityYDisplay = 0; + this.dataDoc.velocity_XDisplay = 0; + this.dataDoc.velocity_YDisplay = 0; } if (mode == 'Freeform') { - this.dataDoc.showForceMagnitudes = true; + this.dataDoc.show_ForceMagnitudes = true; if (simulationType == 'One Weight') { - this.dataDoc.showComponentForces = false; - this.dataDoc.startPosY = this.yMin + 0.08 * this.layoutDoc[HeightSym](); - this.dataDoc.startPosX = (this.xMax + this.xMin) / 2 - 0.08 * this.layoutDoc[HeightSym](); - this.dataDoc.positionYDisplay = this.getDisplayYPos(this.yMin + 0.08 * this.layoutDoc[HeightSym]()); - this.dataDoc.positionXDisplay = (this.xMax + this.xMin) / 2 - 0.08 * this.layoutDoc[HeightSym](); + this.dataDoc.show_ComponentForces = false; + this.dataDoc.start_PosY = this.yMin + 0.08 * this.layoutDoc[HeightSym](); + this.dataDoc.start_PosX = (this.xMax + this.xMin) / 2 - 0.08 * this.layoutDoc[HeightSym](); + this.dataDoc.position_YDisplay = this.getDisplayYPos(this.yMin + 0.08 * this.layoutDoc[HeightSym]()); + this.dataDoc.position_XDisplay = (this.xMax + this.xMin) / 2 - 0.08 * this.layoutDoc[HeightSym](); this.dataDoc.updatedForces = [ { description: 'Gravity', - magnitude: Math.abs(this.dataDoc.gravity) * this.dataDoc.mass, + magnitude: Math.abs(NumCast(this.dataDoc.gravity)) * NumCast(this.dataDoc.mass), directionInDegrees: 270, component: false, }, ]; - this.dataDoc.startForces = [ + this.dataDoc.start_Forces = [ { description: 'Gravity', - magnitude: Math.abs(this.dataDoc.gravity) * this.dataDoc.mass, + magnitude: Math.abs(NumCast(this.dataDoc.gravity)) * NumCast(this.dataDoc.mass), directionInDegrees: 270, component: false, }, ]; - this.dataDoc.simulationReset = !this.dataDoc.simulationReset; + this.dataDoc.simulation_Reset = !this.dataDoc.simulation_Reset; } else if (simulationType == 'Inclined Plane') { this.changeWedgeBasedOnNewAngle(26); - this.dataDoc.startForces = [ + this.dataDoc.start_Forces = [ { description: 'Gravity', - magnitude: Math.abs(this.dataDoc.gravity) * this.dataDoc.mass, + magnitude: Math.abs(NumCast(this.dataDoc.gravity)) * NumCast(this.dataDoc.mass), directionInDegrees: 270, component: false, }, ]; - this.updateForcesWithFriction(Number(this.dataDoc.coefficientOfStaticFriction)); + this.updateForcesWithFriction(NumCast(this.dataDoc.coefficientOfStaticFriction)); } else if (simulationType == 'Pendulum') { this.setupPendulum(); } else if (simulationType == 'Spring') { @@ -267,11 +230,11 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent { + updateForcesWithFriction = (coefficient: number, width: number = NumCast(this.dataDoc.wedgeWidth), height: number = NumCast(this.dataDoc.wedgeHeight)) => { const normalForce: IForce = { description: 'Normal Force', - magnitude: Math.abs(this.dataDoc.gravity) * Math.cos(Math.atan(height / width)) * this.dataDoc.mass, + magnitude: Math.abs(NumCast(this.dataDoc.gravity)) * Math.cos(Math.atan(height / width)) * NumCast(this.dataDoc.mass), directionInDegrees: 180 - 90 - (Math.atan(height / width) * 180) / Math.PI, component: false, }; let frictionForce: IForce = { description: 'Static Friction Force', - magnitude: coefficient * Math.abs(this.dataDoc.gravity) * Math.cos(Math.atan(height / width)) * this.dataDoc.mass, + magnitude: coefficient * Math.abs(NumCast(this.dataDoc.gravity)) * Math.cos(Math.atan(height / width)) * NumCast(this.dataDoc.mass), directionInDegrees: 180 - (Math.atan(height / width) * 180) / Math.PI, component: false, }; // reduce magnitude or friction force if necessary such that block cannot slide up plane - let yForce = -Math.abs(this.dataDoc.gravity) * this.dataDoc.mass; + let yForce = -Math.abs(NumCast(this.dataDoc.gravity)) * NumCast(this.dataDoc.mass); yForce += normalForce.magnitude * Math.sin((normalForce.directionInDegrees * Math.PI) / 180); yForce += frictionForce.magnitude * Math.sin((frictionForce.directionInDegrees * Math.PI) / 180); if (yForce > 0) { - frictionForce.magnitude = (-normalForce.magnitude * Math.sin((normalForce.directionInDegrees * Math.PI) / 180) + Math.abs(this.dataDoc.gravity) * this.dataDoc.mass) / Math.sin((frictionForce.directionInDegrees * Math.PI) / 180); + frictionForce.magnitude = + (-normalForce.magnitude * Math.sin((normalForce.directionInDegrees * Math.PI) / 180) + Math.abs(NumCast(this.dataDoc.gravity)) * NumCast(this.dataDoc.mass)) / Math.sin((frictionForce.directionInDegrees * Math.PI) / 180); } const frictionForceComponent: IForce = { description: 'Static Friction Force', - magnitude: coefficient * Math.abs(this.dataDoc.gravity) * Math.cos(Math.atan(height / width)), + magnitude: coefficient * Math.abs(NumCast(this.dataDoc.gravity)) * Math.cos(Math.atan(height / width)), directionInDegrees: 180 - (Math.atan(height / width) * 180) / Math.PI, component: true, }; const normalForceComponent: IForce = { description: 'Normal Force', - magnitude: Math.abs(this.dataDoc.gravity) * Math.cos(Math.atan(height / width)), + magnitude: Math.abs(NumCast(this.dataDoc.gravity)) * Math.cos(Math.atan(height / width)), directionInDegrees: 180 - 90 - (Math.atan(height / width) * 180) / Math.PI, component: true, }; const gravityParallel: IForce = { description: 'Gravity Parallel Component', - magnitude: this.dataDoc.mass * Math.abs(this.dataDoc.gravity) * Math.sin(Math.PI / 2 - Math.atan(height / width)), + magnitude: NumCast(this.dataDoc.mass) * Math.abs(NumCast(this.dataDoc.gravity)) * Math.sin(Math.PI / 2 - Math.atan(height / width)), directionInDegrees: 180 - 90 - (Math.atan(height / width) * 180) / Math.PI + 180, component: true, }; const gravityPerpendicular: IForce = { description: 'Gravity Perpendicular Component', - magnitude: this.dataDoc.mass * Math.abs(this.dataDoc.gravity) * Math.cos(Math.PI / 2 - Math.atan(height / width)), + magnitude: NumCast(this.dataDoc.mass) * Math.abs(NumCast(this.dataDoc.gravity)) * Math.cos(Math.PI / 2 - Math.atan(height / width)), directionInDegrees: 360 - (Math.atan(height / width) * 180) / Math.PI, component: true, }; const gravityForce: IForce = { description: 'Gravity', - magnitude: this.dataDoc.mass * Math.abs(this.dataDoc.gravity), + magnitude: NumCast(this.dataDoc.mass) * Math.abs(NumCast(this.dataDoc.gravity)), directionInDegrees: 270, component: false, }; if (coefficient != 0) { - this.dataDoc.startForces = [gravityForce, normalForce, frictionForce]; + this.dataDoc.start_Forces = [gravityForce, normalForce, frictionForce]; this.dataDoc.updatedForces = [gravityForce, normalForce, frictionForce]; this.dataDoc.componentForces = [frictionForceComponent, normalForceComponent, gravityParallel, gravityPerpendicular]; } else { - this.dataDoc.startForces = [gravityForce, normalForce]; + this.dataDoc.start_Forces = [gravityForce, normalForce]; this.dataDoc.updatedForces = [gravityForce, normalForce]; this.dataDoc.componentForces = [normalForceComponent, gravityParallel, gravityPerpendicular]; } @@ -468,65 +433,65 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent { - let theta: number = Number(this.dataDoc.wedgeAngle); + let theta: number = NumCast(this.dataDoc.wedgeAngle); let index = this.dataDoc.selectedQuestion.variablesForQuestionSetup.indexOf('theta - max 45'); if (index >= 0) { - theta = this.dataDoc.questionVariables[index]; + theta = NumListCast(this.dataDoc.questionVariables)[index]; } if (isNaN(theta)) { return; } - this.dataDoc.reviewGravityMagnitude = Math.abs(this.dataDoc.gravity); - this.dataDoc.reviewGravityAngle = 270; - this.dataDoc.reviewNormalMagnitude = Math.abs(this.dataDoc.gravity) * Math.cos((theta * Math.PI) / 180); - this.dataDoc.reviewNormalAngle = 90 - theta; - let yForce = -Math.abs(this.dataDoc.gravity); - yForce += Math.abs(this.dataDoc.gravity) * Math.cos((theta * Math.PI) / 180) * Math.sin(((90 - theta) * Math.PI) / 180); - yForce += coefficient * Math.abs(this.dataDoc.gravity) * Math.cos((theta * Math.PI) / 180) * Math.sin(((180 - theta) * Math.PI) / 180); - let friction = coefficient * Math.abs(this.dataDoc.gravity) * Math.cos((theta * Math.PI) / 180); + this.dataDoc.review_GravityMagnitude = Math.abs(NumCast(this.dataDoc.gravity)); + this.dataDoc.review_GravityAngle = 270; + this.dataDoc.review_NormalMagnitude = Math.abs(NumCast(this.dataDoc.gravity)) * Math.cos((theta * Math.PI) / 180); + this.dataDoc.review_NormalAngle = 90 - theta; + let yForce = -Math.abs(NumCast(this.dataDoc.gravity)); + yForce += Math.abs(NumCast(this.dataDoc.gravity)) * Math.cos((theta * Math.PI) / 180) * Math.sin(((90 - theta) * Math.PI) / 180); + yForce += coefficient * Math.abs(NumCast(this.dataDoc.gravity)) * Math.cos((theta * Math.PI) / 180) * Math.sin(((180 - theta) * Math.PI) / 180); + let friction = coefficient * Math.abs(NumCast(this.dataDoc.gravity)) * Math.cos((theta * Math.PI) / 180); if (yForce > 0) { - friction = (-(Math.abs(this.dataDoc.gravity) * Math.cos((theta * Math.PI) / 180)) * Math.sin(((90 - theta) * Math.PI) / 180) + Math.abs(this.dataDoc.gravity)) / Math.sin(((180 - theta) * Math.PI) / 180); + friction = (-(Math.abs(NumCast(this.dataDoc.gravity)) * Math.cos((theta * Math.PI) / 180)) * Math.sin(((90 - theta) * Math.PI) / 180) + Math.abs(NumCast(this.dataDoc.gravity))) / Math.sin(((180 - theta) * Math.PI) / 180); } - this.dataDoc.reviewStaticMagnitude = friction; - this.dataDoc.reviewStaticAngle = 180 - theta; + this.dataDoc.review_StaticMagnitude = friction; + this.dataDoc.review_StaticAngle = 180 - theta; }; // In review mode, update forces when wedge angle changed updateReviewForcesBasedOnAngle = (angle: number) => { - this.dataDoc.reviewGravityMagnitude = Math.abs(this.dataDoc.gravity); - this.dataDoc.reviewGravityAngle = 270; - this.dataDoc.reviewNormalMagnitude = Math.abs(this.dataDoc.gravity) * Math.cos((Number(angle) * Math.PI) / 180); - this.dataDoc.reviewNormalAngle = 90 - angle; - let yForce = -Math.abs(this.dataDoc.gravity); - yForce += Math.abs(this.dataDoc.gravity) * Math.cos((Number(angle) * Math.PI) / 180) * Math.sin(((90 - Number(angle)) * Math.PI) / 180); - yForce += this.dataDoc.reviewCoefficient * Math.abs(this.dataDoc.gravity) * Math.cos((Number(angle) * Math.PI) / 180) * Math.sin(((180 - Number(angle)) * Math.PI) / 180); - let friction = this.dataDoc.reviewCoefficient * Math.abs(this.dataDoc.gravity) * Math.cos((Number(angle) * Math.PI) / 180); + this.dataDoc.review_GravityMagnitude = Math.abs(NumCast(this.dataDoc.gravity)); + this.dataDoc.review_GravityAngle = 270; + this.dataDoc.review_NormalMagnitude = Math.abs(NumCast(this.dataDoc.gravity)) * Math.cos((angle * Math.PI) / 180); + this.dataDoc.review_NormalAngle = 90 - angle; + let yForce = -Math.abs(NumCast(this.dataDoc.gravity)); + yForce += Math.abs(NumCast(this.dataDoc.gravity)) * Math.cos((angle * Math.PI) / 180) * Math.sin(((90 - angle) * Math.PI) / 180); + yForce += NumCast(this.dataDoc.review_Coefficient) * Math.abs(NumCast(this.dataDoc.gravity)) * Math.cos((angle * Math.PI) / 180) * Math.sin(((180 - angle) * Math.PI) / 180); + let friction = NumCast(this.dataDoc.review_Coefficient) * Math.abs(NumCast(this.dataDoc.gravity)) * Math.cos((angle * Math.PI) / 180); if (yForce > 0) { - friction = (-(Math.abs(this.dataDoc.gravity) * Math.cos((Number(angle) * Math.PI) / 180)) * Math.sin(((90 - Number(angle)) * Math.PI) / 180) + Math.abs(this.dataDoc.gravity)) / Math.sin(((180 - Number(angle)) * Math.PI) / 180); + friction = (-(Math.abs(NumCast(this.dataDoc.gravity)) * Math.cos((angle * Math.PI) / 180)) * Math.sin(((90 - angle) * Math.PI) / 180) + Math.abs(NumCast(this.dataDoc.gravity))) / Math.sin(((180 - angle) * Math.PI) / 180); } - this.dataDoc.reviewStaticMagnitude = friction; - this.dataDoc.reviewStaticAngle = 180 - angle; + this.dataDoc.review_StaticMagnitude = friction; + this.dataDoc.review_StaticAngle = 180 - angle; }; // Solve for the correct answers to the generated problem getAnswersToQuestion = (question: QuestionTemplate, questionVars: number[]) => { const solutions: number[] = []; - let theta: number = Number(this.dataDoc.wedgeAngle); + let theta: number = NumCast(this.dataDoc.wedgeAngle); let index = question.variablesForQuestionSetup.indexOf('theta - max 45'); if (index >= 0) { theta = questionVars[index]; } - let muS: number = Number(this.dataDoc.coefficientOfStaticFriction); + let muS: number = NumCast(this.dataDoc.coefficientOfStaticFriction); index = question.variablesForQuestionSetup.indexOf('coefficient of static friction'); if (index >= 0) { muS = questionVars[index]; @@ -534,25 +499,25 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent epsilon) { + if (Math.abs(NumCast(this.dataDoc.review_GravityMagnitude) - this.dataDoc.selectedSolutions[i]) > epsilon) { error = true; } } else if (this.dataDoc.selectedQuestion.answerParts[i] == 'angle of gravity') { - if (Math.abs(this.dataDoc.reviewGravityAngle - this.dataDoc.selectedSolutions[i]) > epsilon) { + if (Math.abs(NumCast(this.dataDoc.review_GravityAngle) - this.dataDoc.selectedSolutions[i]) > epsilon) { error = true; } } else if (this.dataDoc.selectedQuestion.answerParts[i] == 'normal force') { - if (Math.abs(this.dataDoc.reviewNormalMagnitude - this.dataDoc.selectedSolutions[i]) > epsilon) { + if (Math.abs(NumCast(this.dataDoc.review_NormalMagnitude) - this.dataDoc.selectedSolutions[i]) > epsilon) { error = true; } } else if (this.dataDoc.selectedQuestion.answerParts[i] == 'angle of normal force') { - if (Math.abs(this.dataDoc.reviewNormalAngle - this.dataDoc.selectedSolutions[i]) > epsilon) { + if (Math.abs(NumCast(this.dataDoc.review_NormalAngle) - this.dataDoc.selectedSolutions[i]) > epsilon) { error = true; } } else if (this.dataDoc.selectedQuestion.answerParts[i] == 'force of static friction') { - if (Math.abs(this.dataDoc.reviewStaticMagnitude - this.dataDoc.selectedSolutions[i]) > epsilon) { + if (Math.abs(NumCast(this.dataDoc.review_StaticMagnitude) - this.dataDoc.selectedSolutions[i]) > epsilon) { error = true; } } else if (this.dataDoc.selectedQuestion.answerParts[i] == 'angle of static friction') { - if (Math.abs(this.dataDoc.reviewStaticAngle - this.dataDoc.selectedSolutions[i]) > epsilon) { + if (Math.abs(NumCast(this.dataDoc.review_StaticAngle) - this.dataDoc.selectedSolutions[i]) > epsilon) { error = true; } } else if (this.dataDoc.selectedQuestion.answerParts[i] == 'coefficient of static friction') { - if (Math.abs(Number(this.dataDoc.coefficientOfStaticFriction) - this.dataDoc.selectedSolutions[i]) > epsilon) { + if (Math.abs(NumCast(this.dataDoc.coefficientOfStaticFriction) - this.dataDoc.selectedSolutions[i]) > epsilon) { error = true; } } else if (this.dataDoc.selectedQuestion.answerParts[i] == 'wedge angle') { - if (Math.abs(Number(this.dataDoc.wedgeAngle) - this.dataDoc.selectedSolutions[i]) > epsilon) { + if (Math.abs(NumCast(this.dataDoc.wedgeAngle) - this.dataDoc.selectedSolutions[i]) > epsilon) { error = true; } } @@ -606,14 +571,14 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent { - this.dataDoc.simulationPaused = true; + this.dataDoc.simulation_Paused = true; }, 3000); } else { - this.dataDoc.simulationPaused = false; + this.dataDoc.simulation_Paused = false; setTimeout(() => { - this.dataDoc.simulationPaused = true; + this.dataDoc.simulation_Paused = true; }, 3000); } } @@ -628,14 +593,14 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent { - this.dataDoc.reviewGravityMagnitude = 0; - this.dataDoc.reviewGravityAngle = 0; - this.dataDoc.reviewNormalMagnitude = 0; - this.dataDoc.reviewNormalAngle = 0; - this.dataDoc.reviewStaticMagnitude = 0; - this.dataDoc.reviewStaticAngle = 0; + this.dataDoc.review_GravityMagnitude = 0; + this.dataDoc.review_GravityAngle = 0; + this.dataDoc.review_NormalMagnitude = 0; + this.dataDoc.review_NormalAngle = 0; + this.dataDoc.review_StaticMagnitude = 0; + this.dataDoc.review_StaticAngle = 0; this.dataDoc.coefficientOfKineticFriction = 0; - this.dataDoc.simulationPaused = true; + this.dataDoc.simulation_Paused = true; }; // In review mode, reset problem variables and generate a new question @@ -645,13 +610,13 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent(vars); this.dataDoc.selectedQuestion = question; this.dataDoc.questionPartOne = q; this.dataDoc.questionPartTwo = question.question; - this.dataDoc.answers = this.getAnswersToQuestion(question, vars); - //this.dataDoc.simulationReset = (!this.dataDoc.simulationReset); + this.dataDoc.answers = new List(this.getAnswersToQuestion(question, vars)); + //this.dataDoc.simulation_Reset = (!this.dataDoc.simulation_Reset); }; // Default setup for uniform circular motion simulation setupCircular = (value: number) => { - this.dataDoc.showComponentForces = false; - this.dataDoc.startVelY = 0; - this.dataDoc.startVelX = value; + this.dataDoc.show_ComponentForces = false; + this.dataDoc.start_VelY = 0; + this.dataDoc.start_VelX = value; let xPos = (this.xMax + this.xMin) / 2 - 0.08 * this.layoutDoc[HeightSym](); - let yPos = (this.yMax + this.yMin) / 2 + this.dataDoc.circularMotionRadius - 0.08 * this.layoutDoc[HeightSym](); - this.dataDoc.startPosY = yPos; - this.dataDoc.startPosX = xPos; + let yPos = (this.yMax + this.yMin) / 2 + NumCast(this.dataDoc.circularMotionRadius) - 0.08 * this.layoutDoc[HeightSym](); + this.dataDoc.start_PosY = yPos; + this.dataDoc.start_PosX = xPos; const tensionForce: IForce = { description: 'Centripetal Force', - magnitude: (this.dataDoc.startVelX ** 2 * this.dataDoc.mass) / this.dataDoc.circularMotionRadius, + magnitude: (this.dataDoc.start_VelX ** 2 * NumCast(this.dataDoc.mass)) / NumCast(this.dataDoc.circularMotionRadius), directionInDegrees: 90, component: false, }; this.dataDoc.updatedForces = [tensionForce]; - this.dataDoc.startForces = [tensionForce]; - this.dataDoc.simulationReset = !this.dataDoc.simulationReset; + this.dataDoc.start_Forces = [tensionForce]; + this.dataDoc.simulation_Reset = !this.dataDoc.simulation_Reset; }; // Default setup for pendulum simulation @@ -718,9 +683,9 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent { - this.dataDoc.showComponentForces = false; + this.dataDoc.show_ComponentForces = false; const gravityForce: IForce = { description: 'Gravity', - magnitude: Math.abs(this.dataDoc.gravity) * this.dataDoc.mass, + magnitude: Math.abs(NumCast(this.dataDoc.gravity)) * NumCast(this.dataDoc.mass), directionInDegrees: 270, component: false, }; this.dataDoc.updatedForces = [gravityForce]; - this.dataDoc.startForces = [gravityForce]; - this.dataDoc.startPosX = this.xMax / 2 - 0.08 * this.layoutDoc[HeightSym](); - this.dataDoc.startPosY = 200; + this.dataDoc.start_Forces = [gravityForce]; + this.dataDoc.start_PosX = this.xMax / 2 - 0.08 * this.layoutDoc[HeightSym](); + this.dataDoc.start_PosY = 200; this.dataDoc.springConstant = 0.5; this.dataDoc.springRestLength = 200; this.dataDoc.springStartLength = 200; - this.dataDoc.simulationReset = !this.dataDoc.simulationReset; + this.dataDoc.simulation_Reset = !this.dataDoc.simulation_Reset; }; // Default setup for suspension simulation setupSuspension = () => { let xPos = (this.xMax + this.xMin) / 2 - 0.08 * this.layoutDoc[HeightSym](); let yPos = this.yMin + 200; - this.dataDoc.startPosY = yPos; - this.dataDoc.startPosX = xPos; - this.dataDoc.positionYDisplay = this.getDisplayYPos(yPos); - this.dataDoc.positionXDisplay = xPos; - let tensionMag = (this.dataDoc.mass * Math.abs(this.dataDoc.gravity)) / (2 * Math.sin(Math.PI / 4)); + this.dataDoc.start_PosY = yPos; + this.dataDoc.start_PosX = xPos; + this.dataDoc.position_YDisplay = this.getDisplayYPos(yPos); + this.dataDoc.position_XDisplay = xPos; + let tensionMag = (NumCast(this.dataDoc.mass) * Math.abs(NumCast(this.dataDoc.gravity))) / (2 * Math.sin(Math.PI / 4)); const tensionForce1: IForce = { description: 'Tension', magnitude: tensionMag, @@ -814,59 +780,59 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent { - this.dataDoc.showComponentForces = false; - this.dataDoc.startPosY = (this.yMax + this.yMin) / 2; - this.dataDoc.startPosX = (this.xMin + this.xMax) / 2 - 2 * (0.08 * this.layoutDoc[HeightSym]()) - 5; - this.dataDoc.positionYDisplay = this.getDisplayYPos((this.yMax + this.yMin) / 2); - this.dataDoc.positionXDisplay = (this.xMin + this.xMax) / 2 - 2 * (0.08 * this.layoutDoc[HeightSym]()) - 5; - let a = (-1 * ((this.dataDoc.mass - this.dataDoc.mass2) * Math.abs(this.dataDoc.gravity))) / (this.dataDoc.mass + this.dataDoc.mass2); + this.dataDoc.show_ComponentForces = false; + this.dataDoc.start_PosY = (this.yMax + this.yMin) / 2; + this.dataDoc.start_PosX = (this.xMin + this.xMax) / 2 - 2 * (0.08 * this.layoutDoc[HeightSym]()) - 5; + this.dataDoc.position_YDisplay = this.getDisplayYPos((this.yMax + this.yMin) / 2); + this.dataDoc.position_XDisplay = (this.xMin + this.xMax) / 2 - 2 * (0.08 * this.layoutDoc[HeightSym]()) - 5; + let a = (-1 * ((NumCast(this.dataDoc.mass) - NumCast(this.dataDoc.mass2)) * Math.abs(NumCast(this.dataDoc.gravity)))) / (NumCast(this.dataDoc.mass) + NumCast(this.dataDoc.mass2)); const gravityForce1: IForce = { description: 'Gravity', - magnitude: this.dataDoc.mass * Math.abs(this.dataDoc.gravity), + magnitude: NumCast(this.dataDoc.mass) * Math.abs(NumCast(this.dataDoc.gravity)), directionInDegrees: 270, component: false, }; const tensionForce1: IForce = { description: 'Tension', - magnitude: this.dataDoc.mass * a + this.dataDoc.mass * Math.abs(this.dataDoc.gravity), + magnitude: NumCast(this.dataDoc.mass) * a + NumCast(this.dataDoc.mass) * Math.abs(NumCast(this.dataDoc.gravity)), directionInDegrees: 90, component: false, }; a *= -1; const gravityForce2: IForce = { description: 'Gravity', - magnitude: this.dataDoc.mass2 * Math.abs(this.dataDoc.gravity), + magnitude: NumCast(this.dataDoc.mass2) * Math.abs(NumCast(this.dataDoc.gravity)), directionInDegrees: 270, component: false, }; const tensionForce2: IForce = { description: 'Tension', - magnitude: this.dataDoc.mass2 * a + this.dataDoc.mass2 * Math.abs(this.dataDoc.gravity), + magnitude: NumCast(this.dataDoc.mass2) * a + NumCast(this.dataDoc.mass2) * Math.abs(NumCast(this.dataDoc.gravity)), directionInDegrees: 90, component: false, }; this.dataDoc.updatedForces = [gravityForce1, tensionForce1]; - this.dataDoc.startForces = [gravityForce1, tensionForce1]; - this.dataDoc.startPosY2 = (this.yMax + this.yMin) / 2; - this.dataDoc.startPosX2 = (this.xMin + this.xMax) / 2 + 5; - this.dataDoc.positionYDisplay2 = this.getDisplayYPos((this.yMax + this.yMin) / 2); - this.dataDoc.positionXDisplay2 = (this.xMin + this.xMax) / 2 + 5; + this.dataDoc.start_Forces = [gravityForce1, tensionForce1]; + this.dataDoc.start_PosY2 = (this.yMax + this.yMin) / 2; + this.dataDoc.start_PosX2 = (this.xMin + this.xMax) / 2 + 5; + this.dataDoc.position_YDisplay2 = this.getDisplayYPos((this.yMax + this.yMin) / 2); + this.dataDoc.position_XDisplay2 = (this.xMin + this.xMax) / 2 + 5; this.dataDoc.updatedForces2 = [gravityForce2, tensionForce2]; - this.dataDoc.startForces2 = [gravityForce2, tensionForce2]; + this.dataDoc.start_Forces2 = [gravityForce2, tensionForce2]; - this.dataDoc.simulationReset = !this.dataDoc.simulationReset; + this.dataDoc.simulation_Reset = !this.dataDoc.simulation_Reset; }; // Helper function used for tutorial and review mode @@ -895,23 +861,23 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent { const forceOfGravityReview: IForce = { description: 'Gravity', - magnitude: this.dataDoc.reviewGravityMagnitude, - directionInDegrees: this.dataDoc.reviewGravityAngle, + magnitude: NumCast(this.dataDoc.review_GravityMagnitude), + directionInDegrees: NumCast(this.dataDoc.review_GravityAngle), component: false, }; const normalForceReview: IForce = { description: 'Normal Force', - magnitude: this.dataDoc.reviewNormalMagnitude, - directionInDegrees: this.dataDoc.reviewNormalAngle, + magnitude: NumCast(this.dataDoc.review_NormalMagnitude), + directionInDegrees: NumCast(this.dataDoc.review_NormalAngle), component: false, }; const staticFrictionForceReview: IForce = { description: 'Static Friction Force', - magnitude: this.dataDoc.reviewStaticMagnitude, - directionInDegrees: this.dataDoc.reviewStaticAngle, + magnitude: NumCast(this.dataDoc.review_StaticMagnitude), + directionInDegrees: NumCast(this.dataDoc.review_StaticAngle), component: false, }; - this.dataDoc.startForces = [forceOfGravityReview, normalForceReview, staticFrictionForceReview]; + this.dataDoc.start_Forces = [forceOfGravityReview, normalForceReview, staticFrictionForceReview]; this.dataDoc.updatedForces = [forceOfGravityReview, normalForceReview, staticFrictionForceReview]; }; @@ -922,7 +888,7 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent
- {!this.dataDoc.simulationPaused && ( + {!this.dataDoc.simulation_Paused && (
- {this.dataDoc.simulationType == 'Pulley' && ( + {this.dataDoc.simulation_Type == 'Pulley' && (
- {(this.dataDoc.simulationType == 'One Weight' || this.dataDoc.simulationType == 'Inclined Plane') && + {(this.dataDoc.simulation_Type == 'One Weight' || this.dataDoc.simulation_Type == 'Inclined Plane') && this.wallPositions && this.wallPositions.map((element, index) => { return ; @@ -1044,26 +1014,26 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent
- {this.dataDoc.simulationPaused && this.dataDoc.mode != 'Tutorial' && ( + {this.dataDoc.simulation_Paused && this.dataDoc.mode != 'Tutorial' && ( { - this.dataDoc.simulationPaused = false; + this.dataDoc.simulation_Paused = false; }}> )} - {!this.dataDoc.simulationPaused && this.dataDoc.mode != 'Tutorial' && ( + {!this.dataDoc.simulation_Paused && this.dataDoc.mode != 'Tutorial' && ( { - this.dataDoc.simulationPaused = true; + this.dataDoc.simulation_Paused = true; }}> )} - {this.dataDoc.simulationPaused && this.dataDoc.mode != 'Tutorial' && ( + {this.dataDoc.simulation_Paused && this.dataDoc.mode != 'Tutorial' && ( { - this.dataDoc.simulationReset = !this.dataDoc.simulationReset; + this.dataDoc.simulation_Reset = !this.dataDoc.simulation_Reset; }}> @@ -1071,10 +1041,10 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent
{ this.dataDoc.mode = event.target.value; - this.setupSimulation(this.dataDoc.simulationType, event.target.value); + this.setupSimulation(StrCast(this.dataDoc.simulation_Type), event.target.value); }} style={{ height: '2em', width: '100%', fontSize: '16px' }}> @@ -1100,13 +1070,13 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent
- {this.dataDoc.mode == 'Review' && this.dataDoc.simulationType != 'Inclined Plane' && ( + {this.dataDoc.mode == 'Review' && this.dataDoc.simulation_Type != 'Inclined Plane' && (
-

{this.dataDoc.simulationType} review problems in progress!

+

{this.dataDoc.simulation_Type} review problems in progress!


)} - {this.dataDoc.mode == 'Review' && this.dataDoc.simulationType == 'Inclined Plane' && ( + {this.dataDoc.mode == 'Review' && this.dataDoc.simulation_Type == 'Inclined Plane' && (
{!this.dataDoc.hintDialogueOpen && ( )} - (this.dataDoc.hintDialogueOpen = false)}> + (this.dataDoc.hintDialogueOpen = false)}> Hints - {this.dataDoc.selectedQuestion.hints && - this.dataDoc.selectedQuestion.hints.map((hint: any, index: number) => { - return ( -
- -
- - - Hint {index + 1}: {hint.description} - - - {hint.content} -
-
-
- ); - })} + {this.dataDoc.selectedQuestion.hints?.map((hint: any, index: number) => { + return ( +
+ +
+ + + Hint {index + 1}: {hint.description} + + + {hint.content} +
+
+
+ ); + })}